@fps-games/editor-deployment 0.2.3-beta.17 → 0.2.3-beta.18
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/bin/fps-editor-project.mjs +3 -3
- package/licenses/THIRD_PARTY_NOTICES.txt +2 -2
- package/manifest.json +48 -48
- package/npm-shrinkwrap.json +2 -2
- package/package.json +7 -7
- package/public/assets/index-DTqLoSGs.js +1 -0
- package/public/assets/index-DTqLoSGs.js.br +0 -0
- package/public/assets/index-DTqLoSGs.js.gz +0 -0
- package/public/assets/playable-sdk-A7Cfp-Qu.js +4 -0
- package/public/assets/playable-sdk-A7Cfp-Qu.js.br +0 -0
- package/public/assets/playable-sdk-A7Cfp-Qu.js.gz +0 -0
- package/public/assets/playable-standard-project-bxE3z_Fn.js +5250 -0
- package/public/assets/playable-standard-project-bxE3z_Fn.js.br +0 -0
- package/public/assets/playable-standard-project-bxE3z_Fn.js.gz +0 -0
- package/public/index.html +3 -3
- package/public/index.html.br +0 -0
- package/public/index.html.gz +0 -0
- package/runtime/editor-control-plane.mjs +4 -4
- package/worker/editor-service-worker.mjs +17 -17
- package/public/assets/index-ChyK2lhc.js +0 -1
- package/public/assets/index-ChyK2lhc.js.br +0 -0
- package/public/assets/index-ChyK2lhc.js.gz +0 -0
- package/public/assets/playable-sdk-D42v8kWc.js +0 -4
- package/public/assets/playable-sdk-D42v8kWc.js.br +0 -0
- package/public/assets/playable-sdk-D42v8kWc.js.gz +0 -0
- package/public/assets/playable-standard-project-DgsY-0An.js +0 -5250
- package/public/assets/playable-standard-project-DgsY-0An.js.br +0 -0
- package/public/assets/playable-standard-project-DgsY-0An.js.gz +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import jr from"node:fs/promises";import ie from"node:path";import{pathToFileURL as sf}from"node:url";var _t=class extends Error{path;reason;code="runtime.lighting.invalid";constructor(t,n){super(`Invalid Runtime Lighting data at ${t}: ${n}`),this.path=t,this.reason=n,this.name="FpsRuntimeLightingDataError"}},Lr=1e-6,ks=1e-4,Ms=new Set(["schemaVersion","type","intensity","direction","diffuseColor"]),Cs=new Set(["schemaVersion","type","intensity","diffuseColor","groundColor"]),Rs=new Set(["x","y","z"]),$s=new Set(["r","g","b"]);function ft(e,t="$.direction"){let n=zr(e,t),r=Math.hypot(n.x,n.y,n.z);return r<=Lr&&ce(t,"expected a non-zero direction vector"),Object.freeze({x:n.x/r,y:n.y/r,z:n.z/r})}function qe(e,t="$.light"){let n=kn(e,t);n.schemaVersion!==1&&ce(`${t}.schemaVersion`,"expected 1");let r=Ns(n.intensity,`${t}.intensity`);if(n.type==="directional"){Lt(n,Ms,t);let i=zr(n.direction,`${t}.direction`),o=Math.hypot(i.x,i.y,i.z);return o<=Lr&&ce(`${t}.direction`,"expected a non-zero direction vector"),Math.abs(o-1)>ks&&ce(`${t}.direction`,"expected a normalized direction vector"),Object.freeze({schemaVersion:1,type:"directional",intensity:r,direction:i,diffuseColor:Tn(n.diffuseColor,`${t}.diffuseColor`)})}if(n.type==="hemispheric")return Lt(n,Cs,t),Object.freeze({schemaVersion:1,type:"hemispheric",intensity:r,diffuseColor:Tn(n.diffuseColor,`${t}.diffuseColor`),groundColor:Tn(n.groundColor,`${t}.groundColor`)});ce(`${t}.type`,"expected directional or hemispheric")}function zr(e,t){let n=kn(e,t);return Lt(n,Rs,t),Object.freeze({x:ut(n.x,`${t}.x`),y:ut(n.y,`${t}.y`),z:ut(n.z,`${t}.z`)})}function Tn(e,t){let n=kn(e,t);return Lt(n,$s,t),Object.freeze({r:Dn(n.r,`${t}.r`),g:Dn(n.g,`${t}.g`),b:Dn(n.b,`${t}.b`)})}function kn(e,t){(!e||typeof e!="object"||Array.isArray(e))&&ce(t,"expected a plain object");let n=Object.getPrototypeOf(e);return n!==Object.prototype&&n!==null&&ce(t,"expected a plain object"),e}function Lt(e,t,n){for(let r of Object.keys(e))t.has(r)||ce(`${n}.${r}`,"unknown field")}function ut(e,t){return(typeof e!="number"||!Number.isFinite(e))&&ce(t,"expected a finite number"),e}function Ns(e,t){let n=ut(e,t);return n<0&&ce(t,"expected a non-negative number"),n}function Dn(e,t){let n=ut(e,t);return(n<0||n>1)&&ce(t,"expected a number between 0 and 1"),n}function ce(e,t){throw new _t(e,t)}var gt="medium",Mn={low:{opacity:.32,softness:.25,bias:.0015,normalBias:.02,maxDistance:24,resolution:512,cascadeCount:1,bakeSamples:8,blurKernel:2},medium:{opacity:.42,softness:.4,bias:.001,normalBias:.01,maxDistance:48,resolution:1024,cascadeCount:2,bakeSamples:24,blurKernel:4},high:{opacity:.5,softness:.58,bias:8e-4,normalBias:.006,maxDistance:80,resolution:2048,cascadeCount:4,bakeSamples:64,blurKernel:8},ultra:{opacity:.56,softness:.72,bias:6e-4,normalBias:.004,maxDistance:120,resolution:4096,cascadeCount:4,bakeSamples:128,blurKernel:12}};function zt(e=gt,t={}){let n=Mn[e]??Mn[gt];return{opacity:mt(t.opacity,n.opacity),softness:mt(t.softness,n.softness),bias:mt(t.bias,n.bias),normalBias:mt(t.normalBias,n.normalBias),maxDistance:mt(t.maxDistance,n.maxDistance),resolution:Gs(t.resolution,n.resolution),cascadeCount:js(t.cascadeCount,n.cascadeCount),bakeSamples:Os(t.bakeSamples,n.bakeSamples),blurKernel:vs(t.blurKernel,n.blurKernel)}}function mt(e,t){return typeof e=="number"&&Number.isFinite(e)?e:t}function Os(e,t){return typeof e=="number"&&Number.isFinite(e)&&e>0?Math.round(e):t}function vs(e,t){return typeof e=="number"&&Number.isFinite(e)&&e>=0?Math.round(e):t}function Gs(e,t){return e===512||e===1024||e===2048||e===4096?e:t}function js(e,t){return e===1||e===2||e===4?e:t}function Ut(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function Bt(e){return e==="inherit"||e==="none"||e==="enabled"||e==="auto"}function Vt(e){return e==="inherit"||e==="none"||e==="enabled"||e==="auto"}function Kt(e){return e==="inherit"||e==="none"||e==="dynamic"||e==="static"||e==="blob"||e==="projected"||e==="auto"}function Ht(e){return e==="inherit"||e==="low"||e==="medium"||e==="high"||e==="ultra"}function Wt(e){return e==="inherit"||e==="scene-main"||e==="nearest"||e==="explicit"}function Ur(e){let t=Ut(e);if(!t)return;let n={};Bt(t.cast)&&(n.cast=t.cast),Vt(t.receive)&&(n.receive=t.receive),Kt(t.mode)&&(n.mode=t.mode),Ht(t.quality)&&(n.quality=t.quality);let r=Ut(t.light);if(r){let o={};Wt(r.mode)&&(o.mode=r.mode),typeof r.lightId=="string"&&r.lightId.trim()&&(o.lightId=r.lightId.trim()),Object.keys(o).length>0&&(n.light=o)}let i=Fs(t.params);return i&&(n.params=i),Object.keys(n).length>0?n:void 0}function De(e){let t=Ur(e);return t?{shadow:t,diagnostics:[]}:{diagnostics:[]}}function Cn(e,t="none"){let n=e?.mode;return!n||n==="inherit"||n==="auto"?t:n}function Rn(e,t=gt){let n=e?.quality;return n&&n!=="inherit"?n:t}function Fs(e){let t=Ut(e);if(!t)return;let n={};return typeof t.opacity=="number"&&Number.isFinite(t.opacity)&&(n.opacity=t.opacity),typeof t.softness=="number"&&Number.isFinite(t.softness)&&(n.softness=t.softness),typeof t.bias=="number"&&Number.isFinite(t.bias)&&(n.bias=t.bias),typeof t.normalBias=="number"&&Number.isFinite(t.normalBias)&&(n.normalBias=t.normalBias),typeof t.maxDistance=="number"&&Number.isFinite(t.maxDistance)&&(n.maxDistance=t.maxDistance),(t.resolution===512||t.resolution===1024||t.resolution===2048||t.resolution===4096)&&(n.resolution=t.resolution),(t.cascadeCount===1||t.cascadeCount===2||t.cascadeCount===4)&&(n.cascadeCount=t.cascadeCount),typeof t.bakeSamples=="number"&&Number.isFinite(t.bakeSamples)&&(n.bakeSamples=t.bakeSamples),typeof t.blurKernel=="number"&&Number.isFinite(t.blurKernel)&&(n.blurKernel=t.blurKernel),Object.keys(n).length>0?n:void 0}var _s=new Set(["cast","receive","mode","quality","light","params"]),Ls=new Set(["mode","lightId"]),zs=new Set(["opacity","softness","bias","normalBias","maxDistance","resolution","cascadeCount","bakeSamples","blurKernel"]);function pt(e,t="$.shadow"){let n=Nn(e);if(!n)throw Q("schema.invalidType",t);if($n(n,_s,t),"cast"in n&&!Bt(n.cast))throw Q("schema.invalidValue",`${t}.cast`);if("receive"in n&&!Vt(n.receive))throw Q("schema.invalidValue",`${t}.receive`);if("mode"in n&&!Kt(n.mode))throw Q("schema.invalidValue",`${t}.mode`);if("quality"in n&&!Ht(n.quality))throw Q("schema.invalidValue",`${t}.quality`);"light"in n&&Us(n.light,`${t}.light`),"params"in n&&Bs(n.params,`${t}.params`)}function Us(e,t){let n=Nn(e);if(!n)throw Q("schema.invalidType",t);if($n(n,Ls,t),"mode"in n&&!Wt(n.mode))throw Q("schema.invalidValue",`${t}.mode`);if("lightId"in n&&(typeof n.lightId!="string"||!n.lightId.trim()))throw Q("schema.invalidValue",`${t}.lightId`);if(n.mode==="explicit"&&(typeof n.lightId!="string"||!n.lightId.trim()))throw Q("schema.invalidValue",`${t}.lightId`)}function Bs(e,t){let n=Nn(e);if(!n)throw Q("schema.invalidType",t);if($n(n,zs,t),Ge(n,"opacity",t,r=>r>=0&&r<=1),Ge(n,"softness",t,r=>r>=0),Ge(n,"bias",t,()=>!0),Ge(n,"normalBias",t,()=>!0),Ge(n,"maxDistance",t,r=>r>0),Ge(n,"bakeSamples",t,r=>r>0),Ge(n,"blurKernel",t,r=>r>=0),"resolution"in n&&![512,1024,2048,4096].includes(n.resolution))throw Q("schema.invalidValue",`${t}.resolution`);if("cascadeCount"in n&&![1,2,4].includes(n.cascadeCount))throw Q("schema.invalidValue",`${t}.cascadeCount`)}function Ge(e,t,n,r){if(!(t in e))return;let i=e[t];if(typeof i!="number"||!Number.isFinite(i)||!r(i))throw Q("schema.invalidValue",`${n}.${t}`)}function $n(e,t,n){for(let r of Object.keys(e))if(!t.has(r))throw Q("schema.deprecatedField",`${n}.${r}`)}function Q(e,t){let n=new Error(`${e}: ${t}`);return Object.assign(n,{code:e,path:t}),n}function Nn(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}var jn="fps.shadow-map-experiment";function Vs(e,t="$.scene.shadowMapExperiment"){let n=le(e,t);ye(n,["qualityProfile","behaviorProfile"],t),n.qualityProfile!==void 0&&be(n.qualityProfile,`${t}.qualityProfile`),n.behaviorProfile!==void 0&&be(n.behaviorProfile,`${t}.behaviorProfile`)}function Ks(e,t="$.shadowMapExperiment"){let n=le(e,t);ye(n,["behaviorProfile"],t),be(n.behaviorProfile,`${t}.behaviorProfile`)}function Hs(e,t="$"){let n=le(e,t);ye(n,["schemaVersion","enabled","lightRef","defaultQualityProfile","defaultBehaviorProfile","qualityProfiles","behaviorProfiles"],t),n.schemaVersion!==1&&N(`${t}.schemaVersion`,"expected 1"),typeof n.enabled!="boolean"&&N(`${t}.enabled`,"expected boolean"),be(n.lightRef,`${t}.lightRef`);let r=be(n.defaultQualityProfile,`${t}.defaultQualityProfile`),i=be(n.defaultBehaviorProfile,`${t}.defaultBehaviorProfile`),o=Vr(n.qualityProfiles,`${t}.qualityProfiles`),s=Vr(n.behaviorProfiles,`${t}.behaviorProfiles`);for(let[a,c]of Object.entries(o))qs(c,`${t}.qualityProfiles.${a}`);for(let[a,c]of Object.entries(s))Js(c,`${t}.behaviorProfiles.${a}`);Object.prototype.hasOwnProperty.call(o,r)||N(`${t}.defaultQualityProfile`,`unknown quality profile: ${r}`),Object.prototype.hasOwnProperty.call(s,i)||N(`${t}.defaultBehaviorProfile`,`unknown behavior profile: ${i}`)}function Kr(e){Hs(e.config),e.settings!==void 0&&Vs(e.settings),(!Number.isInteger(e.revision)||e.revision<0)&&N("$.revision","expected a non-negative integer");let t=e.settings?.qualityProfile??e.config.defaultQualityProfile,n=e.settings?.behaviorProfile??e.config.defaultBehaviorProfile,r=vn(e.config.qualityProfiles,t,"$.settings.qualityProfile","quality");vn(e.config.behaviorProfiles,n,"$.settings.behaviorProfile","behavior");let i=e.objects.map((a,c)=>{let d=`$.objects[${c}]`;a.override!==void 0&&Ks(a.override,`${d}.override`);let u=a.override?.behaviorProfile??n,l=vn(e.config.behaviorProfiles,u,`${d}.override.behaviorProfile`,"behavior");return Object.freeze({entityId:be(a.entityId,`${d}.entityId`),renderableIds:Object.freeze(ra(a.renderableIds,`${d}.renderableIds`)),cast:Br(a.cast,`${d}.cast`)??l.cast==="enabled",receive:Br(a.receive,`${d}.receive`)??l.receive==="enabled",updateClass:l.updateClass!=="auto"?l.updateClass:a.inferredUpdateClass??"static",behaviorProfileId:u})}).sort((a,c)=>a.entityId.localeCompare(c.entityId)),o=e.config.enabled?i:[];ta(o);let s=Object.fromEntries(Object.entries(e.config.behaviorProfiles).sort(([a],[c])=>a.localeCompare(c)).map(([a,c])=>[a,Object.freeze({cast:c.cast==="enabled",receive:c.receive==="enabled",updateClass:c.updateClass})]));return Hr({schemaVersion:3,revision:e.revision,enabled:e.config.enabled,scopeId:be(e.scopeId,"$.scopeId"),light:{entityId:e.config.lightRef,direction:yt(e.lightDirection,"$.lightDirection")},qualityProfileId:t,generator:{maps:{...r.maps},...r.cascadeCount===void 0?{}:{cascadeCount:r.cascadeCount},filter:r.receiverFilter,bias:r.bias,normalBias:r.normalBias,darkness:r.darkness,...r.softness===void 0?{}:{softness:r.softness},bounds:na(r.bounds),backend:{...r.backend}},culling:{...r.culling},diagnosticThresholds:{...r.diagnostics},behaviorProfiles:s,objects:o,diagnostics:[]})}function Br(e,t){if(e!==void 0)return typeof e!="boolean"&&N(t,"expected a boolean"),e}function Ws(e,t){let n=le(e,t);ye(n,["mode","center","extent","near","far"],t),n.mode!=="fixed"&&N(`${t}.mode`,"expected fixed"),yt(n.center,`${t}.center`),yt(n.extent,`${t}.extent`).some(s=>s<=0)&&N(`${t}.extent`,"expected positive values");let i=qt(n.near,`${t}.near`),o=qt(n.far,`${t}.far`);(i<0||o<=i)&&N(t,"expected 0 <= near < far")}function qs(e,t){let n=le(e,t);ye(n,["maps","cascadeCount","receiverFilter","bias","normalBias","darkness","softness","bounds","backend","culling","diagnostics"],t),Xs(n.maps,`${t}.maps`),n.cascadeCount!==void 0&&Zs(n.cascadeCount,`${t}.cascadeCount`),n.receiverFilter!=="hard"&&n.receiverFilter!=="low-pcf"&&N(`${t}.receiverFilter`,"expected hard or low-pcf"),bt(n.bias,`${t}.bias`,0,.1),bt(n.normalBias,`${t}.normalBias`,0,1),bt(n.darkness,`${t}.darkness`,0,1),n.softness!==void 0&&bt(n.softness,`${t}.softness`,0,1),Ws(n.bounds,`${t}.bounds`),Ys(n.backend,`${t}.backend`),Qs(n.culling,`${t}.culling`),ea(n.diagnostics,`${t}.diagnostics`)}function Js(e,t){let n=le(e,t);ye(n,["cast","receive","updateClass"],t),n.cast!=="enabled"&&n.cast!=="disabled"&&N(`${t}.cast`,"expected enabled or disabled"),n.receive!=="enabled"&&n.receive!=="disabled"&&N(`${t}.receive`,"expected enabled or disabled"),["auto","static","dynamic","skinned"].includes(String(n.updateClass))||N(`${t}.updateClass`,"expected auto, static, dynamic, or skinned")}function Xs(e,t){let n=le(e,t);ye(n,["staticResolution","dynamicResolution","compositeResolution"],t),On(n.staticResolution,`${t}.staticResolution`),On(n.dynamicResolution,`${t}.dynamicResolution`),On(n.compositeResolution,`${t}.compositeResolution`)}function On(e,t){e!==512&&e!==1024&&e!==2048&&e!==4096&&N(t,"expected 512, 1024, 2048, or 4096")}function Zs(e,t){e!==1&&e!==2&&e!==4&&N(t,"expected 1, 2, or 4")}function Ys(e,t){let n=le(e,t);ye(n,["mode","fallback"],t),["auto","split","single"].includes(String(n.mode))||N(`${t}.mode`,"expected auto, split, or single"),n.fallback!=="single-map"&&n.fallback!=="disable"&&N(`${t}.fallback`,"expected single-map or disable")}function Qs(e,t){let n=le(e,t);ye(n,["enabled","guardBandRatio"],t),typeof n.enabled!="boolean"&&N(`${t}.enabled`,"expected boolean"),bt(n.guardBandRatio,`${t}.guardBandRatio`,0,4)}function ea(e,t){let n=le(e,t);ye(n,["staticCasterCountWarning","dynamicCasterCountWarning","renderableCountWarning"],t),Gn(n.staticCasterCountWarning,`${t}.staticCasterCountWarning`),Gn(n.dynamicCasterCountWarning,`${t}.dynamicCasterCountWarning`),Gn(n.renderableCountWarning,`${t}.renderableCountWarning`)}function ta(e){let t=new Set,n=new Set;for(let r of e){t.has(r.entityId)&&N("$.objects",`duplicate entity id: ${r.entityId}`),t.add(r.entityId);for(let i of r.renderableIds)n.has(i)&&N("$.objects",`duplicate renderable id: ${i}`),n.add(i)}}function Vr(e,t){let n=le(e,t);Object.keys(n).length===0&&N(t,"expected at least one profile");for(let r of Object.keys(n))be(r,`${t} key`);return n}function vn(e,t,n,r){return Object.prototype.hasOwnProperty.call(e,t)||N(n,`unknown ${r} profile: ${t}`),e[t]}function na(e){return Object.freeze({mode:"fixed",center:yt(e.center,"$.bounds.center"),extent:yt(e.extent,"$.bounds.extent"),near:e.near,far:e.far})}function yt(e,t){let n=ia(e,t);return n.length!==3&&N(t,"expected exactly three numbers"),Object.freeze(n.map((r,i)=>qt(r,`${t}[${i}]`)))}function ra(e,t){let n=e.map((r,i)=>be(r,`${t}[${i}]`));return new Set(n).size!==n.length&&N(t,"expected unique strings"),n}function qt(e,t){return(typeof e!="number"||!Number.isFinite(e))&&N(t,"expected a finite number"),e}function bt(e,t,n,r){let i=qt(e,t);return(i<n||i>r)&&N(t,`expected ${n}..${r}`),i}function Gn(e,t){return(!Number.isInteger(e)||e<0)&&N(t,"expected a non-negative integer"),e}function be(e,t){return(typeof e!="string"||!e.trim()||e!==e.trim())&&N(t,"expected a trimmed non-empty string"),e}function le(e,t){(!e||typeof e!="object"||Array.isArray(e))&&N(t,"expected an object");let n=Object.getPrototypeOf(e);return n!==Object.prototype&&n!==null&&N(t,"expected a plain object"),e}function ia(e,t){return Array.isArray(e)||N(t,"expected an array"),e}function ye(e,t,n){let r=new Set(t);for(let i of Object.keys(e))r.has(i)||N(`${n}.${i}`,"unknown field")}function Hr(e){if(!e||typeof e!="object"||Object.isFrozen(e))return e;for(let t of Object.values(e))Hr(t);return Object.freeze(e)}function N(e,t){throw new Error(`shadow_map_experiment_invalid:${e}:${t}`)}var Wr=["useBlobShadow","blobSettings"],oa=["resolution","maxSize"],sa=new Set(["none","blob","static","planar","dynamic"]);function qr(e){let t=je(e);if(!t)throw v("schema.invalidType","$");for(let i of Wr)if(Object.prototype.hasOwnProperty.call(t,i))throw v("schema.deprecatedField",`$.${i}`);if(O(t,["globalVolume","materials","renderingGroups","shadowMeshes","shadows"],"$"),ca(t.globalVolume,"$.globalVolume"),la(t.materials,"$.materials"),aa(t.renderingGroups,"$.renderingGroups"),da(t.globalVolume,"$.globalVolume"),ba(t.shadowMeshes,"$.shadowMeshes"),!Object.prototype.hasOwnProperty.call(t,"shadows"))return;let n=je(t.shadows);if(!n)throw v("schema.invalidType","$.shadows");for(let i of Wr)if(Object.prototype.hasOwnProperty.call(n,i))throw v("schema.deprecatedField",`$.shadows.${i}`);if(O(n,["defaultMode","enabled","useCsm","settings","blob","staticProjected","planar","shadowRange","shadowOrtho","csm"],"$.shadows"),"defaultMode"in n&&!sa.has(String(n.defaultMode)))throw v("schema.invalidValue","$.shadows.defaultMode");ee(n,"enabled","$.shadows"),ee(n,"useCsm","$.shadows");let r=je(n.settings);if(Object.prototype.hasOwnProperty.call(n,"settings")&&!r)throw v("schema.invalidType","$.shadows.settings");if(r){O(r,["mapSize","darkness","blurKernel","bias","normalBias","shadowMinZ","shadowMaxZ","useBlurExponentialShadowMap","shadowColor"],"$.shadows.settings");for(let i of["mapSize","darkness","blurKernel","bias","normalBias","shadowMinZ","shadowMaxZ"])X(r,i,"$.shadows.settings");ee(r,"useBlurExponentialShadowMap","$.shadows.settings"),Jt(r.shadowColor,"$.shadows.settings.shadowColor",!1)}fa(n.blob,"$.shadows.blob"),ma(n.staticProjected,"$.shadows.staticProjected"),ga(n.planar,"$.shadows.planar"),Fe(n.shadowRange,"$.shadows.shadowRange",["minZ","maxZ"]),Fe(n.shadowOrtho,"$.shadows.shadowOrtho",["left","right","top","bottom"]),pa(n.csm,"$.shadows.csm")}function aa(e,t){if(e===void 0)return;let n=je(e);if(!n||!Array.isArray(n.slots))throw v("schema.invalidType",t);O(n,["slots"],t),n.slots.forEach((r,i)=>{let o=`${t}.slots[${i}]`,s=je(r);if(!s)throw v("schema.invalidType",o);if(O(s,["renderingGroupId","name","alphaIndexPresets"],o),![0,1,2,3].includes(s.renderingGroupId))throw v("schema.invalidValue",`${o}.renderingGroupId`);if(typeof s.name!="string"||!s.name.trim())throw v("schema.invalidValue",`${o}.name`);if(!Array.isArray(s.alphaIndexPresets))throw v("schema.invalidType",`${o}.alphaIndexPresets`);s.alphaIndexPresets.forEach((a,c)=>{let d=`${o}.alphaIndexPresets[${c}]`,u=je(a);if(!u)throw v("schema.invalidType",d);if(O(u,["name","alphaIndex"],d),typeof u.name!="string"||!u.name.trim())throw v("schema.invalidValue",`${d}.name`);_n(u,"alphaIndex",d)})})}function da(e,t){if(e===void 0)return;let n=K(e,t);for(let o of["samples","camera","lights"])if(o in n)throw v("schema.deprecatedField",`${t}.${o}`);if(O(n,["enabled","hdr","environment","imageProcessing","toneMapping","antialiasing","postProcessing","rendering","textures"],t),ee(n,"enabled",t),ee(n,"hdr",t),n.environment!==void 0){let o=K(n.environment,`${t}.environment`);for(let s of["textureAssetId","textureUrl","intensity"])if(s in o)throw v("schema.deprecatedField",`${t}.environment.${s}`);if(O(o,["texture","iblIntensity","rotationY","useCocosIBL"],`${t}.environment`),o.texture!==void 0&&o.texture!==null){let s=K(o.texture,`${t}.environment.texture`);for(let a of Object.keys(s))if(a!=="textureAssetId"&&a!=="url")throw v("schema.deprecatedField",`${t}.environment.texture.${a}`);for(let a of["textureAssetId","url"])if(a in s&&s[a]!=null&&(typeof s[a]!="string"||!s[a].trim()))throw v("schema.invalidValue",`${t}.environment.texture.${a}`)}X(o,"iblIntensity",`${t}.environment`),X(o,"rotationY",`${t}.environment`),ee(o,"useCocosIBL",`${t}.environment`)}if(Fe(n.imageProcessing,`${t}.imageProcessing`,["exposure","contrast"]),n.toneMapping!==void 0){let o=K(n.toneMapping,`${t}.toneMapping`);if(O(o,["enabled","type"],`${t}.toneMapping`),ee(o,"enabled",`${t}.toneMapping`),"type"in o&&!["standard","aces","khr-pbr-neutral"].includes(String(o.type)))throw v("schema.invalidValue",`${t}.toneMapping.type`)}if(n.antialiasing!==void 0){let o=K(n.antialiasing,`${t}.antialiasing`);if(O(o,["samples"],`${t}.antialiasing`),"samples"in o&&![1,2,4,8].includes(o.samples))throw v("schema.invalidValue",`${t}.antialiasing.samples`)}let r=ue(n.postProcessing,`${t}.postProcessing`);r&&O(r,["bloom"],`${t}.postProcessing`);let i=r?ue(r.bloom,`${t}.postProcessing.bloom`):null;if(i){O(i,["enabled","threshold","weight","kernel","scale"],`${t}.postProcessing.bloom`),ee(i,"enabled",`${t}.postProcessing.bloom`);for(let o of["threshold","weight","kernel","scale"])X(i,o,`${t}.postProcessing.bloom`)}}function ca(e,t){if(e===void 0)return;let n=K(e,t),r=ue(n.rendering,`${t}.rendering`);r&&(O(r,["maxDpr","hardwareScalingLevel"],`${t}.rendering`),X(r,"maxDpr",`${t}.rendering`),ua(r,"hardwareScalingLevel",`${t}.rendering`));let i=ue(n.textures,`${t}.textures`);if(i&&(O(i,["anisotropicFilteringLevel","samplingMode"],`${t}.textures`),X(i,"anisotropicFilteringLevel",`${t}.textures`),"samplingMode"in i&&(typeof i.samplingMode!="string"||!i.samplingMode.trim())))throw v("schema.invalidValue",`${t}.textures.samplingMode`)}function la(e,t){if(e===void 0)return;let n=K(e,t);O(n,["sceneMaterials","plantMaterials"],t);for(let r of["sceneMaterials","plantMaterials"])r in n&&K(n[r],`${t}.${r}`)}function ua(e,t,n){!(t in e)||e[t]==null||X(e,t,n)}function fa(e,t){if(e===void 0)return;let n=K(e,t);O(n,["enabled","plane","appearance","size"],t),ee(n,"enabled",t),Fe(n.plane,`${t}.plane`,["height","yOffset"]);let r=ue(n.appearance,`${t}.appearance`);r&&(O(r,["color","edgeSoftness"],`${t}.appearance`),Jt(r.color,`${t}.appearance.color`,!0),X(r,"edgeSoftness",`${t}.appearance`)),Fe(n.size,`${t}.size`,["sizeMultiplier","minSize","maxSize"])}function ma(e,t){if(e===void 0)return;let n=K(e,t);O(n,["enabled","plane","appearance","bake"],t),ee(n,"enabled",t),Fe(n.plane,`${t}.plane`,["height","yOffset"]);let r=ue(n.appearance,`${t}.appearance`);if(r&&(O(r,["color"],`${t}.appearance`),Jt(r.color,`${t}.appearance.color`,!0)),n.bake===void 0)return;let i=K(n.bake,`${t}.bake`);for(let o of oa)if(o in i)throw v("schema.deprecatedField",`${t}.bake.${o}`);O(i,["padding","blur","texelsPerMeter","atlasSize","maxAtlasPages","sdfRadiusPx","spatialChunkSize","targetChunkCount"],`${t}.bake`);for(let o of["padding","blur","texelsPerMeter","atlasSize","maxAtlasPages","sdfRadiusPx","spatialChunkSize","targetChunkCount"])X(i,o,`${t}.bake`)}function ga(e,t){if(e===void 0)return;let n=K(e,t);O(n,["enabled","plane","appearance","projection","stencil","casters","receivers"],t),ee(n,"enabled",t);let r=ue(n.plane,`${t}.plane`);if(r){O(r,["normal","height","bias","heightMode"],`${t}.plane`),ya(r.normal,`${t}.plane.normal`);for(let c of["height","bias"])X(r,c,`${t}.plane`);if("heightMode"in r&&!["fixed","receiver"].includes(String(r.heightMode)))throw v("schema.invalidValue",`${t}.plane.heightMode`)}let i=ue(n.appearance,`${t}.appearance`);i&&(O(i,["color"],`${t}.appearance`),Jt(i.color,`${t}.appearance.color`,!0)),Fe(n.projection,`${t}.projection`,["footprintScale"]);let o=ue(n.stencil,`${t}.stencil`);if(o){O(o,["enabled","receiverRenderingGroup","shadowRenderingGroup"],`${t}.stencil`),ee(o,"enabled",`${t}.stencil`);for(let c of["receiverRenderingGroup","shadowRenderingGroup"])X(o,c,`${t}.stencil`)}let s=ue(n.casters,`${t}.casters`);if(s){O(s,["autoDetectAll","includePatterns","excludePatterns","rootBoundaryPatterns","minVolume"],`${t}.casters`),ee(s,"autoDetectAll",`${t}.casters`);for(let c of["includePatterns","excludePatterns","rootBoundaryPatterns"])Fn(s[c],`${t}.casters.${c}`);X(s,"minVolume",`${t}.casters`)}let a=ue(n.receivers,`${t}.receivers`);a&&(O(a,["patterns"],`${t}.receivers`),Fn(a.patterns,`${t}.receivers.patterns`))}function pa(e,t){if(e===void 0)return;let n=K(e,t);O(n,["numCascades","lambda","cascadeBlendPercentage","stabilizeCascades"],t);for(let r of["numCascades","lambda","cascadeBlendPercentage"])X(n,r,t);ee(n,"stabilizeCascades",t)}function ba(e,t){if(e===void 0)return;let n=K(e,t);O(n,["shadowReceivers","shadowCasters","excludeFromShadow"],t);for(let r of["shadowReceivers","shadowCasters","excludeFromShadow"])Fn(n[r],`${t}.${r}`)}function Fe(e,t,n){if(e===void 0)return;let r=K(e,t);O(r,n,t);for(let i of n)X(r,i,t)}function Jt(e,t,n){if(e===void 0)return;let r=K(e,t),i=n?["r","g","b","a"]:["r","g","b"];O(r,i,t);for(let o of i)_n(r,o,t)}function ya(e,t){if(e===void 0)return;let n=K(e,t);O(n,["x","y","z"],t);for(let r of["x","y","z"])_n(n,r,t)}function Fn(e,t){if(e!==void 0&&(!Array.isArray(e)||e.some(n=>typeof n!="string")))throw v("schema.invalidType",t)}function _n(e,t,n){if(!(t in e))throw v("schema.invalidValue",`${n}.${t}`);X(e,t,n)}function ue(e,t){return e===void 0?null:K(e,t)}function K(e,t){let n=je(e);if(!n)throw v("schema.invalidType",t);return n}function ee(e,t,n){if(t in e&&typeof e[t]!="boolean")throw v("schema.invalidValue",`${n}.${t}`)}function X(e,t,n){if(!(t in e))return;let r=e[t];if(typeof r!="number"||!Number.isFinite(r))throw v("schema.invalidValue",`${n}.${t}`)}function O(e,t,n){let r=new Set(t);for(let i of Object.keys(e))if(!r.has(i))throw v("schema.unknownField",`${n}.${i}`)}function v(e,t){let n=new Error(`${e}: ${t}`);return Object.assign(n,{code:e,path:t}),n}function je(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function M(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}function Jr(e,t){let n=M(e);return{x:H(n.x,t.x),y:H(n.y,t.y),z:H(n.z,t.z)}}function Ln(e,t){let n=M(e);return{r:Pe(n.r,t.r,0,1),g:Pe(n.g,t.g,0,1),b:Pe(n.b,t.b,0,1)}}function ht(e,t){let n=M(e);return{...Ln(n,t),a:Pe(n.a,t.a,0,1)}}function ke(e){return Array.isArray(e)?e.map(t=>typeof t=="string"?t.trim():"").filter((t,n,r)=>t.length>0&&r.indexOf(t)===n):[]}function zn(e){return(typeof e=="string"?e.trim():"")||null}function Un(e,t){return(typeof e=="string"?e.trim():"")||t}function te(e,t){return typeof e=="boolean"?e:t}function Xr(e){return e===0||e===1||e===2||e===3?e:null}function Zr(e,t){return e==="standard"||e==="aces"||e==="khr-pbr-neutral"?e:t}function Yr(e,t){return e===1||e===2||e===4||e===8?e:t}function Qr(e,t){return e==="fixed"||e==="receiver"?e:t}function ei(e,t){return e==="none"||e==="blob"||e==="static"||e==="planar"||e==="dynamic"?e:t}function H(e,t){return typeof e=="number"&&Number.isFinite(e)?e:t}function G(e,t){let n=H(e,t);return Math.max(0,n)}function Me(e,t){let n=H(e,t);return n>0?n:t}function Pe(e,t,n,r){let i=H(e,t);return Math.min(r,Math.max(n,i))}var ti=["editor","grid","gizmo","helper","camera","light","decal","texture","trigger","collision","ui","_shadow","_planarShadow"],ni=[...ti,"_blobShadow"],ha=[...ni,"_staticProjectedShadow"];var ri=[{renderingGroupId:0,name:"\u666E\u901A\u573A\u666F",alphaIndexPresets:[{name:"\u9ED8\u8BA4\u900F\u660E\u987A\u5E8F",alphaIndex:0},{name:"\u5730\u8868\u8D34\u82B1",alphaIndex:100},{name:"\u8FD1\u666F\u8986\u76D6",alphaIndex:200}]},{renderingGroupId:1,name:"\u6C34\u9762 / \u900F\u660E\u5730\u8868",alphaIndexPresets:[{name:"\u6C34\u9762",alphaIndex:0},{name:"\u900F\u660E\u5730\u8868",alphaIndex:100},{name:"\u6C34\u9762\u9AD8\u5149",alphaIndex:200}]},{renderingGroupId:2,name:"\u7279\u6548",alphaIndexPresets:[{name:"\u666E\u901A\u7279\u6548",alphaIndex:0},{name:"\u524D\u666F\u7279\u6548",alphaIndex:100},{name:"\u6700\u524D\u7279\u6548",alphaIndex:200}]},{renderingGroupId:3,name:"\u4E16\u754C\u7A7A\u95F4 UI / \u5F15\u5BFC\u7BAD\u5934",alphaIndexPresets:[{name:"\u4E16\u754C\u7A7A\u95F4 UI",alphaIndex:0},{name:"\u5F15\u5BFC\u7BAD\u5934",alphaIndex:100},{name:"\u9876\u5C42\u63D0\u793A",alphaIndex:200}]}];function Xt(e){e!=null&&qr(e);let t=M(e),n=M(t.shadows),r=M(n.settings),i=M(n.blob),o=Sa(i),s=Pa(n.staticProjected),a=M(n.shadowRange),c=M(n.shadowOrtho),d=M(n.csm),u=M(t.shadowMeshes);return{renderingGroups:ii(t.renderingGroups),environment:Ia(t.globalVolume),postProcess:Ea(t.globalVolume),shadows:{defaultMode:ei(n.defaultMode,"none"),enabled:te(n.enabled,!1),useCsm:te(n.useCsm,!1),settings:{mapSize:G(r.mapSize,1024),darkness:G(r.darkness,.3),blurKernel:G(r.blurKernel,16),bias:G(r.bias,5e-5),normalBias:G(r.normalBias,.02),useBlurExponentialShadowMap:te(r.useBlurExponentialShadowMap,!0),shadowMinZ:G(r.shadowMinZ,1),shadowMaxZ:G(r.shadowMaxZ,60),shadowColor:Ln(r.shadowColor,{r:0,g:0,b:0})},blob:o,staticProjected:s,shadowRange:{minZ:G(a.minZ,1),maxZ:G(a.maxZ,60)},shadowOrtho:{left:H(c.left,-20),right:H(c.right,20),top:H(c.top,20),bottom:H(c.bottom,-20)},csm:{numCascades:G(d.numCascades,2),lambda:Pe(d.lambda,.5,0,1),cascadeBlendPercentage:Pe(d.cascadeBlendPercentage,.1,0,1),stabilizeCascades:te(d.stabilizeCascades,!0)},planar:xa(n.planar)},shadowMeshes:{shadowReceivers:ke(u.shadowReceivers),shadowCasters:ke(u.shadowCasters),excludeFromShadow:ke(u.excludeFromShadow)}}}function Sa(e){let t=M(e),n=M(t.plane),r=M(t.appearance),i=M(t.size),o=ht(r.color,{r:0,g:0,b:0,a:.35});return{enabled:te(t.enabled,!0),plane:{height:H(n.height,0),yOffset:G(n.yOffset,.08)},appearance:{color:ht(r.color,o),edgeSoftness:Pe(r.edgeSoftness,.55,0,.98)},size:{sizeMultiplier:G(i.sizeMultiplier,1.25),minSize:G(i.minSize,.25),maxSize:Me(i.maxSize,20)}}}function ii(e){let t=M(e),n=Array.isArray(t.slots)?t.slots:[];return{slots:ri.map(r=>{let i=n.find(s=>Xr(M(s).renderingGroupId)===r.renderingGroupId),o=M(i);return{renderingGroupId:r.renderingGroupId,name:Un(o.name,r.name),alphaIndexPresets:oi(o.alphaIndexPresets,r.alphaIndexPresets)}})}}function oi(e,t){let n=Array.isArray(e)?e:t,r=new Set,i=[];return n.forEach((o,s)=>{let a=M(o),c=H(a.alphaIndex,Number.NaN);!Number.isFinite(c)||r.has(c)||(r.add(c),i.push({name:Un(a.name,`Order ${s+1}`),alphaIndex:c}))}),i}function xa(e){let t=M(e),n=M(t.plane),r=M(t.appearance),i=M(t.projection),o=M(t.stencil),s=M(t.casters),a=M(t.receivers);return{enabled:te(t.enabled,!0),plane:{normal:Jr(n.normal,{x:0,y:1,z:0}),height:H(n.height,0),heightMode:Qr(n.heightMode,"receiver"),bias:G(n.bias,.4)},appearance:{color:ht(r.color,{r:0,g:0,b:0,a:.35})},projection:{footprintScale:Pe(i.footprintScale,1,0,2)},stencil:{enabled:te(o.enabled,!0),receiverRenderingGroup:G(o.receiverRenderingGroup,0),shadowRenderingGroup:G(o.shadowRenderingGroup,1)},casters:{autoDetectAll:te(s.autoDetectAll,!0),includePatterns:ke(s.includePatterns),excludePatterns:ke(s.excludePatterns),rootBoundaryPatterns:ke(s.rootBoundaryPatterns),minVolume:G(s.minVolume,.001)},receivers:{patterns:ke(a.patterns)}}}function Pa(e){let t=M(e),n=M(t.plane),r=M(t.appearance),i=M(t.bake),o=Me(i.spatialChunkSize,16);return{enabled:te(t.enabled,!1),plane:{height:H(n.height,0),yOffset:G(n.yOffset,.08)},appearance:{color:ht(r.color,{r:0,g:0,b:0,a:.35})},bake:{padding:G(i.padding,.15),blur:G(i.blur,0),texelsPerMeter:Me(i.texelsPerMeter,256),atlasSize:Me(i.atlasSize,4096),maxAtlasPages:Me(i.maxAtlasPages,8),sdfRadiusPx:G(i.sdfRadiusPx,8),spatialChunkSize:o,targetChunkCount:Me(i.targetChunkCount,64)}}}function Ia(e){let t=M(e),n=M(t.environment),r=M(n.texture),i=zn(r.textureAssetId),o=zn(r.url);return{texture:i||o?{...i?{textureAssetId:i}:{},...o?{url:o}:{}}:null,iblIntensity:G(n.iblIntensity,1),rotationY:H(n.rotationY,0)}}function Ea(e){let t=M(e),n=M(t.imageProcessing),r=M(t.toneMapping),i=M(t.antialiasing),o=M(t.postProcessing),s=M(o.bloom);return{enabled:te(t.enabled,!0),hdr:te(t.hdr,!0),imageProcessing:{exposure:H(n.exposure,1),contrast:H(n.contrast,1)},toneMapping:{enabled:te(r.enabled,!0),type:Zr(r.type,"aces")},antialiasing:{samples:Yr(i.samples,4)},bloom:{enabled:te(s.enabled,!1),threshold:G(s.threshold,.9),weight:G(s.weight,.2),kernel:G(s.kernel,64),scale:Me(s.scale,.5)}}}var Aa=new Set([".glb",".gltf",".png",".jpg",".jpeg",".webp",".env",".hdr",".dds",".ktx",".ktx2",".mp3",".wav",".ogg",".flac",".aac",".m4a"]);function si(e){let t=String(e??"").trim().toLowerCase();if(/^\.[a-z0-9]+$/.test(t))return t;let n=t.split(/[?#]/,1)[0]??"",r=n.slice(n.lastIndexOf("/")+1),i=r.lastIndexOf(".");return i<=0||i===r.length-1?null:r.slice(i)}function ai(e){return Aa.has(e)}function Zt(e){return e==="fps.builtin.pbr"||e==="fps.builtin.standard"?e:void 0}function di(e){if(!e||typeof e!="object")return;let t={};(e.lightingModel==="lit"||e.lightingModel==="unlit")&&(t.lightingModel=e.lightingModel);let n={},r=ci(e.baseColor?.color);r&&(n.color=r);let i=_e(e.baseColor?.texture);i!==void 0&&(n.texture=i),Ie(e.baseColor,n,"brightness"),Ie(e.baseColor,n,"saturation"),Ie(e.baseColor,n,"contrast"),Ie(e.baseColor,n,"hue"),Object.keys(n).length>0&&(t.baseColor=n);let o={},s=_e(e.normal?.texture);s!==void 0&&(o.texture=s),Ie(e.normal,o,"strength"),Object.keys(o).length>0&&(t.normal=o),Xe(e.metallic)&&(t.metallic=e.metallic),Xe(e.roughness)&&(t.roughness=e.roughness);let a={},c=_e(e.metallicRoughness?.texture);c!==void 0&&(a.texture=c),Object.keys(a).length>0&&(t.metallicRoughness=a);let d={},u=_e(e.occlusion?.texture);u!==void 0&&(d.texture=u),Ie(e.occlusion,d,"strength"),Object.keys(d).length>0&&(t.occlusion=d);let l={},f=ci(e.emission?.color);f&&(l.color=f),Ie(e.emission,l,"intensity");let g=_e(e.emission?.texture);g!==void 0&&(l.texture=g);let p=_e(e.emission?.maskTexture);p!==void 0&&(l.maskTexture=p),Object.keys(l).length>0&&(t.emission=l);let h={};(e.alpha?.mode==="opaque"||e.alpha?.mode==="mask"||e.alpha?.mode==="blend")&&(h.mode=e.alpha.mode),Ie(e.alpha,h,"opacity"),Ie(e.alpha,h,"cutoff");let S=_e(e.alpha?.texture);return S!==void 0&&(h.texture=S),Object.keys(h).length>0&&(t.alpha=h),Object.keys(t).length>0?t:void 0}function Bn(...e){let t={};for(let n of e){let r=di(n);r&&(r.lightingModel&&(t.lightingModel=r.lightingModel),Je(t,r,"baseColor"),Je(t,r,"normal"),r.metallic!==void 0&&(t.metallic=r.metallic),r.roughness!==void 0&&(t.roughness=r.roughness),Je(t,r,"metallicRoughness"),Je(t,r,"occlusion"),Je(t,r,"emission"),Je(t,r,"alpha"))}return di(t)??{}}function Je(e,t,n){let r=t[n];r&&Object.assign(e,{[n]:{...e[n]??{},...r}})}function ci(e){return e&&Xe(e.r)&&Xe(e.g)&&Xe(e.b)?{r:e.r,g:e.g,b:e.b}:void 0}function _e(e){if(e===null)return null;if(!e||typeof e!="object")return;let t=typeof e.url=="string"?e.url.trim():"",n=typeof e.textureAssetId=="string"?e.textureAssetId.trim():"";if(!(!t&&!n))return{...t?{url:t}:{},...n?{textureAssetId:n}:{}}}function Ie(e,t,n){Xe(e?.[n])&&(t[n]=e[n])}function Xe(e){return typeof e=="number"&&Number.isFinite(e)}function wa(e){let t=Ae(e);if(!t)return null;let n=B(t.sourceHash),r=B(t.lightHash),i=B(t.profileHash);if(!n||!r||!i)return null;let o={sourceHash:n,lightHash:r,profileHash:i,...typeof t.generatedAt=="string"&&t.generatedAt.trim()?{generatedAt:t.generatedAt.trim()}:{},...(()=>{let u=Na(t.stats);return u?{stats:u}:{}})()};if(t.version!==2||t.format!=="sdf-atlas"||!Array.isArray(t.pages)||!Array.isArray(t.chunks))return null;let s=[],a=new Map;for(let u of t.pages){let l=Ta(u);if(!l||a.has(l.id))return null;s.push(l),a.set(l.id,l)}let c=[],d=new Set;for(let u of t.chunks){let l=Da(u,a);if(!l||d.has(l.id))return null;c.push(l),d.add(l.id)}return{version:2,format:"sdf-atlas",pages:s,chunks:c,...o}}function nn(e,t="$.staticShadows"){let n=wa(e);if(n)return n;let r=new Error(`schema.unsupportedVersion: ${t}`);throw Object.assign(r,{code:"schema.unsupportedVersion",path:t}),r}function Ta(e){let t=Ae(e);if(!t)return null;let n=B(t.id),r=tn(t.width),i=tn(t.height),o=Oa(t.sdfTextureDataUrl);return!n||r==null||i==null||!o?null:{id:n,width:r,height:i,sdfTextureDataUrl:o}}function Da(e,t){let n=Ae(e);if(!n)return null;let r=B(n.id),i=Ra(n.bounds),o=$a(n.plane),s=B(n.pageId),a=Ma(n.atlasRect),c=Ca(n.atlasUv),d=va(n.sourceNodeIds),u=B(n.sourceHash),l=B(n.lightHash),f=B(n.profileHash);if(!r||!i||!o||!s||!a||!c||!d||!u||!l||!f)return null;let g=t.get(s);return!g||a.x+a.width>g.width||a.y+a.height>g.height?null:{id:r,bounds:i,plane:o,pageId:s,atlasRect:a,atlasUv:c,sourceNodeIds:d,sourceHash:u,lightHash:l,profileHash:f,...(()=>{let p=ka(n.binding);return p?{binding:p}:{}})()}}function ka(e){let t=Ae(e);if(!t)return null;let n=B(t.id),r=B(t.ownerCasterId),i=B(t.receiverId),o=B(t.generatedAt),s=B(t.sourceHash);if(!n||!r||!i||!o||!s||t.visibleWhenOwnerVisible!==!0||t.staleWhenOwnerTransformChanges!==!0||t.staleWhenLightChanges!==!0)return null;let a=B(t.lightId),c=B(t.textureAssetId),d=B(t.projectionNodeId);return{id:n,ownerCasterId:r,receiverId:i,...a?{lightId:a}:{},...c?{textureAssetId:c}:{},...d?{projectionNodeId:d}:{},visibleWhenOwnerVisible:!0,staleWhenOwnerTransformChanges:!0,staleWhenLightChanges:!0,generatedAt:o,sourceHash:s}}function Ma(e){let t=Ae(e);if(!t)return null;let n=Ce(t.x),r=Ce(t.y),i=tn(t.width),o=tn(t.height);return n==null||r==null||i==null||o==null?null:{x:n,y:r,width:i,height:o}}function Ca(e){let t=Ae(e);if(!t)return null;let n=Yt(t.u0),r=Yt(t.v0),i=Yt(t.u1),o=Yt(t.v1);return n==null||r==null||i==null||o==null||i<=n||o<=r?null:{u0:n,v0:r,u1:i,v1:o}}function Ra(e){let t=Ae(e);if(!t)return null;let n=he(t.minX),r=he(t.maxX),i=he(t.minZ),o=he(t.maxZ),s=he(t.y);return n==null||r==null||i==null||o==null||s==null||r<=n||o<=i?null:{minX:n,maxX:r,minZ:i,maxZ:o,y:s}}function $a(e){let t=Ae(e);if(!t)return null;let n=he(t.height),r=he(t.yOffset);return n==null||r==null||r<0?null:{height:n,yOffset:r}}function Na(e){let t=Ae(e);if(!t)return null;let n=Ce(t.sourceRootCount),r=Ce(t.sourceMeshCount),i=Ce(t.attemptedChunkCount),o=Ce(t.chunkCount),s=Ce(t.textureCount);return n==null||r==null||i==null||o==null||s==null?null:{sourceRootCount:n,sourceMeshCount:r,attemptedChunkCount:i,chunkCount:o,textureCount:s,...Qt(t.skippedChunkCount,"skippedChunkCount"),...Qt(t.pageCount,"pageCount"),...Ee(t.resolution,"resolution"),...Ee(t.chunkSize,"chunkSize"),...Ee(t.atlasSize,"atlasSize"),...en(t.atlasUsedPixels,"atlasUsedPixels"),...en(t.atlasAllocatedPixels,"atlasAllocatedPixels"),...Ga(t.atlasOccupancy,"atlasOccupancy"),...Ee(t.texelsPerMeter,"texelsPerMeter"),...Ee(t.effectiveTexelsPerMeter,"effectiveTexelsPerMeter"),...Ee(t.maxAtlasPages,"maxAtlasPages"),...en(t.sdfRadiusPx,"sdfRadiusPx"),...Ee(t.spatialChunkSize,"spatialChunkSize"),...Ee(t.effectiveSpatialChunkSize,"effectiveSpatialChunkSize"),...Ee(t.targetChunkCount,"targetChunkCount"),...Qt(t.bakedChunkCount,"bakedChunkCount"),...Qt(t.reusedChunkCount,"reusedChunkCount"),...en(t.durationMs,"durationMs")}}function Oa(e){let t=B(e);return t&&/^data:image\/png[;,]/i.test(t)?t:null}function va(e){if(!Array.isArray(e)||e.length===0)return null;let t=[],n=new Set;for(let r of e){let i=B(r);if(!i)return null;n.has(i)||t.push(i),n.add(i)}return t}function B(e){return typeof e=="string"&&e.trim()?e.trim():null}function he(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function Ce(e){return typeof e=="number"&&Number.isInteger(e)&&e>=0?e:null}function tn(e){return typeof e=="number"&&Number.isInteger(e)&&e>0?e:null}function Yt(e){return typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=1?e:null}function Qt(e,t){let n=Ce(e);return n==null?{}:{[t]:n}}function Ee(e,t){let n=he(e);return n==null||n<=0?{}:{[t]:n}}function en(e,t){let n=he(e);return n==null||n<0?{}:{[t]:n}}function Ga(e,t){let n=he(e);return n==null||n<0||n>1?{}:{[t]:n}}function Ae(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}var ja="@fps-games/editor.playable-sdk.scene-compiler",Fa="2",_a=1e-4,se={nodeKinds:["group","instance","transform","primitive","image"],primitiveShapes:["cube","sphere","plane","capsule"],transformTypes:["plain","light","camera","groundDecal"],assetTypes:["glb","texture"],materialScopes:["sharedAsset","nodeMaterial"],materialModes:["shared","instance"],materialShaderIds:["fps.builtin.pbr","fps.builtin.standard"],materialAssetSystemPresets:["default-pbr","default-standard"],runtimeV3:{assetFields:["id","guid","type","url","external","warmupCount","singleton","materialMode","defaults","materialSlots"],materialSlotFields:["slotId","label","sourceSurfaces"],materialSlotSourceSurfaceFields:["ownerNodePath","nodeIndex","nodeIndexPath","meshIndex","primitiveIndex","sourceMaterialIndex","sourceMeshName"]},hierarchy:{parentTargets:["root","sceneNode"]},runtimeOnlyTokens:["/@fs","assetUrl","sourceAssetUrl","sourceAssetPath"]},La=new Set(se.nodeKinds),za=new Set(se.primitiveShapes),Ua=new Set(se.assetTypes),Ba=new Set(se.materialModes),Va=new Set(se.materialScopes),Ka=new Set(se.materialAssetSystemPresets),Ha=new Set(se.transformTypes),St=new Set(se.hierarchy.parentTargets),Wa=se.runtimeOnlyTokens,qa=new Set(se.runtimeV3.assetFields),Ja=new Set(se.runtimeV3.materialSlotFields),Xa=new Set(se.runtimeV3.materialSlotSourceSurfaceFields);function Za(e,t={}){let{allowOrphanSharedMaterials:n=!0,allowOrphanNodeMaterials:r=!0,strictAssetIds:i=[],strictNodeIds:o=[],maxErrors:s=50}=t,a=Number.isInteger(s)&&s>0?s:50,c=[],d=new Set(i),u=new Set(o),l=(m,L)=>{c.length<a&&c.push({path:m,message:L})};if(!x(e))return l("$","scene json must be an object"),c;let f=e.schemaVersion;f!==2&&f!==3&&l("$.schemaVersion","schemaVersion must be 2 or 3"),fd(e.meta?.generatedFrom,"$.meta.generatedFrom",l);let g=Pd(e),p=e.scene;if(!x(p))return l("$.scene","scene must be an object"),c;if(E(p.rootId)||l("$.scene.rootId","rootId must be a non-empty string"),Array.isArray(p.assets)||l("$.scene.assets","assets must be an array"),Array.isArray(p.nodes)||l("$.scene.nodes","nodes must be an array"),Array.isArray(p.materialAssets)||l("$.scene.materialAssets","materialAssets must be an array"),Array.isArray(p.materials)||l("$.scene.materials","materials must be an array"),Array.isArray(p.textures)||l("$.scene.textures","textures must be an array"),c.length>0)return c;e.staticShadows!=null&&li(()=>nn(e.staticShadows,"$.staticShadows"),"$.staticShadows",l);let h=new Set,S=new Map,P=new Map,D=new Set,T=new Set([p.rootId]),$=new Map,_=new Map,q=new Set;return p.assets.forEach((m,L)=>{let b=`$.scene.assets[${L}]`;if(!x(m)){l(b,"asset must be an object");return}if(E(m.id)?h.has(m.id)?l(`${b}.id`,`duplicate asset id: ${m.id}`):(h.add(m.id),S.set(m.id,m.type)):l(`${b}.id`,"asset.id must be a non-empty string"),Ua.has(m.type)||l(`${b}.type`,"asset.type must be glb or texture"),m.guid!=null&&!E(m.guid)&&l(`${b}.guid`,"asset.guid must be a non-empty string when present"),m.url!=null&&!E(m.url)&&l(`${b}.url`,"url must be a non-empty string when present"),m.external!=null&&!x(m.external)&&l(`${b}.external`,"external must be an object when present"),m.warmupCount!=null&&(!Number.isInteger(m.warmupCount)||m.warmupCount<0)&&l(`${b}.warmupCount`,"warmupCount must be a non-negative integer when present"),m.singleton!=null&&typeof m.singleton!="boolean"&&l(`${b}.singleton`,"singleton must be a boolean when present"),m.materialMode!=null&&!Ba.has(m.materialMode)&&l(`${b}.materialMode`,"materialMode must be shared or instance"),ud(m.defaults,`${b}.defaults`,l),f===3)for(let z of Object.keys(m))qa.has(z)||l(`${b}.${z}`,`runtime schema v3 asset field is not allowed: ${z}`);else m.displayName!=null&&!E(m.displayName)&&l(`${b}.displayName`,"displayName must be a non-empty string when present"),m.category!=null&&!E(m.category)&&l(`${b}.category`,"category must be a non-empty string when present"),m.metadata!=null&&!x(m.metadata)&&l(`${b}.metadata`,"metadata must be an object when present");let j=f===3?m.materialSlots:x(m.metadata)?m.metadata.materialSlots:void 0,W=f===3?`${b}.materialSlots`:`${b}.metadata.materialSlots`,J=new Set;j!=null&&(Array.isArray(j)?j.forEach((z,jt)=>{let We=`${W}[${jt}]`;if(!x(z)||!E(z.slotId)){l(We,f===3?"material slot must contain a stable slotId":"material slot must contain stable slotId and ownerNodePath");return}if(f!==3&&!E(z.ownerNodePath)){l(We,"material slot must contain stable slotId and ownerNodePath");return}J.has(z.slotId)?l(`${We}.slotId`,`duplicate material slot id: ${z.slotId}`):J.add(z.slotId),f===3&&ld(z,We,l)}):l(W,"materialSlots must be an array when present")),E(m.id)&&P.set(m.id,J),d.has(m.id)&&mi(m,b,l)}),p.nodes.forEach((m,L)=>{let b=`$.scene.nodes[${L}]`;if(!x(m)){l(b,"node must be an object");return}E(m.id)&&$.set(m.id,m),E(m.id)?T.has(m.id)?l(`${b}.id`,`duplicate node id: ${m.id}`):(T.add(m.id),typeof m.kind=="string"&&_.set(m.id,m.kind),m.kind==="transform"&&Object.prototype.hasOwnProperty.call(m,"marker")&&q.add(m.id)):l(`${b}.id`,"node.id must be a non-empty string"),La.has(m.kind)||l(`${b}.kind`,"node.kind must be group, instance, transform, primitive, or image")}),p.materialAssets.forEach((m,L)=>{let b=`$.scene.materialAssets[${L}]`;if(!x(m)){l(b,"material asset must be an object");return}E(m.id)?D.has(m.id)?l(`${b}.id`,`duplicate material asset id: ${m.id}`):D.add(m.id):l(`${b}.id`,"material asset id must be a non-empty string"),m.name!=null&&!E(m.name)&&l(`${b}.name`,"material asset name must be a non-empty string when present"),m.guid!=null&&!E(m.guid)&&l(`${b}.guid`,"material asset guid must be a non-empty string when present"),Object.prototype.hasOwnProperty.call(m,"materialKind")&&l(`${b}.materialKind`,"materialKind is not supported; use shaderId"),Object.prototype.hasOwnProperty.call(m,"profile")&&l(`${b}.profile`,"profile is not supported; use properties");let j=Zt(m.shaderId),W=nd(m.shaderId);!j&&!W&&l(`${b}.shaderId`,"shaderId must be a built-in id or a namespaced lowercase project id"),m.definitionVersion!=null&&!rd(m.definitionVersion)?l(`${b}.definitionVersion`,"definitionVersion must be a positive integer when present"):W&&m.definitionVersion==null&&l(`${b}.definitionVersion`,"definitionVersion is required for project shader material assets"),j?pi(m.properties,`${b}.properties`,l):id(m.properties,`${b}.properties`,l);for(let J of Object.keys(m))["id","guid","name","shaderId","definitionVersion","properties","system","origin"].includes(J)||l(`${b}.${J}`,`material asset field is not allowed: ${J}`);od(m.system,`${b}.system`,l),sd(m.origin,`${b}.origin`,l),ad(m,b,l)}),p.nodes.forEach((m,L)=>{if(!x(m))return;let b=`$.scene.nodes[${L}]`,j=Object.prototype.hasOwnProperty.call(m,"parentId");j&&!E(m.parentId)&&l(`${b}.parentId`,"parentId must be a non-empty string when present");let W=j?m.parentId:p.rootId;E(W)&&dd(W,p.rootId,T,`${b}.parentId`,l),E(m.id)&&cd(m.id,p.rootId,$,`${b}.parentId`,l),md(m.source,`${b}.source`,l),hi(m.transform,`${b}.transform`,l),$d(m.rendering,`${b}.rendering`,l),m.shadow!=null&&li(()=>pt(m.shadow,`${b}.shadow`),`${b}.shadow`,l),Object.prototype.hasOwnProperty.call(m,"shadowMode")&&l(`${b}.shadowMode`,"deprecated field; use shadow.mode");let J=null;m.kind==="instance"&&(x(m.instance)?h.has(m.instance.assetId)?S.get(m.instance.assetId)!=="glb"?l(`${b}.instance.assetId`,"instance.assetId must reference a glb asset"):J=E(m.instance.assetId)?m.instance.assetId:null:l(`${b}.instance.assetId`,`assetId must reference scene.assets: ${m.instance.assetId}`):l(`${b}.instance`,"instance node must contain instance object")),m.kind==="primitive"&&(x(m.primitive)?za.has(m.primitive.shape)||l(`${b}.primitive.shape`,"primitive.shape must be cube, sphere, plane, or capsule"):l(`${b}.primitive`,"primitive node must contain primitive object")),m.kind==="image"&&(x(m.image)?(h.has(m.image.assetId)?S.get(m.image.assetId)!=="texture"&&l(`${b}.image.assetId`,"image.assetId must reference a texture asset"):l(`${b}.image.assetId`,`assetId must reference scene.assets: ${m.image.assetId}`),x(m.image.size)?(fi(m.image.size.width)||l(`${b}.image.size.width`,"image.size.width must be positive"),fi(m.image.size.height)||l(`${b}.image.size.height`,"image.size.height must be positive")):l(`${b}.image.size`,"image.size must be an object")):l(`${b}.image`,"image node must contain image object")),m.kind==="transform"&&m.transformType!=null&&!Ha.has(m.transformType)&&l(`${b}.transformType`,"transformType must be plain, light, camera, or groundDecal"),m.kind==="transform"&&m.transformType==="groundDecal"?Ad(m.groundDecal,`${b}.groundDecal`,l):Object.prototype.hasOwnProperty.call(m,"groundDecal")&&l(`${b}.groundDecal`,"groundDecal is only allowed on transform nodes with transformType groundDecal"),m.kind==="transform"&&(xd(m.camera,`${b}.camera`,l),Id(m.light,`${b}.light`,l,g)),Object.prototype.hasOwnProperty.call(m,"marker")&&(m.kind!=="transform"?l(`${b}.marker`,"marker is only allowed on transform nodes"):(gd(m.marker,`${b}.marker`,l),pd(m.marker,m.id,T,q,`${b}.marker`,l))),(m.kind==="instance"||m.kind==="transform"||m.kind==="primitive"||m.kind==="image")&&Qa(m.overrides,`${b}.overrides`,D,J?P.get(J):void 0,f===3?"materialSlots":"metadata.materialSlots",l),u.has(m.id)&&mi(m,b,l)}),p.materials.forEach((m,L)=>{let b=`$.scene.materials[${L}]`;if(!x(m)){l(b,"material must be an object");return}if(E(m.id)||l(`${b}.id`,"material.id must be a non-empty string"),m.scope!=null&&!Va.has(m.scope)&&l(`${b}.scope`,"material scope must be sharedAsset or nodeMaterial"),m.scope==="sharedAsset"&&(!E(m.assetId)||!h.has(m.assetId))&&!n&&l(`${b}.assetId`,`shared material assetId must reference scene.assets: ${m.assetId}`),m.scope==="nodeMaterial"){if((!E(m.nodeId)||!T.has(m.nodeId))&&!r)l(`${b}.nodeId`,`node material nodeId must reference scene.nodes: ${m.nodeId}`);else if(E(m.nodeId)&&T.has(m.nodeId)){let j=_.get(m.nodeId);j!=="instance"&&j!=="transform"&&j!=="primitive"&&l(`${b}.nodeId`,`node material nodeId must reference an instance, transform, or primitive node: ${m.nodeId}`)}}E(m.materialName)||l(`${b}.materialName`,"materialName must be a non-empty string"),x(m.properties)?xi(m.properties,`${b}.properties`,l):l(`${b}.properties`,"properties must be an object")}),c}function Ya(e,t={}){let n=Za(e,t);return{ok:n.length===0,errors:n}}function li(e,t,n){try{e()}catch(r){let i=typeof r?.path=="string"?r.path:t,o=typeof r?.code=="string"?r.code:"schema.invalidValue";n(i,o)}}function Qa(e,t,n,r,i,o){if(e!=null){if(!x(e)){o(t,"overrides must be an object when present");return}gi(e.materialBinding,`${t}.materialBinding`,n,o),ed(e.materialSlotBindings,`${t}.materialSlotBindings`,"slotId",n,r,i,o),Object.prototype.hasOwnProperty.call(e,"childMaterialBindings")&&o(`${t}.childMaterialBindings`,"deprecated field; use materialSlotBindings keyed by slotId"),Object.prototype.hasOwnProperty.call(e,"childMaterials")&&o(`${t}.childMaterials`,"deprecated field; use materialSlotBindings keyed by slotId")}}function ed(e,t,n,r,i,o,s){if(e!=null){if(!x(e)){s(t,"material binding map must be an object when present");return}for(let[a,c]of Object.entries(e)){let d=`${t}.${a}`;E(a)||s(d,`${n} must be a non-empty string`),i?i.has(a)||s(d,`${n} must reference asset ${o}`):s(d,`${n} requires an instance asset with ${o}`),c==null?s(d,"material binding must be an object"):gi(c,d,r,s)}}}function gi(e,t,n,r){if(e!=null){if(!x(e)){r(t,"material binding must be an object when present");return}e.materialAssetId!=null&&(E(e.materialAssetId)?n.has(e.materialAssetId)||r(`${t}.materialAssetId`,`materialAssetId must reference scene.materialAssets: ${e.materialAssetId}`):r(`${t}.materialAssetId`,"materialAssetId must be non-empty when present")),e.override!=null&&pi(e.override,`${t}.override`,r)}}function pi(e,t,n){if(!x(e)){n(t,"material asset profile must be an object");return}if(e.lightingModel!=null&&e.lightingModel!=="lit"&&e.lightingModel!=="unlit"&&n(`${t}.lightingModel`,"lightingModel must be lit or unlit"),e.baseColor!=null)if(!x(e.baseColor))n(`${t}.baseColor`,"baseColor must be an object");else{rn(e.baseColor.color,`${t}.baseColor.color`,n),Le(e.baseColor.texture,`${t}.baseColor.texture`,n);for(let r of["brightness","saturation","contrast","hue"])e.baseColor[r]!=null&&!oe(e.baseColor[r])&&n(`${t}.baseColor.${r}`,`${r} must be a finite number`)}for(let r of["metallic","roughness"])e[r]!=null&&!oe(e[r])&&n(`${t}.${r}`,`${r} must be a finite number`);e.normal!=null&&(x(e.normal)?(Le(e.normal.texture,`${t}.normal.texture`,n),e.normal.strength!=null&&!oe(e.normal.strength)&&n(`${t}.normal.strength`,"normal strength must be a finite number")):n(`${t}.normal`,"normal must be an object")),e.metallicRoughness!=null&&(x(e.metallicRoughness)?Le(e.metallicRoughness.texture,`${t}.metallicRoughness.texture`,n):n(`${t}.metallicRoughness`,"metallicRoughness must be an object")),e.occlusion!=null&&(x(e.occlusion)?(Le(e.occlusion.texture,`${t}.occlusion.texture`,n),e.occlusion.strength!=null&&!oe(e.occlusion.strength)&&n(`${t}.occlusion.strength`,"occlusion strength must be a finite number")):n(`${t}.occlusion`,"occlusion must be an object")),e.emission!=null&&(x(e.emission)?(rn(e.emission.color,`${t}.emission.color`,n),e.emission.intensity!=null&&!oe(e.emission.intensity)&&n(`${t}.emission.intensity`,"emission intensity must be a finite number"),Le(e.emission.texture,`${t}.emission.texture`,n),Le(e.emission.maskTexture,`${t}.emission.maskTexture`,n)):n(`${t}.emission`,"emission must be an object")),e.alpha!=null&&(x(e.alpha)?(e.alpha.mode!=null&&e.alpha.mode!=="opaque"&&e.alpha.mode!=="mask"&&e.alpha.mode!=="blend"&&n(`${t}.alpha.mode`,"alpha mode must be opaque, mask, or blend"),e.alpha.opacity!=null&&!oe(e.alpha.opacity)&&n(`${t}.alpha.opacity`,"alpha opacity must be a finite number"),e.alpha.cutoff!=null&&!oe(e.alpha.cutoff)&&n(`${t}.alpha.cutoff`,"alpha cutoff must be a finite number"),Le(e.alpha.texture,`${t}.alpha.texture`,n)):n(`${t}.alpha`,"alpha must be an object"))}var td=/^[a-z0-9]+(?:[._-][a-z0-9]+)+$/;function Hn(e){return typeof e=="string"&&!e.startsWith("fps.builtin.")&&td.test(e)}function nd(e){return Hn(e)?e:null}function rd(e){return Number.isSafeInteger(e)&&e>0}function id(e,t,n){if(!x(e)){n(t,"project shader material properties must be an object");return}Vn(e,t,n)}function Vn(e,t,n){if(!(e===null||typeof e=="string"||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||n(t,"project shader material numbers must be finite");return}if(Array.isArray(e)){e.forEach((r,i)=>Vn(r,`${t}[${i}]`,n));return}if(x(e)){for(let[r,i]of Object.entries(e))Vn(i,`${t}.${r}`,n);return}n(t,"project shader material properties must be JSON-safe")}}function Le(e,t,n){if(e!=null){if(!x(e)){n(t,"texture ref must be an object");return}e.url!=null&&!E(e.url)&&n(`${t}.url`,"texture url must be non-empty when present"),e.textureAssetId!=null&&!E(e.textureAssetId)&&n(`${t}.textureAssetId`,"textureAssetId must be non-empty when present")}}function od(e,t,n){if(e!=null){if(!x(e)){n(t,"material asset system must be an object");return}e.readonly!=null&&typeof e.readonly!="boolean"&&n(`${t}.readonly`,"readonly must be boolean"),e.preset!=null&&!Ka.has(e.preset)&&n(`${t}.preset`,"preset must be default-pbr or default-standard")}}function sd(e,t,n){if(e!=null){if(!x(e)){n(t,"material asset origin must be an object");return}e.type!=="imported"&&e.type!=="created"&&e.type!=="duplicated"&&e.type!=="preset"&&n(`${t}.type`,"origin type must be imported, created, duplicated, or preset"),e.sourceAssetGuid!=null&&!E(e.sourceAssetGuid)&&n(`${t}.sourceAssetGuid`,"sourceAssetGuid must be non-empty when present"),e.sourceAssetId!=null&&!E(e.sourceAssetId)&&n(`${t}.sourceAssetId`,"sourceAssetId must be non-empty when present"),e.sourceSlotId!=null&&!E(e.sourceSlotId)&&n(`${t}.sourceSlotId`,"sourceSlotId must be non-empty when present"),e.sourceMaterialIndex!=null&&!Number.isInteger(e.sourceMaterialIndex)&&n(`${t}.sourceMaterialIndex`,"sourceMaterialIndex must be an integer when present"),e.sourceMaterialName!=null&&!E(e.sourceMaterialName)&&n(`${t}.sourceMaterialName`,"sourceMaterialName must be non-empty when present"),e.sourceMaterialAssetId!=null&&!E(e.sourceMaterialAssetId)&&n(`${t}.sourceMaterialAssetId`,"sourceMaterialAssetId must be non-empty when present")}}function ad(e,t,n){let r=x(e.system)?e.system.preset:void 0;r==="default-pbr"&&e.shaderId!=="fps.builtin.pbr"&&n(`${t}.shaderId`,"default-pbr material assets must use shaderId fps.builtin.pbr"),r==="default-standard"&&e.shaderId!=="fps.builtin.standard"&&n(`${t}.shaderId`,"default-standard material assets must use shaderId fps.builtin.standard")}function dd(e,t,n,r,i){if(e===t){St.has("root")||i(r,`parentId must point to scene node: ${e}`);return}if(St.has("sceneNode")&&n.has(e))return;let o=St.has("root")&&St.has("sceneNode")?"root or scene node":St.has("sceneNode")?"scene node":"root";i(r,`parentId must point to ${o}: ${e}`)}function cd(e,t,n,r,i){if(!E(t))return;let o=new Set([e]),s=E(n.get(e)?.parentId)?n.get(e)?.parentId:t;for(;E(s)&&s!==t;){if(o.has(s)){i(r,`parentId creates a node cycle involving ${e}`);return}o.add(s);let a=n.get(s);if(!a)return;s=E(a.parentId)?a.parentId:t}}function ld(e,t,n){for(let r of Object.keys(e))Ja.has(r)||n(`${t}.${r}`,`runtime schema v3 material slot field is not allowed: ${r}`);if(e.label!=null&&!E(e.label)&&n(`${t}.label`,"label must be a non-empty string when present"),!Array.isArray(e.sourceSurfaces)||e.sourceSurfaces.length===0){n(`${t}.sourceSurfaces`,"sourceSurfaces must be a non-empty array");return}for(let r=0;r<e.sourceSurfaces.length;r+=1){let i=`${t}.sourceSurfaces[${r}]`,o=e.sourceSurfaces[r];if(!x(o)){n(i,"source surface must be an object");continue}for(let s of Object.keys(o))Xa.has(s)||n(`${i}.${s}`,`runtime schema v3 material slot source surface field is not allowed: ${s}`);E(o.ownerNodePath)||n(`${i}.ownerNodePath`,"ownerNodePath must be a non-empty string");for(let s of["meshIndex","primitiveIndex"])(!Number.isInteger(o[s])||o[s]<0)&&n(`${i}.${s}`,`${s} must be a non-negative integer`);for(let s of["nodeIndex","sourceMaterialIndex"])o[s]!=null&&(!Number.isInteger(o[s])||o[s]<0)&&n(`${i}.${s}`,`${s} must be a non-negative integer when present`);o.nodeIndexPath!=null&&(!Array.isArray(o.nodeIndexPath)||o.nodeIndexPath.some(s=>!Number.isInteger(s)||s<0))&&n(`${i}.nodeIndexPath`,"nodeIndexPath must contain non-negative integers"),E(o.sourceMeshName)||n(`${i}.sourceMeshName`,"sourceMeshName is required")}}function ud(e,t,n){if(e!=null){if(!x(e)){n(t,"defaults must be an object");return}if(hi(e.transform,`${t}.transform`,n),ui(e.outline,`${t}.outline`,n),e.childOutlines!=null)if(!x(e.childOutlines))n(`${t}.childOutlines`,"childOutlines must be an object");else for(let[r,i]of Object.entries(e.childOutlines))ui(i,`${t}.childOutlines.${r}`,n)}}function fd(e,t,n){if(e!=null){if(!x(e)){n(t,"generatedFrom must be an object when present");return}bi(e,t,n),E(e.compilerId)||n(`${t}.compilerId`,"compilerId must be a non-empty string"),E(e.compilerVersion)||n(`${t}.compilerVersion`,"compilerVersion must be a non-empty string"),E(e.compiledAt)||n(`${t}.compiledAt`,"compiledAt must be a non-empty string")}}function md(e,t,n){if(e!=null){if(!x(e)){n(t,"source must be an object when present");return}bi(e,t,n),e.objectGuid!=null&&!E(e.objectGuid)&&n(`${t}.objectGuid`,"objectGuid must be a non-empty string when present"),e.objectId!=null&&!E(e.objectId)&&n(`${t}.objectId`,"objectId must be a non-empty string when present"),e.component!=null&&!E(e.component)&&n(`${t}.component`,"component must be a non-empty string when present"),e.propertyPath!=null&&!E(e.propertyPath)&&n(`${t}.propertyPath`,"propertyPath must be a non-empty string when present")}}function bi(e,t,n){E(e.sourceId)||n(`${t}.sourceId`,"sourceId must be a non-empty string"),E(e.sourceType)||n(`${t}.sourceType`,"sourceType must be a non-empty string"),e.revision!=null&&(typeof e.revision!="number"||!Number.isFinite(e.revision))&&n(`${t}.revision`,"revision must be a finite number when present")}function yi(e,t){let n=Ya(e,t);if(n.ok)return;let r=new Error(`scene_json_schema_failed:
|
|
3
|
-
${JSON.stringify(n.errors,null,2)}`);throw Object.assign(r,{code:"scene_json_schema_failed",diagnostics:n.errors}),r}function x(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function E(e){return typeof e=="string"&&e.trim().length>0}function hi(e,t,n){if(e!=null){if(!x(e)){n(t,"transform must be an object");return}Se(e.position,`${t}.position`,n),Se(e.rotation,`${t}.rotation`,n),Se(e.rotationDeg,`${t}.rotationDeg`,n),typeof e.scale=="number"?Number.isFinite(e.scale)||n(`${t}.scale`,"scale number must be finite"):Se(e.scale,`${t}.scale`,n)}}function gd(e,t,n){if(!x(e)){n(t,"marker must be an object");return}Re(e,["schemaVersion","label","type","kind","tags","note","color","target","semanticFrame","geometry","metadata"],t,n),e.schemaVersion!==1&&n(`${t}.schemaVersion`,"marker.schemaVersion must be 1"),E(e.label)||n(`${t}.label`,"marker.label must be a non-empty string"),E(e.type)||n(`${t}.type`,"marker.type must be a non-empty string"),e.kind!=null&&!E(e.kind)&&n(`${t}.kind`,"marker.kind must be a non-empty string when present"),e.tags!=null&&(Array.isArray(e.tags)?e.tags.forEach((r,i)=>{typeof r!="string"&&n(`${t}.tags[${i}]`,"marker tag must be a string")}):n(`${t}.tags`,"marker.tags must be an array when present")),e.note!=null&&typeof e.note!="string"&&n(`${t}.note`,"marker.note must be a string when present"),e.color!=null&&hd(e.color,`${t}.color`,n),e.target!=null&&Kn(e.target,`${t}.target`,n),e.semanticFrame!=null&&bd(e.semanticFrame,`${t}.semanticFrame`,n),yd(e.geometry,`${t}.geometry`,n),e.metadata!=null&&!x(e.metadata)&&n(`${t}.metadata`,"marker.metadata must be an object when present")}function pd(e,t,n,r,i,o){if(!x(e))return;let s=[];e.target!=null&&s.push({value:e.target,path:`${i}.target`}),x(e.geometry)&&e.geometry.target!=null&&s.push({value:e.geometry.target,path:`${i}.geometry.target`});for(let a of s)x(a.value)&&(a.value.kind!=="scene-object"&&a.value.kind!=="marker"&&o(`${a.path}.kind`,"runtime marker target kind must be scene-object or marker"),E(a.value.id)&&(a.value.id===t?o(`${a.path}.id`,"runtime marker target must not reference its marker node"):n.has(a.value.id)?a.value.kind==="marker"&&!r.has(a.value.id)?o(`${a.path}.id`,`runtime marker target must reference a marker node: ${a.value.id}`):a.value.kind==="scene-object"&&r.has(a.value.id)&&o(`${a.path}.id`,`runtime scene-object target must not reference a marker node: ${a.value.id}`):o(`${a.path}.id`,`runtime marker target must reference scene.nodes: ${a.value.id}`)))}function Kn(e,t,n){if(!x(e)){n(t,"marker target must be an object");return}Re(e,["kind","id","label","path","metadata"],t,n),E(e.kind)||n(`${t}.kind`,"marker target kind must be a non-empty string"),E(e.id)||n(`${t}.id`,"marker target id must be a non-empty string");for(let r of["label","path"])e[r]!=null&&typeof e[r]!="string"&&n(`${t}.${r}`,`marker target ${r} must be a string when present`);e.metadata!=null&&!x(e.metadata)&&n(`${t}.metadata`,"marker target metadata must be an object when present")}function bd(e,t,n){if(!x(e)){n(t,"marker semanticFrame must be an object");return}Re(e,["origin","forward","right","up","label","description"],t,n),x(e.origin)?Se(e.origin,`${t}.origin`,n):n(`${t}.origin`,"marker semanticFrame.origin must be a vector object");for(let r of["forward","right","up"])e[r]!=null&&Se(e[r],`${t}.${r}`,n);for(let r of["label","description"])e[r]!=null&&typeof e[r]!="string"&&n(`${t}.${r}`,`marker semanticFrame ${r} must be a string when present`)}function yd(e,t,n){if(!x(e)){n(t,"marker.geometry must be an object");return}if(e.kind==="box"){Re(e,["kind"],t,n);return}if(e.kind==="point"){Re(e,["kind","coordinateSpace","position","offset","target"],t,n),e.coordinateSpace!=null&&e.coordinateSpace!=="world"&&e.coordinateSpace!=="local"&&n(`${t}.coordinateSpace`,"point marker coordinateSpace must be world or local"),e.position!=null&&Se(e.position,`${t}.position`,n),e.offset!=null&&Se(e.offset,`${t}.offset`,n),e.target!=null&&Kn(e.target,`${t}.target`,n);return}if(e.kind==="object-bounds"){Re(e,["kind","target"],t,n),Kn(e.target,`${t}.target`,n);return}if(e.kind==="polyhedron"){Re(e,["kind","coordinateSpace","vertices","faces"],t,n),e.coordinateSpace!=null&&e.coordinateSpace!=="world"&&n(`${t}.coordinateSpace`,"polyhedron marker coordinateSpace must be world"),Array.isArray(e.vertices)?e.vertices.forEach((r,i)=>{let o=`${t}.vertices[${i}]`;x(r)?Se(r,o,n):n(o,"polyhedron marker vertex must be a vector object")}):n(`${t}.vertices`,"polyhedron marker vertices must be an array"),e.faces!=null&&(Array.isArray(e.faces)?e.faces.forEach((r,i)=>{Array.isArray(r)?r.forEach((o,s)=>{(!Number.isInteger(o)||o<0)&&n(`${t}.faces[${i}][${s}]`,"polyhedron marker index must be a non-negative integer")}):n(`${t}.faces[${i}]`,"polyhedron marker face must be an array")}):n(`${t}.faces`,"polyhedron marker faces must be an array when present"));return}n(`${t}.kind`,"marker.geometry.kind must be box, point, object-bounds, or polyhedron")}function hd(e,t,n){if(!x(e)){n(t,"marker color must be an object");return}Re(e,["r","g","b"],t,n);for(let r of["r","g","b"])Si(e[r])||n(`${t}.${r}`,"marker color component must be between 0 and 1")}function Re(e,t,n,r){let i=new Set(t);for(let o of Object.keys(e))i.has(o)||r(`${n}.${o}`,`field is not allowed: ${o}`)}function Se(e,t,n){if(e!=null){if(!x(e)){n(t,"value must be a vector object");return}for(let r of["x","y","z"])(typeof e[r]!="number"||!Number.isFinite(e[r]))&&n(`${t}.${r}`,"vector component must be a finite number")}}function Sd(e,t,n){if(e!=null){if(!x(e)){n(t,"value must be a vector object");return}for(let r of["x","y"])(typeof e[r]!="number"||!Number.isFinite(e[r]))&&n(`${t}.${r}`,"vector component must be a finite number")}}function oe(e){return typeof e=="number"&&Number.isFinite(e)}function ze(e){return oe(e)&&e>0}function Si(e){return oe(e)&&e>=0&&e<=1}function rn(e,t,n){if(e!=null){if(!x(e)){n(t,"color must be an object");return}for(let r of["r","g","b"])(typeof e[r]!="number"||!Number.isFinite(e[r]))&&n(`${t}.${r}`,"color component must be a finite number")}}function xd(e,t,n){if(e!=null){if(!x(e)){n(t,"camera must be an object");return}e.projection!=null&&e.projection!=="orthographic"&&e.projection!=="perspective"&&n(`${t}.projection`,"camera projection must be orthographic or perspective");for(let r of["alpha","beta"])e[r]!=null&&!oe(e[r])&&n(`${t}.${r}`,"camera property must be a finite number when present");for(let r of["radius","orthoSize"])e[r]!=null&&!ze(e[r])&&n(`${t}.${r}`,"camera property must be a positive finite number when present");e.fov!=null&&!ze(e.fov)&&n(`${t}.fov`,"camera fov must be a positive finite number"),Se(e.targetOffset,`${t}.targetOffset`,n),Sd(e.targetScreenOffset,`${t}.targetScreenOffset`,n);for(let r of["minZ","maxZ","lowerRadiusLimit","upperRadiusLimit"])e[r]!=null&&!ze(e[r])&&n(`${t}.${r}`,"camera property must be a positive finite number");for(let r of["lowerBetaLimit","upperBetaLimit"])e[r]!=null&&!oe(e[r])&&n(`${t}.${r}`,"camera property must be a finite number");e.inertia!=null&&!Si(e.inertia)&&n(`${t}.inertia`,"camera inertia must be between 0 and 1"),ze(e.minZ)&&ze(e.maxZ)&&e.maxZ<=e.minZ&&n(`${t}.maxZ`,"camera maxZ must be greater than minZ"),oe(e.lowerBetaLimit)&&oe(e.upperBetaLimit)&&e.upperBetaLimit<e.lowerBetaLimit&&n(`${t}.upperBetaLimit`,"camera upperBetaLimit must be greater than or equal to lowerBetaLimit"),ze(e.lowerRadiusLimit)&&ze(e.upperRadiusLimit)&&e.upperRadiusLimit<e.lowerRadiusLimit&&n(`${t}.upperRadiusLimit`,"camera upperRadiusLimit must be greater than or equal to lowerRadiusLimit")}}function Pd(e){let t=e.meta?.generatedFrom;return x(t)&&t.compilerId===ja&&t.compilerVersion===Fa}function Id(e,t,n,r=!1){if(e==null)return;let i=r&&x(e)&&!Object.prototype.hasOwnProperty.call(e,"schemaVersion")?Ed(e,t):e;try{qe(i,t)}catch(o){let s=o;n(typeof s.path=="string"?s.path:t,typeof s.reason=="string"?s.reason:typeof s.message=="string"?s.message:"light does not satisfy the Engine Runtime Light contract")}}function Ed(e,t){let n={...e,schemaVersion:1};if(e.type!=="directional"||!x(e.direction))return n;let{x:r,y:i,z:o}=e.direction;if(![r,i,o].every(a=>typeof a=="number"&&Number.isFinite(a)))return n;let s=Math.hypot(r,i,o);return s<=0||Math.abs(s-1)>_a?n:{...n,direction:ft(e.direction,`${t}.direction`)}}function ui(e,t,n){if(e!=null){if(!x(e)){n(t,"outline must be an object");return}e.renderOutline!=null&&typeof e.renderOutline!="boolean"&&n(`${t}.renderOutline`,"renderOutline must be boolean"),e.outlineWidth!=null&&(typeof e.outlineWidth!="number"||!Number.isFinite(e.outlineWidth))&&n(`${t}.outlineWidth`,"outlineWidth must be a finite number"),rn(e.outlineColor,`${t}.outlineColor`,n)}}function Ad(e,t,n){if(e==null){n(t,"groundDecal is required when transformType is groundDecal");return}if(!x(e)){n(t,"groundDecal must be an object");return}wd(e,t,n)}function wd(e,t,n){if(E(e.uiKind)||n(`${t}.uiKind`,"groundDecal UI kind must be non-empty"),!x(e.size))n(`${t}.size`,"groundDecal.size must be an object");else for(let r of["width","depth"])(typeof e.size[r]!="number"||!Number.isFinite(e.size[r])||e.size[r]<=0)&&n(`${t}.size.${r}`,"groundDecal size must be a positive finite number");if(e.aspectSourceLayerId!=null&&!E(e.aspectSourceLayerId)&&n(`${t}.aspectSourceLayerId`,"aspectSourceLayerId must be non-empty when present"),e.lockAspectToBorder!=null&&typeof e.lockAspectToBorder!="boolean"&&n(`${t}.lockAspectToBorder`,"lockAspectToBorder must be boolean when present"),e.editorPreviewActive!=null&&n(`${t}.editorPreviewActive`,"editorPreviewActive is editor-only and must not appear in runtime scene data"),Td(e.mask,`${t}.mask`,n),Dd(e.rendering,`${t}.rendering`,n),!Array.isArray(e.layers)){n(`${t}.layers`,"groundDecal UI layers must be an array");return}e.layers.forEach((r,i)=>kd(r,`${t}.layers[${i}]`,n)),Md(e.layers,`${t}.layers`,n)}function Td(e,t,n){if(e!=null){if(!x(e)){n(t,"groundDecal UI mask must be an object");return}e.enabled!=null&&typeof e.enabled!="boolean"&&n(`${t}.enabled`,"mask.enabled must be boolean"),e.source!=null&&e.source!=="roundedRect"&&e.source!=="borderAlpha"&&e.source!=="texture"&&n(`${t}.source`,"mask.source must be roundedRect, borderAlpha, or texture"),e.textureId!=null&&!E(e.textureId)&&n(`${t}.textureId`,"mask.textureId must be non-empty when present");for(let r of["cornerRadius","padding"])e[r]!=null&&(typeof e[r]!="number"||!Number.isFinite(e[r])||e[r]<0)&&n(`${t}.${r}`,`${r} must be a non-negative finite number`)}}function Dd(e,t,n){if(e!=null){if(!x(e)){n(t,"groundDecal UI rendering must be an object");return}for(let r of["textureWidth","textureHeight"])e[r]!=null&&(!Number.isInteger(e[r])||e[r]<=0)&&n(`${t}.${r}`,`${r} must be a positive integer`);for(let r of["alphaIndex","diffuseTextureLevel","emissiveTextureLevel"])e[r]!=null&&(typeof e[r]!="number"||!Number.isFinite(e[r]))&&n(`${t}.${r}`,`${r} must be a finite number`)}}function kd(e,t,n){if(!x(e)){n(t,"groundDecal UI layer must be an object");return}E(e.id)||n(`${t}.id`,"layer.id must be non-empty"),E(e.role)||n(`${t}.role`,"layer.role must be non-empty"),e.editorPreviewPercent!=null&&n(`${t}.editorPreviewPercent`,"editorPreviewPercent is editor-only and must not appear in runtime scene data"),e.enabled!=null&&typeof e.enabled!="boolean"&&n(`${t}.enabled`,"layer.enabled must be boolean"),(typeof e.zOrder!="number"||!Number.isFinite(e.zOrder))&&n(`${t}.zOrder`,"layer.zOrder must be a finite number"),e.opacity!=null&&(typeof e.opacity!="number"||!Number.isFinite(e.opacity))&&n(`${t}.opacity`,"layer.opacity must be finite"),e.rotationDeg!=null&&(typeof e.rotationDeg!="number"||!Number.isFinite(e.rotationDeg)||e.rotationDeg<=-180||e.rotationDeg>180)&&n(`${t}.rotationDeg`,"layer.rotationDeg must be in the range (-180, 180]"),Cd(e.rect,`${t}.rect`,n),e.kind==="texture"?(e.textureId!=null&&!E(e.textureId)&&n(`${t}.textureId`,"texture layer textureId must be non-empty when present"),e.imageFit!=null&&e.imageFit!=="contain"&&e.imageFit!=="stretch"&&n(`${t}.imageFit`,"texture layer imageFit must be contain or stretch"),Ze(e.tint,`${t}.tint`,n)):e.kind==="textureProgress"?(e.textureId!=null&&!E(e.textureId)&&n(`${t}.textureId`,"texture progress layer textureId must be non-empty when present"),e.imageFit!=null&&e.imageFit!=="contain"&&e.imageFit!=="stretch"&&n(`${t}.imageFit`,"texture progress layer imageFit must be contain or stretch"),(typeof e.value!="number"||!Number.isFinite(e.value)||e.value<0||e.value>1)&&n(`${t}.value`,"texture progress value must be between 0 and 1"),e.direction!=null&&!["leftToRight","rightToLeft","bottomToTop","topToBottom"].includes(String(e.direction))&&n(`${t}.direction`,"texture progress direction is invalid"),Ze(e.tint,`${t}.tint`,n)):e.kind==="color"?Ze(e.color,`${t}.color`,n):e.kind==="progress"?((typeof e.value!="number"||!Number.isFinite(e.value)||e.value<0||e.value>1)&&n(`${t}.value`,"progress value must be between 0 and 1"),e.direction!=null&&!["leftToRight","rightToLeft","bottomToTop","topToBottom"].includes(String(e.direction))&&n(`${t}.direction`,"progress direction is invalid"),Ze(e.color,`${t}.color`,n)):e.kind==="text"?Rd(e.text,`${t}.text`,n):n(`${t}.kind`,"layer.kind must be texture, textureProgress, color, progress, or text")}function Md(e,t,n){let r=new Map;e.forEach((i,o)=>{if(!x(i)||!E(i.id))return;let s=r.get(i.id);if(s!=null){n(`${t}[${o}].id`,`layer.id must be unique; duplicate of layers[${s}]`);return}r.set(i.id,o)})}function Cd(e,t,n){if(!x(e)){n(t,"layer.rect must be an object");return}for(let r of["x","z","width","depth"])(typeof e[r]!="number"||!Number.isFinite(e[r]))&&n(`${t}.${r}`,`rect.${r} must be a finite number`);for(let r of["width","depth"])typeof e[r]=="number"&&e[r]<=0&&n(`${t}.${r}`,`rect.${r} must be positive`)}function Rd(e,t,n){if(!x(e)){n(t,"text layer text must be an object");return}typeof e.value!="string"&&n(`${t}.value`,"text.value must be a string"),e.fontFamily!=null&&typeof e.fontFamily!="string"&&n(`${t}.fontFamily`,"fontFamily must be a string"),e.fontSize!=null&&(typeof e.fontSize!="number"||!Number.isFinite(e.fontSize)||e.fontSize<=0)&&n(`${t}.fontSize`,"fontSize must be a positive finite number"),e.fontWeight!=null&&typeof e.fontWeight!="string"&&n(`${t}.fontWeight`,"fontWeight must be a string"),Ze(e.color,`${t}.color`,n),Ze(e.strokeColor,`${t}.strokeColor`,n),e.strokeWidth!=null&&(typeof e.strokeWidth!="number"||!Number.isFinite(e.strokeWidth)||e.strokeWidth<0)&&n(`${t}.strokeWidth`,"strokeWidth must be a non-negative finite number")}function Ze(e,t,n){if(e!=null){if(!x(e)){n(t,"color must be an object");return}for(let r of["r","g","b"])(typeof e[r]!="number"||!Number.isFinite(e[r]))&&n(`${t}.${r}`,`color.${r} must be finite`);e.a!=null&&(typeof e.a!="number"||!Number.isFinite(e.a))&&n(`${t}.a`,"color.a must be finite")}}function $d(e,t,n){if(e!=null){if(!x(e)){n(t,"rendering must be an object");return}e.renderingGroupId!=null&&e.renderingGroupId!==0&&e.renderingGroupId!==1&&e.renderingGroupId!==2&&e.renderingGroupId!==3&&n(`${t}.renderingGroupId`,"renderingGroupId must be 0, 1, 2, or 3"),e.alphaIndex!=null&&(typeof e.alphaIndex!="number"||!Number.isFinite(e.alphaIndex))&&n(`${t}.alphaIndex`,"alphaIndex must be a finite number")}}function fi(e){return typeof e=="number"&&Number.isFinite(e)&&e>0}function xi(e,t,n){for(let[r,i]of Object.entries(e)){let o=`${t}.${r}`;["albedoColor","diffuseColor","emissiveColor","outlineColor"].includes(r)&&rn(i,o,n),["metallic","roughness","contrast","brightness","saturation","hue","colorDensity","alpha","alphaCutOff","transparencyMode"].includes(r)&&(typeof i!="number"||!Number.isFinite(i))&&n(o,`${r} must be a finite number`),r==="backFaceCulling"&&typeof i!="boolean"&&n(o,"backFaceCulling must be boolean"),["albedoTexture","normalTexture","metallicTexture"].includes(r)&&(x(i)?i.url!=null&&!E(i.url)&&n(`${o}.url`,"texture url must be non-empty when present"):n(o,`${r} must be an object`)),["pbr","standard"].includes(r)&&(x(i)?xi(i,o,n):n(o,`${r} must be an object`))}}function mi(e,t,n){let r=JSON.stringify(e),i=Wa.filter(o=>r.includes(o));i.length>0&&n(t,`contains runtime-only asset fields: ${i.join(", ")}`)}function Nd(e,t,n){let r=Pi(e)??512,i=Pi(t)??512;if(!Number.isFinite(n)||n<=0)return{width:r,height:i};let o=r,s=Math.max(1,Math.round(o/n));return s>i&&(s=i,o=Math.max(1,Math.round(s*n))),{width:o,height:s}}function Ii(e){let t=e.rendering?.textureWidth??512,n=e.rendering?.textureHeight??512,r=e.size.width>0&&e.size.depth>0?e.size.width/e.size.depth:t/n;return Nd(t,n,r)}function Pi(e){return typeof e!="number"||!Number.isFinite(e)||e<=0?null:Math.max(64,Math.min(2048,Math.round(e)))}var fe=(e,t)=>({kind:"number",...e!=null?{min:e}:{},...t!=null?{max:t}:{}}),Ue={kind:"texture"},Ei={kind:"color"},Od={kind:"enum",values:["lit","unlit"]},vd={kind:"enum",values:["opaque","mask","blend"]},Ti={lightingModel:Od,baseColor:{kind:"object",properties:{color:Ei,texture:Ue,brightness:fe(0),saturation:fe(0),contrast:fe(0),hue:fe(-180,180)}},normal:{kind:"object",properties:{texture:Ue,strength:fe(0)}},emission:{kind:"object",properties:{color:Ei,intensity:fe(0),texture:Ue,maskTexture:Ue}},alpha:{kind:"object",properties:{mode:vd,opacity:fe(0,1),cutoff:fe(0,1),texture:Ue}}},Gd={kind:"object",properties:{...Ti,metallic:fe(0,1),roughness:fe(0,1),metallicRoughness:{kind:"object",properties:{texture:Ue}},occlusion:{kind:"object",properties:{texture:Ue,strength:fe(0)}}}},jd={kind:"object",properties:Ti},Fd={lightingModel:"lit",baseColor:{color:{r:1,g:1,b:1},brightness:1,saturation:1,contrast:1,hue:0},metallic:0,roughness:1,emission:{color:{r:0,g:0,b:0},intensity:0}},_d={lightingModel:"lit",baseColor:{color:{r:1,g:1,b:1},brightness:1,saturation:1,contrast:1,hue:0},emission:{color:{r:0,g:0,b:0},intensity:0}},Ai=[{id:"surface",title:"Surface",order:40},{id:"geometry",title:"Geometry",order:50},{id:"emission",title:"Emission",order:60},{id:"alpha",title:"Alpha",order:70}],Be={path:"properties.lightingModel",operator:"equals",value:"lit",inactiveReasonKey:"litMaterial"},Di=[Qe("properties.lightingModel","surface",1,"enum","assetLightingModel","lightingModel","lit",{options:[{value:"lit",labelKey:"assetLightingModelLit"},{value:"unlit",labelKey:"assetLightingModelUnlit"}],binding:"lightingModel",updateClass:"define"}),Qe("properties.baseColor.color","surface",2,"color","assetBaseColor","baseColor",{r:1,g:1,b:1},{binding:"baseColor.color"}),et("properties.baseColor.texture.textureAssetId","properties.baseColor.texture","surface",3,"assetBaseTexture","baseTexture","baseColor.texture"),me("properties.baseColor.brightness","surface",4,"assetBrightness","brightness",1,{softMin:0,softMax:4,step:.05,conditions:[Ye("properties.baseColor.texture.textureAssetId","baseTexture")]}),me("properties.baseColor.saturation","surface",5,"assetSaturation","saturation",1,{softMin:0,softMax:2,step:.05,conditions:[Ye("properties.baseColor.texture.textureAssetId","baseTexture")]}),me("properties.baseColor.contrast","surface",6,"assetContrast","contrast",1,{softMin:0,softMax:2,step:.05,conditions:[Ye("properties.baseColor.texture.textureAssetId","baseTexture")]}),me("properties.baseColor.hue","surface",7,"assetHue","hue",0,{step:1,conditions:[Ye("properties.baseColor.texture.textureAssetId","baseTexture")]}),et("properties.normal.texture.textureAssetId","properties.normal.texture","geometry",10,"assetNormalTexture","normalTexture","normal.texture",[Be]),me("properties.normal.strength","geometry",11,"assetNormalStrength","normalStrength",1,{softMin:0,softMax:4,step:.05,conditions:[Be,Ye("properties.normal.texture.textureAssetId","normalTexture")]}),Qe("properties.emission.color","emission",50,"color","assetEmissionColor","emissionColor",{r:0,g:0,b:0},{binding:"emission.color"}),me("properties.emission.intensity","emission",51,"assetEmissionIntensity","emissionIntensity",0,{softMin:0,softMax:8,step:.05}),et("properties.emission.texture.textureAssetId","properties.emission.texture","emission",52,"assetEmissionTexture","emissionTexture","emission.texture"),Qe("properties.alpha.mode","alpha",60,"enum","assetAlphaMode","alphaMode","opaque",{options:[{value:"opaque",labelKey:"assetAlphaModeOpaque"},{value:"mask",labelKey:"assetAlphaModeMask"},{value:"blend",labelKey:"assetAlphaModeBlend"}],binding:"alpha.mode",updateClass:"pipeline"}),me("properties.alpha.opacity","alpha",61,"assetAlphaOpacity","alphaOpacity",1,{step:.05,conditions:[{path:"properties.alpha.mode",operator:"equals",value:"blend",inactiveReasonKey:"alphaBlend"}]}),me("properties.alpha.cutoff","alpha",62,"assetAlphaCutoff","alphaCutoff",.5,{step:.01,conditions:[{path:"properties.alpha.mode",operator:"equals",value:"mask",inactiveReasonKey:"alphaMask"}]}),et("properties.alpha.texture.textureAssetId","properties.alpha.texture","alpha",63,"assetAlphaTexture","alphaTexture","alpha.texture",[{path:"properties.alpha.mode",operator:"not-equals",value:"opaque",inactiveReasonKey:"alphaTransparency"}])],Ld=[...Di,me("properties.metallic","geometry",20,"assetMetallic","metallic",0,{step:.05,conditions:[Be]}),me("properties.roughness","geometry",21,"assetRoughness","roughness",1,{step:.05,conditions:[Be]}),et("properties.metallicRoughness.texture.textureAssetId","properties.metallicRoughness.texture","geometry",22,"assetMetallicRoughnessTexture","metallicRoughnessTexture","metallicRoughness.texture",[Be]),et("properties.occlusion.texture.textureAssetId","properties.occlusion.texture","geometry",23,"assetOcclusionTexture","occlusionTexture","occlusion.texture",[Be]),me("properties.occlusion.strength","geometry",24,"assetOcclusionStrength","occlusionStrength",1,{softMin:0,softMax:4,step:.05,conditions:[Be,Ye("properties.occlusion.texture.textureAssetId","occlusionTexture")]})],zd=[{shaderId:"fps.builtin.pbr",version:1,runtimeKind:"pbr",displayName:"PBR",propertiesSchema:Gd,defaultProperties:Fd,inspector:{sections:Ai,fields:Ld}},{shaderId:"fps.builtin.standard",version:1,runtimeKind:"standard",displayName:"Standard",propertiesSchema:jd,defaultProperties:_d,inspector:{sections:Ai,fields:Di}}],ki=Ud(zd);function Ud(e){let t=new Map;for(let r of e){Bd(r,t);let i=Vd(r);t.set(r.shaderId,$i(i))}let n=Object.freeze([...t.values()]);return Object.freeze({get(r){return typeof r=="string"?t.get(r)??null:null},list(){return n}})}function Mi(e,t=ki){return t.get(e)}function on(e){return Mi(e)}function sn(e,t,n="properties",r=ki){let i=Mi(e,r);if(!i)return[{path:"shaderId",message:`Unknown material shader: ${String(e)}`}];let o=[];return qn(i.propertiesSchema,t,n,o),o}function Qe(e,t,n,r,i,o,s,a){return{path:e,sectionId:t,order:n,control:r,labelKey:i,tooltipKey:o,defaultValue:s,updateClass:"uniform",...a}}function me(e,t,n,r,i,o,s={}){return Qe(e,t,n,"number",r,i,o,{binding:e.replace(/^properties\./,""),step:s.step??.05,displayPrecision:2,precision:2,...s})}function et(e,t,n,r,i,o,s,a){return Qe(e,n,r,"texture",i,o,"",{schemaPath:t,binding:s,updateClass:"texture",...a?{conditions:a}:{}})}function Ye(e,t){return{path:e,operator:"truthy",inactiveReasonKey:t}}function Bd(e,t){if(!Zt(e.shaderId)&&!Hn(e.shaderId))throw new Error("Material Shader Definition shaderId must be a supported built-in id or a lowercase namespaced project id.");if(!Number.isInteger(e.version)||e.version<=0)throw new Error(`Material Shader Definition ${e.shaderId} must use a positive integer version.`);if(t.has(e.shaderId))throw new Error(`Duplicate Material Shader Definition: ${e.shaderId}`);if(e.sourceFile!=null&&!Hd(e.sourceFile))throw new Error(`Material Shader Definition ${e.shaderId} sourceFile must be a safe project-relative path.`);Ci(e.shaderId,e.propertiesSchema,"properties");let n=[];if(qn(e.propertiesSchema,e.defaultProperties,"properties",n),n.length>0){let o=n[0];throw new Error(`Material Shader Definition ${e.shaderId} default ${o.path} ${o.message}.`)}let r=new Set;for(let o of e.inspector.sections){if(!o.id.trim()||r.has(o.id))throw new Error(`Material Shader Definition ${e.shaderId} contains an invalid or duplicate section: ${o.id}`);r.add(o.id)}let i=new Set;for(let o of e.inspector.fields){if(!o.path.startsWith("properties.")||i.has(o.path))throw new Error(`Material Shader Definition ${e.shaderId} contains an invalid or duplicate field: ${o.path}`);if(!r.has(o.sectionId))throw new Error(`Material Shader Definition ${e.shaderId} field ${o.path} references an unknown section.`);Kd(e,o),i.add(o.path)}}function Vd(e){let t=structuredClone(e);return{...t,inspector:{...t.inspector,fields:t.inspector.fields.map(n=>{if(n.control!=="number")return n;let r=Ri(t.propertiesSchema,n.schemaPath??n.path);return r?.kind!=="number"?n:{...n,...r.min!=null?{min:r.min}:{},...r.max!=null?{max:r.max}:{}}})}}}function Kd(e,t){let n=[["min",t.min],["max",t.max],["softMin",t.softMin],["softMax",t.softMax]];for(let[i,o]of n)if(o!=null&&!Number.isFinite(o))throw new Error(`Material Shader Definition ${e.shaderId} field ${t.path} ${i} must be finite.`);if(t.control!=="number"){if(n.some(([,i])=>i!=null))throw new Error(`Material Shader Definition ${e.shaderId} field ${t.path} uses numeric ranges with a non-number control.`);return}let r=Ri(e.propertiesSchema,t.schemaPath??t.path);if(r?.kind!=="number")throw new Error(`Material Shader Definition ${e.shaderId} field ${t.path} must reference a number schema.`);for(let[i,o,s]of[["min",t.min,r.min],["max",t.max,r.max]])if(o!=null&&o!==s)throw new Error(`Material Shader Definition ${e.shaderId} field ${t.path} ${i} must match propertiesSchema.`);if(t.softMin!=null&&t.softMax!=null&&t.softMin>t.softMax)throw new Error(`Material Shader Definition ${e.shaderId} field ${t.path} softMin must not exceed softMax.`);if(r.min!=null&&t.softMin!=null&&t.softMin<r.min)throw new Error(`Material Shader Definition ${e.shaderId} field ${t.path} softMin must not be below the schema minimum.`);if(r.max!=null&&t.softMax!=null&&t.softMax>r.max)throw new Error(`Material Shader Definition ${e.shaderId} field ${t.path} softMax must not exceed the schema maximum.`)}function Ci(e,t,n){if(t.kind==="object"){for(let[r,i]of Object.entries(t.properties))Ci(e,i,`${n}.${r}`);return}if(t.kind==="number"){if(t.min!=null&&!Number.isFinite(t.min))throw new Error(`Material Shader Definition ${e} number field ${n} min must be finite.`);if(t.max!=null&&!Number.isFinite(t.max))throw new Error(`Material Shader Definition ${e} number field ${n} max must be finite.`);if(t.min!=null&&t.max!=null&&t.min>t.max)throw new Error(`Material Shader Definition ${e} number field ${n} min must not exceed max.`);return}if(t.kind==="color"&&t.channels!=null&&t.channels!==3&&t.channels!==4)throw new Error(`Material Shader Definition ${e} color field ${n} channels must be 3 or 4.`)}function Hd(e){let t=e.trim();return!t||t.startsWith("/")||t.includes("\\")||t.includes(":")?!1:!t.split("/").includes("..")}function Wd(e){let t=e.trim();return t.startsWith("properties.")?t:`properties.${t}`}function Ri(e,t){let n=Wd(t).replace(/^properties\./,"").split(".").filter(Boolean);if(n.length===0)return null;let r=e;for(let i of n){if(r.kind!=="object")return null;let o=r.properties[i];if(!o)return null;r=o}return r}function qn(e,t,n,r){if(e.kind==="object"){if(!Wn(t)){r.push({path:n,message:"must be an object"});return}for(let o of Object.keys(t))Object.prototype.hasOwnProperty.call(e.properties,o)||r.push({path:`${n}.${o}`,message:"is not supported by the selected shader"});for(let[o,s]of Object.entries(e.properties))t[o]!==void 0&&qn(s,t[o],`${n}.${o}`,r);return}if(e.kind==="number"){if(typeof t!="number"||!Number.isFinite(t)){r.push({path:n,message:"must be a finite number"});return}e.min!=null&&t<e.min&&r.push({path:n,message:`must be greater than or equal to ${e.min}`}),e.max!=null&&t>e.max&&r.push({path:n,message:`must be less than or equal to ${e.max}`});return}if(e.kind==="boolean"){typeof t!="boolean"&&r.push({path:n,message:"must be a boolean"});return}if(e.kind==="string"){t!==null&&typeof t!="string"?r.push({path:n,message:"must be a string"}):t===null&&!e.nullable&&r.push({path:n,message:"must not be null"});return}if(e.kind==="enum"){(typeof t!="string"||!e.values.includes(t))&&r.push({path:n,message:`must be one of: ${e.values.join(", ")}`});return}if(e.kind==="color"){let o=e.channels===4?["r","g","b","a"]:["r","g","b"];wi(t,n,o,r,e.channels===4?"an RGBA object":"an RGB object");return}if(e.kind==="vec2"||e.kind==="vec3"){wi(t,n,e.kind==="vec2"?["x","y"]:["x","y","z"],r,`a ${e.kind} object`);return}if(t===null)return;if(!Wn(t)){r.push({path:n,message:"must be a texture reference object or null"});return}Object.keys(t).some(o=>o!=="url"&&o!=="textureAssetId")&&r.push({path:n,message:"must contain only url or textureAssetId"});for(let o of["url","textureAssetId"]){let s=t[o];s!==void 0&&(typeof s!="string"||!s.trim())&&r.push({path:`${n}.${o}`,message:"must be a non-empty string"})}}function wi(e,t,n,r,i){if(!Wn(e)){r.push({path:t,message:`must be ${i}`});return}Object.keys(e).some(o=>!n.includes(o))&&r.push({path:t,message:`must contain only ${n.join(", ")}`});for(let o of n)(typeof e[o]!="number"||!Number.isFinite(e[o]))&&r.push({path:`${t}.${o}`,message:"must be a finite number"})}function $i(e){if(e&&typeof e=="object"&&!Object.isFrozen(e)){Object.freeze(e);for(let t of Object.values(e))$i(t)}return e}function Wn(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Ni(e){return e.trim().replace(/^\/+|\/+$/g,"")}function qd(e){let t=[],n=new Map(e.assets.map(r=>[r.id,r]));for(let r of e.scene.gameObjects){let i=oc(r),o=an(r.overrides?.materialBinding);o&&t.push({kind:"root",scope:"scene",gameObjectId:r.id,gameObjectName:r.name,materialAssetId:o,bindingPath:"overrides.materialBinding.materialAssetId",label:i});let s=Jd(e,r,n),a=new Map(s.filter(d=>!!d.slotId).map(d=>[d.slotId,d])),c=r.overrides?.materialSlotBindings??{};for(let[d,u]of Object.entries(c)){let l=an(u);if(!l)continue;let f=a.get(d),g=sc(f,d);t.push({kind:"slot",scope:"scene",gameObjectId:r.id,gameObjectName:r.name,materialAssetId:l,bindingPath:`overrides.materialSlotBindings.${d}.materialAssetId`,label:`${i} / ${g}`,slotId:d,ownerNodePath:Gi(f)??d})}}for(let r of e.assets)if(!(r.type!=="prefab"||!r.prefab)){Oi(t,{ownerId:r.id,ownerName:r.displayName??r.id,prefabAssetId:r.id,path:`assets.${r.id}.prefab.overrides`,overrides:r.prefab.overrides});for(let i of r.prefab.nodes??[])Oi(t,{ownerId:`${r.id}:${i.id}`,ownerName:`${r.displayName??r.id} / ${i.name??i.id}`,prefabAssetId:r.id,prefabNodeId:i.id,path:`assets.${r.id}.prefab.nodes.${i.id}.overrides`,overrides:i.overrides})}return t}function Oi(e,t){let n=an(t.overrides?.materialBinding);n&&e.push({kind:"root",scope:"prefab",gameObjectId:t.ownerId,gameObjectName:t.ownerName,materialAssetId:n,bindingPath:`${t.path}.materialBinding.materialAssetId`,label:t.ownerName,prefabAssetId:t.prefabAssetId,...t.prefabNodeId?{prefabNodeId:t.prefabNodeId}:{}});for(let[r,i]of Object.entries(t.overrides?.materialSlotBindings??{})){let o=an(i);o&&e.push({kind:"slot",scope:"prefab",gameObjectId:t.ownerId,gameObjectName:t.ownerName,materialAssetId:o,bindingPath:`${t.path}.materialSlotBindings.${r}.materialAssetId`,label:`${t.ownerName} / ${r}`,slotId:r,ownerNodePath:r,prefabAssetId:t.prefabAssetId,...t.prefabNodeId?{prefabNodeId:t.prefabNodeId}:{}})}}function dn(e){let t=[...new Set((e.scene.materialAssets??[]).map(a=>a.id?.trim()).filter(a=>!!a))],n=new Set(t),r=qd(e),i=r.filter(a=>!n.has(a.materialAssetId)),o=new Map;for(let a of i){let c=o.get(a.materialAssetId)??[];c.push(a),o.set(a.materialAssetId,c)}let s=[...o.entries()].map(([a,c])=>({kind:"missing-material-asset",materialAssetId:a,usages:c}));return{ok:s.length===0,materialAssetIds:t,references:r,missingMaterialAssetIds:s.map(a=>a.materialAssetId),missingReferences:i,issues:s}}function Jd(e,t,n){let r=new Map;for(let i of Xd(e,t,n))r.set(i.slotId,i);return[...r.values()].sort((i,o)=>(i.label??i.slotId).localeCompare(o.label??o.slotId)||i.slotId.localeCompare(o.slotId))}function Gi(e){return e?.sourceSurfaces[0]?.ownerNodePath??null}function Xd(e,t,n){let r=tt(t);if(!r)return[];let o=(n?.get(r.assetId)??e.assets.find(a=>a.id===r.assetId))?.metadata?.materialSlots;if(!Array.isArray(o))return[];let s=[];for(let a of o){let c=Zd(a);c&&s.push(c)}return s}function Zd(e){if(!e||typeof e!="object"||Array.isArray(e))return null;let t=e,n=typeof t.slotId=="string"&&t.slotId.trim()?t.slotId.trim():"",r=Array.isArray(t.sourceSurfaces)?t.sourceSurfaces:null,i=Yd(r);if(!n||!r||i.length===0||i.length!==r.length)return null;let o=typeof t.label=="string"&&t.label.trim()?t.label.trim():i[0].ownerNodePath,s=typeof t.materialName=="string"&&t.materialName.trim()?t.materialName.trim():"",a=Array.isArray(t.materialNames)?t.materialNames.filter(d=>typeof d=="string"&&!!d.trim()).map(d=>d.trim()):void 0,c=ec(t.sourceMaterialProfiles);return{slotId:n,label:o,sourceSurfaces:i,...s?{materialName:s}:{},...a&&a.length>0?{materialNames:a}:{},...c&&c.length>0?{sourceMaterialProfiles:c}:{}}}function Yd(e){return Array.isArray(e)?e.flatMap(t=>{let n=ic(t);if(!n)return[];let r=Ni(typeof n.ownerNodePath=="string"?n.ownerNodePath:""),i=Number.isInteger(n.meshIndex)&&n.meshIndex>=0?n.meshIndex:void 0,o=Number.isInteger(n.primitiveIndex)&&n.primitiveIndex>=0?n.primitiveIndex:void 0;if(!r||i==null||o==null)return[];let s=Number.isInteger(n.nodeIndex)&&n.nodeIndex>=0?n.nodeIndex:void 0,a=Array.isArray(n.nodeIndexPath)?n.nodeIndexPath.filter(f=>Number.isInteger(f)&&f>=0):void 0,c=Number.isInteger(n.sourceMaterialIndex)&&n.sourceMaterialIndex>=0?n.sourceMaterialIndex:void 0,d=typeof n.sourceMeshName=="string"&&n.sourceMeshName.trim()?n.sourceMeshName.trim():void 0,u=typeof n.triangleCount=="number"&&Number.isFinite(n.triangleCount)&&n.triangleCount>=0?n.triangleCount:void 0,l=Qd(n.boundingBox);return[{ownerNodePath:r,...s!=null?{nodeIndex:s}:{},...a&&a.length>0?{nodeIndexPath:a}:{},meshIndex:i,primitiveIndex:o,...c!=null?{sourceMaterialIndex:c}:{},...d?{sourceMeshName:d}:{},...u!=null?{triangleCount:u}:{},...l?{boundingBox:l}:{}}]}):[]}function Qd(e){if(!e||typeof e!="object"||Array.isArray(e))return;let t=e,n=vi(t.min),r=vi(t.max);if(!(!n&&!r))return{...n?{min:n}:{},...r?{max:r}:{}}}function vi(e){if(!Array.isArray(e)||e.length<3)return null;let[t,n,r]=e;return typeof t=="number"&&Number.isFinite(t)&&typeof n=="number"&&Number.isFinite(n)&&typeof r=="number"&&Number.isFinite(r)?[t,n,r]:null}function ec(e){if(!Array.isArray(e))return;let t=e.map(tc).filter(n=>!!n);return t.length>0?t:void 0}function tc(e){if(!e||typeof e!="object"||Array.isArray(e))return null;let t=e;if(!Number.isInteger(t.sourceMaterialIndex))return null;let n=typeof t.materialName=="string"&&t.materialName.trim()?t.materialName.trim():"",r=t.profile&&typeof t.profile=="object"&&!Array.isArray(t.profile)?t.profile:void 0,i=nc(t.textureHints);return{sourceMaterialIndex:t.sourceMaterialIndex,...n?{materialName:n}:{},...r?{profile:r}:{},...i&&i.length>0?{textureHints:i}:{}}}function nc(e){if(!Array.isArray(e))return;let t=e.map(rc).filter(n=>!!n);return t.length>0?t:void 0}function rc(e){if(!e||typeof e!="object"||Array.isArray(e))return null;let t=e,n=typeof t.profilePath=="string"&&t.profilePath.trim()?t.profilePath.trim():"",r=typeof t.reason=="string"&&t.reason.trim()?t.reason.trim():"";return!n||!r?null:{profilePath:n,reason:r,...Number.isInteger(t.textureIndex)?{textureIndex:t.textureIndex}:{},...Number.isInteger(t.imageIndex)?{imageIndex:t.imageIndex}:{},...Number.isInteger(t.bufferView)?{bufferView:t.bufferView}:{},...typeof t.mimeType=="string"&&t.mimeType.trim()?{mimeType:t.mimeType.trim()}:{},...typeof t.uri=="string"&&t.uri.trim()?{uri:t.uri.trim()}:{}}}function ic(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function oc(e){return e.name?.trim()||e.id}function an(e){return typeof e?.materialAssetId=="string"?e.materialAssetId.trim():""}function sc(e,t){return e?.label?.trim()||Gi(e)?.trim()||e?.slotId?.trim()||t}var ln=1;function Fi(e){let t=structuredClone(e),n={ordinaryObjects:0,prefabRoots:0,discardedFields:0},r=ne(t.scene);return r&&(Z(r,"shadowMapExperiment",n),Array.isArray(r.gameObjects)&&r.gameObjects.forEach(i=>ac(i,n))),Array.isArray(t.assets)&&t.assets.forEach(i=>dc(i,n)),{document:t,summary:n}}function Jn(e){let t=ne(e);return!t||t.prefab!=null||t.transformType==="camera"||t.transformType==="light"||t.camera!=null||t.light!=null?!1:t.kind==="primitive"||ne(t.primitive)?!0:Array.isArray(t.components)&&t.components.some(n=>{let r=ne(n)?.type;return r==="ModelRenderer"||r==="ImageRenderer"})}function ac(e,t){let n=ne(e);if(!n)return;let r=ne(n.shadow);Z(n,"shadowMode",t),Z(n,"shadowMapExperiment",t),Jn(n)?(n.shadow=_i(r),t.ordinaryObjects+=1):Z(n,"shadow",t)}function dc(e,t){let n=ne(e);if(!n)return;let r=ne(n.defaults);r&&(Z(r,"shadowMode",t),Z(r,"shadow",t),Z(r,"shadowMapExperiment",t));let i=ne(n.prefab);if(!i)return;let o=ne(i.defaults);o&&Z(o,"shadowMode",t),i.defaults={...o??{},shadow:_i(o?.shadow)},t.prefabRoots+=1;let s=ne(i.defaults);if(Z(s,"shadowMapExperiment",t),Array.isArray(i.nodes))for(let a of i.nodes){let c=ne(a);if(!c)continue;Z(c,"shadowMode",t),Z(c,"shadow",t),Z(c,"shadowMapExperiment",t);let d=ne(c.defaults);d&&(Z(d,"shadowMode",t),Z(d,"shadow",t),Z(d,"shadowMapExperiment",t))}}function _i(e){let t=ne(e);return{cast:t?.cast==="enabled"?"enabled":"none",receive:t?.receive==="enabled"?"enabled":"none"}}function Z(e,t,n){Object.prototype.hasOwnProperty.call(e,t)&&(delete e[t],n.discardedFields+=1)}function ne(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}var Am=Symbol("unsupported-editor-scene-authored-clone-value");function Xn(e){return e.components.find(fc)??null}function tt(e){return e.components.find(mc)??null}function Zn(e){return e.components.find(gc)??null}function cn(e){return e?.type==="prefab"&&U(e.prefab?.sourceAssetId)!=null}function Li(e){return U(e?.prefab?.prefabId)!=null}function ji(e){return U(e?.prefab?.sourceAssetId)}function It(e){if(!e?.prefab)return null;let t=zi(e.prefab),n=U(e.prefab.rootNodeId);if(n&&t.some(i=>i.id===n))return n;let r=t.find(i=>i.kind==="root"&&!i.parentId);return r?r.id:null}function Et(e){return e?.prefab?zi(e.prefab):[]}function zi(e){if(!Array.isArray(e.nodes))return[];let t=[];for(let n of e.nodes){let r=cc(n);r&&!t.some(i=>i.id===r.id)&&t.push(r)}return structuredClone(t)}function cc(e){if(!e||typeof e!="object"||Array.isArray(e))return null;let t=e,n=U(t.id);return!n||!lc(t.kind)?null:{id:n,...U(t.guid)?{guid:U(t.guid)}:{},...U(t.name)?{name:U(t.name)}:{},...U(t.parentId)?{parentId:U(t.parentId)}:{},kind:t.kind,...t.transform?{transform:structuredClone(t.transform)}:{},...U(t.sourceAssetId)?{sourceAssetId:U(t.sourceAssetId)}:{},...U(t.sourceNodePath)?{sourceNodePath:U(t.sourceNodePath)}:{},...U(t.childPrefabId)?{childPrefabId:U(t.childPrefabId)}:{},...t.primitive?{primitive:structuredClone(t.primitive)}:{},...t.light?{light:structuredClone(t.light)}:{},...t.marker?{marker:structuredClone(t.marker)}:{},...t.defaults?{defaults:structuredClone(t.defaults)}:{},...t.overrides?{overrides:structuredClone(t.overrides)}:{},...t.metadata?{metadata:structuredClone(t.metadata)}:{}}}function lc(e){return e==="root"||e==="group"||e==="model"||e==="primitive"||e==="light"||e==="prefabInstance"||e==="marker"||e==="collision"}function Ui(e,t){let n=U(e?.materialAssetId),r=U(t?.materialAssetId),i=Bn(e?.override,t?.override);return yc({...r??n?{materialAssetId:r??n}:{},...Pt(i)?{override:i}:{}})}function Bi(e,t){let n={},r=Ui(e?.materialBinding,t?.materialBinding);r&&(n.materialBinding=r);let i=hc(e?.materialSlotBindings,t?.materialSlotBindings);return i&&(n.materialSlotBindings=i),Pt(n)?n:void 0}function un(e,t){let n=typeof t=="string"?bc(e,t):t,r=typeof t=="string"?t:t.id,i=[],o=Li(n)?n.prefab:null;if(!n||!o)return i.push({code:"not-prefab-instance",severity:"info",message:n?`GameObject "${n.id}" is not a prefab instance.`:`GameObject "${r}" was not found.`}),{gameObject:n,prefab:null,definition:null,sourceAsset:null,diagnostics:i};let s=e.assets.find(d=>d.id===o.prefabId&&cn(d));s||i.push({code:"missing-prefab-definition",severity:"error",message:`Prefab definition "${o.prefabId}" was not found.`,prefabId:o.prefabId});let a=ji(s)??U(o.sourceAssetId);s&&o.sourceAssetId&&a&&o.sourceAssetId!==a&&i.push({code:"source-asset-mismatch",severity:"warning",message:`Prefab instance source "${o.sourceAssetId}" does not match definition source "${a}".`,prefabId:o.prefabId,expectedSourceAssetId:a,actualSourceAssetId:o.sourceAssetId});let c=a?e.assets.find(d=>d.id===a):void 0;if(a&&!c&&i.push({code:"missing-source-asset",severity:"error",message:`Prefab source asset "${a}" was not found.`,prefabId:o.prefabId,sourceAssetId:a}),a){let d=e.assets.filter(u=>cn(u)&&ji(u)===a).map(u=>u.id);d.length>1&&i.push({code:"duplicate-source-prefab",severity:"info",message:`Source asset "${a}" is referenced by ${d.length} prefab definitions.`,prefabId:o.prefabId,sourceAssetId:a})}return{gameObject:n,prefab:o,definition:s??null,sourceAsset:c??null,diagnostics:i}}function nt(e){return e.kind==="group"||e.kind==="instance"||e.kind==="transform"||e.kind==="primitive"?e.kind:Li(e)?"instance":e.primitive?"primitive":tt(e)?"instance":Zn(e)||e.transformType?"transform":"group"}function Vi(e){let t=e.rendering&&typeof e.rendering=="object"&&!Array.isArray(e.rendering)?e.rendering:void 0,n=uc(t?.renderingGroupId),r=pc(t?.alphaIndex),i={};return n!=null&&(i.renderingGroupId=n),r!=null&&(i.alphaIndex=r),Object.keys(i).length>0?i:void 0}function uc(e){return e===0||e===1||e===2||e===3?e:null}function fc(e){return e.type==="Transform"}function mc(e){return e.type==="ModelRenderer"}function gc(e){return e.type==="ImageRenderer"}function pc(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function U(e){return typeof e=="string"&&e.trim().length>0?e.trim():null}function bc(e,t){return e.scene.gameObjects.find(n=>n.id===t)??null}function yc(e){if(!e||typeof e!="object"||Array.isArray(e))return;let t=e,n=U(t.materialAssetId),r=Bn(t.override),i={...n?{materialAssetId:n}:{},...Pt(r)?{override:r}:{}};return Pt(i)?i:void 0}function hc(e,t){let n=new Set([...Object.keys(e??{}),...Object.keys(t??{})]),r={};for(let i of n){let o=Ui(e?.[i],t?.[i]);o&&(r[i]=o)}return Pt(r)?r:void 0}function Pt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length>0}var Sc=new Set(["id","guid","name","parentId","kind","transform","marker","metadata"]);function Ki(e,t,n){if(e.kind!=="marker"){Object.prototype.hasOwnProperty.call(e,"marker")&&k("schema.invalidValue",`${n}.marker`);return}for(let a of Object.keys(e))Sc.has(a)||k("schema.invalidValue",`${n}.${a}`);At(e.parentId)||k("schema.invalidReference",`${n}.parentId`),Ec(e.transform,`${n}.transform`),xc(e.marker,`${n}.marker`);let r=At(e.id),i=e.marker,o=Pc(i,`${n}.marker`),s=o[0]??null;for(let a of o){a.target.id===r&&k("schema.invalidReference",`${a.path}.id`),s&&(a.target.kind!==s.target.kind||a.target.id!==s.target.id)&&k("schema.invalidReference",a.path);let c=t.get(a.target.id);c&&(a.target.kind==="marker"&&c.kind!=="marker"&&k("schema.invalidReference",`${a.path}.kind`),a.target.kind==="scene-object"&&c.kind==="marker"&&k("schema.invalidReference",`${a.path}.kind`))}}function xc(e,t){let n=Ne(e);n||k("schema.invalidType",t),ge(n,["schemaVersion","type","kind","tags","note","color","target","semanticFrame","geometry","metadata"],t),n.schemaVersion!==1&&k("schema.unsupportedVersion",`${t}.schemaVersion`),At(n.type)||k("schema.invalidValue",`${t}.type`),n.kind!==void 0&&!At(n.kind)&&k("schema.invalidValue",`${t}.kind`),n.tags!==void 0&&Tc(n.tags,`${t}.tags`),n.note!==void 0&&typeof n.note!="string"&&k("schema.invalidType",`${t}.note`),n.color!==void 0&&wc(n.color,`${t}.color`),n.target!==void 0&&Yn(n.target,`${t}.target`),n.semanticFrame!==void 0&&Ac(n.semanticFrame,`${t}.semanticFrame`),Ic(n.geometry,`${t}.geometry`),n.metadata!==void 0&&Dc(n.metadata,`${t}.metadata`)}function Pc(e,t){let n=[];return e.target&&n.push({target:e.target,path:`${t}.target`}),e.geometry.kind==="point"&&e.geometry.target&&n.push({target:e.geometry.target,path:`${t}.geometry.target`}),e.geometry.kind==="object-bounds"&&n.push({target:e.geometry.target,path:`${t}.geometry.target`}),n}function Ic(e,t){let n=Ne(e);if(n||k("schema.invalidType",t),n.kind==="box"){ge(n,["kind"],t);return}if(n.kind==="point"){ge(n,["kind","coordinateSpace","position","offset","target"],t),n.coordinateSpace!==void 0&&n.coordinateSpace!=="world"&&n.coordinateSpace!=="local"&&k("schema.invalidValue",`${t}.coordinateSpace`),n.position!==void 0&&$e(n.position,`${t}.position`),n.offset!==void 0&&$e(n.offset,`${t}.offset`),n.target!==void 0&&Yn(n.target,`${t}.target`);return}if(n.kind==="object-bounds"){ge(n,["kind","target"],t),Yn(n.target,`${t}.target`);return}if(n.kind==="polyhedron"){ge(n,["kind","coordinateSpace","vertices","faces"],t),n.coordinateSpace!==void 0&&n.coordinateSpace!=="world"&&k("schema.invalidValue",`${t}.coordinateSpace`),Array.isArray(n.vertices)||k("schema.invalidType",`${t}.vertices`),n.vertices.forEach((r,i)=>$e(r,`${t}.vertices[${i}]`)),n.faces!==void 0&&(Array.isArray(n.faces)||k("schema.invalidType",`${t}.faces`),n.faces.forEach((r,i)=>{Array.isArray(r)||k("schema.invalidType",`${t}.faces[${i}]`),r.forEach((o,s)=>{(!Number.isInteger(o)||o<0)&&k("schema.invalidValue",`${t}.faces[${i}][${s}]`)})}));return}k("schema.invalidValue",`${t}.kind`)}function Yn(e,t){let n=Ne(e);n||k("schema.invalidType",t),ge(n,["kind","id","label"],t),n.kind!=="marker"&&n.kind!=="scene-object"&&k("schema.invalidValue",`${t}.kind`),At(n.id)||k("schema.invalidValue",`${t}.id`),n.label!==void 0&&typeof n.label!="string"&&k("schema.invalidType",`${t}.label`)}function Ec(e,t){let n=Ne(e);if(n||k("schema.invalidType",t),n.type!=="Transform"&&k("schema.invalidValue",`${t}.type`),n.mode==="matrix"){ge(n,["type","mode","matrix"],t),(!Array.isArray(n.matrix)||n.matrix.length!==16)&&k("schema.invalidType",`${t}.matrix`),n.matrix.forEach((r,i)=>fn(r,`${t}.matrix[${i}]`));return}ge(n,["type","mode","position","rotation","scale"],t),n.mode!==void 0&&n.mode!=="trs"&&k("schema.invalidValue",`${t}.mode`),$e(n.position,`${t}.position`),$e(n.rotation,`${t}.rotation`),n.scale!==void 0&&$e(n.scale,`${t}.scale`)}function Ac(e,t){let n=Ne(e);n||k("schema.invalidType",t),ge(n,["origin","forward","right","up","label","description"],t),$e(n.origin,`${t}.origin`);for(let r of["forward","right","up"])n[r]!==void 0&&$e(n[r],`${t}.${r}`);for(let r of["label","description"])n[r]!==void 0&&typeof n[r]!="string"&&k("schema.invalidType",`${t}.${r}`)}function wc(e,t){let n=Ne(e);n||k("schema.invalidType",t),ge(n,["r","g","b"],t);for(let r of["r","g","b"])fn(n[r],`${t}.${r}`),(n[r]<0||n[r]>1)&&k("schema.invalidValue",`${t}.${r}`)}function $e(e,t){let n=Ne(e);n||k("schema.invalidType",t),ge(n,["x","y","z"],t);for(let r of["x","y","z"])fn(n[r],`${t}.${r}`)}function Tc(e,t){Array.isArray(e)||k("schema.invalidType",t),e.forEach((n,r)=>{typeof n!="string"&&k("schema.invalidType",`${t}[${r}]`)})}function Dc(e,t){let n=Ne(e);n||k("schema.invalidType",t),Qn(n,t,new Set)}function Qn(e,t,n){if(e===null||typeof e=="string"||typeof e=="boolean")return;if(typeof e=="number"){fn(e,t);return}(!e||typeof e!="object")&&k("schema.invalidType",t),n.has(e)&&k("schema.invalidValue",t);let r=Object.getPrototypeOf(e);Array.isArray(e)?r!==Array.prototype&&k("schema.invalidType",t):r!==Object.prototype&&r!==null&&k("schema.invalidType",t),n.add(e);try{if(Array.isArray(e))e.forEach((i,o)=>Qn(i,`${t}[${o}]`,n));else for(let[i,o]of Object.entries(e))Qn(o,`${t}.${i}`,n)}finally{n.delete(e)}}function ge(e,t,n){let r=new Set(t);for(let i of Object.keys(e))r.has(i)||k("schema.invalidValue",`${n}.${i}`)}function fn(e,t){(typeof e!="number"||!Number.isFinite(e))&&k("schema.invalidValue",t)}function Ne(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function At(e){return typeof e=="string"&&e.trim()?e.trim():null}function k(e,t){throw new Error(`${e}: ${t}`)}function tr(e,t){return t===e.rootNodeId?e.instanceId:`${e.instanceId}:${kc(t)}`}function kc(e){return encodeURIComponent(e)}function er(e,t){return{...structuredClone(e),id:tr(t,e.id)}}function Hi(e,t){let n=structuredClone(e);return n.target&&(n.target=er(n.target,t)),n.geometry.kind==="point"&&n.geometry.target&&(n.geometry.target=er(n.geometry.target,t)),n.geometry.kind==="object-bounds"&&(n.geometry.target=er(n.geometry.target,t)),n}var Wi={x:-.3,y:-1,z:-.2};var qi="scene.main",Ji="scene";function Xi(e){let t=e.meta?.authoringSource;return{sourceId:t?.sourceId||qi,sourceType:t?.sourceType||Ji,revision:typeof t?.revision=="number"?t.revision:1}}var Mc="sun_light";function Cc(e,t){let n=typeof t.prefab?.prefabId=="string"?t.prefab.prefabId:null,r=n?e.assets.find(o=>o.id===n)?.prefab?.defaults?.shadow:void 0,i=De(r??t.shadow);return{settings:i.shadow,diagnostics:i.diagnostics}}function Rc(e){let t=new Map,n=e.casterId;for(let r of e.explicitReceiverIds??[]){let i=gn(e.document,r);!i||i.id===n||i.active===!1||t.set(i.id,{receiverId:i.id,source:"explicit",score:120,...nr(i,"explicit",120,["explicit receiver id"])})}for(let r of e.document.scene.gameObjects){if(r.id===n||r.active===!1)continue;De(r.shadow).shadow?.receive==="enabled"&&Oc(t,{receiverId:r.id,source:"explicit",score:100,...nr(r,"explicit",100,["shadow.receive enabled"])})}return[...t.values()].sort((r,i)=>i.score-r.score||r.receiverId.localeCompare(i.receiverId))}function mn(e){let t=e.caster?.id===e.casterId?e.caster:gn(e.document,e.casterId),n=[];if(!t)return{casterId:e.casterId,receiverIds:[],backend:"none",mode:"none",quality:e.fallbackQuality??"medium",params:zt(e.fallbackQuality??"medium"),diagnostics:[{code:"shadow.invalidTarget",severity:"error",message:`Shadow caster "${e.casterId}" was not found.`,casterId:e.casterId}]};let r=e.resolvedSettings!==void 0?(()=>{let g=De(e.resolvedSettings);return{settings:g.shadow,diagnostics:g.diagnostics}})():Cc(e.document,t);n.push(...r.diagnostics);let o=r.settings?.cast==="enabled"?Cn(r.settings,e.fallbackMode??"none"):"none",s=Rn(r.settings,e.fallbackQuality??"medium"),a=zt(s,r.settings?.params),c=$c(o),d=vc(e.explicitReceiverIds),u=c==="none"?{candidates:[],diagnostics:[]}:d.length>0&&e.strictExplicitReceivers===!0?Gc(e.document,t.id,d):{candidates:Rc({document:e.document,casterId:t.id,explicitReceiverIds:d.length>0?d:void 0}),diagnostics:[]};n.push(...u.diagnostics);let l=u.candidates;c!=="none"&&l.length===0&&n.push({code:"shadow.receiverNotFound",severity:"warning",message:`No shadow receiver was found for caster "${t.id}".`,casterId:t.id});let f=c==="none"?null:Nc(e.document,r.settings??void 0,e.defaultLightId);return f?.diagnostic&&n.push(f.diagnostic),{casterId:t.id,receiverIds:l.map(g=>g.receiverId),...f?.lightId?{lightId:f.lightId}:{},backend:c,mode:o,quality:s,params:a,diagnostics:n}}function $c(e){return e==="dynamic"?"dynamic-map":e==="static"?"static-baked":e==="blob"?"blob":e==="projected"?"projected":"none"}function Nc(e,t,n){if(t?.light?.mode==="explicit"){let o=t?.light?.lightId;return o&&Zi(e,o)?{lightId:o}:{diagnostic:{code:"shadow.lightNotFound",severity:"warning",message:o?`Explicit shadow light "${o}" was not found.`:"Shadow light mode is explicit, but no lightId was configured.",...o?{lightId:o}:{}}}}let r=n??Mc;if(Zi(e,r))return{lightId:r};let i=e.scene.gameObjects.find(o=>Yi(o)&&o.active!==!1);return i?{lightId:i.id}:{diagnostic:{code:"shadow.lightNotFound",severity:"warning",message:"No directional shadow light was found."}}}function Zi(e,t){let n=gn(e,t);return!!n&&n.active!==!1&&Yi(n)}function Yi(e){return nt(e)==="transform"&&e.light?.type==="directional"}function Oc(e,t){let n=e.get(t.receiverId);(!n||t.score>n.score)&&e.set(t.receiverId,t)}function vc(e){let t=new Set,n=[];for(let r of e??[]){let i=typeof r=="string"?r.trim():"";!i||t.has(i)||(t.add(i),n.push(i))}return n}function Gc(e,t,n){let r=[],i=[];for(let o of n){let s=gn(e,o);if(!s){i.push({code:"shadow.receiverNotFound",severity:"warning",message:`Explicit shadow receiver "${o}" was not found.`,casterId:t,receiverId:o,details:{source:"explicit"}});continue}if(s.id===t){i.push({code:"shadow.receiverNotFound",severity:"warning",message:`Shadow caster "${t}" cannot be used as its own receiver.`,casterId:t,receiverId:o,details:{source:"explicit",reason:"self"}});continue}if(s.active===!1){i.push({code:"shadow.receiverNotFound",severity:"warning",message:`Explicit shadow receiver "${o}" is inactive.`,casterId:t,receiverId:o,details:{source:"explicit",reason:"inactive"}});continue}r.push({receiverId:s.id,source:"explicit",score:120,...nr(s,"explicit",120,["explicit receiver id"])})}return{candidates:r,diagnostics:i}}function nr(e,t,n,r){let i=De(e.shadow).shadow;return{active:e.active!==!1,visible:e.active!==!1,...i?.receive?{receive:i.receive}:{},suitability:{score:n,material:nt(e)==="primitive"?"primitive":t,reasons:r}}}function gn(e,t){return e.scene.gameObjects.find(n=>n.id===t)??null}var Qi={type:"directional",intensity:2,direction:{...Wi},diffuseColor:{r:1,g:1,b:1},inspectorLanguage:"zh"},rr={type:"hemispheric",intensity:.8,diffuseColor:{r:1,g:1,b:1},groundColor:{r:.48,g:.52,b:.62},inspectorLanguage:"zh"};function to(e){return e.filter(t=>t.kind==="model"||t.kind==="texture").map(jc).sort(Lc)}function jc(e){let t=e.kind==="texture"?"texture":e.kind==="prefab"?"prefab":"glb",n=Ve(e.guid),r=Uc(e);return{id:e.assetId,...n?{guid:n}:{},assetId:e.assetId,type:t,kind:e.kind==="texture"?"texture":e.kind==="prefab"?"prefab":"model",displayName:e.displayName,category:e.category??zc(e),warmupCount:e.warmupCount,singleton:e.singleton,materialMode:e.materialMode,defaults:bn(e.defaults),prefab:bn(e.prefab),external:bn(e.external),metadata:r,origin:e.origin??"project",dedupeKey:e.dedupeKey??n??Kc(e.external)??e.assetId,placeable:_c(e)}}function Fc(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;let t=e;return t.kind==="texture"||t.type==="texture"}function _c(e){return Fc(e)?!0:!e||typeof e!="object"||Array.isArray(e)||e.placeable!==!1}function Lc(e,t){return(e.category??"").localeCompare(t.category??"")||e.displayName.localeCompare(t.displayName)||e.assetId.localeCompare(t.assetId)||e.type.localeCompare(t.type)}function zc(e){return e.kind==="prefab"?"Prefab":e.kind==="texture"?"Texture":e.kind==="image"?"Image":e.kind==="sound"?"Sound":"Model"}function Uc(e){return Bc({originalFileName:e.originalFileName,relativePath:e.relativePath,codeKey:e.codeKey,contentHash:e.contentHash,byteSize:e.byteSize,...bn(e.metadata)})}function Bc(e){if(!Array.isArray(e.materialSlots))return e;let t=pn(e.assetAnalysis),n=Array.isArray(t?.meshes)?t.meshes:[],r=Array.isArray(t?.nodes)?t.nodes:[],i=new Map(n.flatMap(c=>{let d=pn(c),u=wt(d?.meshIndex),l=Ve(d?.name);return u==null||!l?[]:[[u,l]]})),o=new Map(r.flatMap(c=>{let d=pn(c),u=wt(d?.nodeIndex),l=Ve(d?.meshName);return u==null||!l?[]:[[u,l]]})),s=eo(t,"meshCount",n.length)||eo(t,"nodeCount",r.length),a=e.materialSlots.map(c=>{let d=pn(c);if(!d||Ve(d.sourceMeshName))return c;let u=wt(d.meshIndex);if(u==null)return c;let l=wt(d.nodeIndex),f=i.get(u)??(l==null?void 0:o.get(l))??(s?Vc(d):void 0);return f?{...d,sourceMeshName:f}:c});return{...e,materialSlots:a}}function Vc(e){let t=Ve(e.label);if(t){let n=t.replace(/\s+\/\s+Primitive\s+\d+$/,"").trim();if(n)return n}return Ve(e.ownerNodePath)?.split("/").filter(Boolean).pop()}function eo(e,t,n){let r=wt(e?.[t]);return r!=null&&r>n}function Kc(e){return!e||typeof e!="object"||Array.isArray(e)?null:Ve(e.platformAssetId)}function Ve(e){return typeof e=="string"&&e.trim()?e.trim():null}function wt(e){return Number.isInteger(e)&&e>=0?e:null}function pn(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function bn(e){return e==null?void 0:structuredClone(e)}function ro(e,t){let n=new Map(t.filter(o=>o.type==="glb").map(o=>[o.assetId,o])),r=e.assets.map(o=>{if(o.type!=="glb")return o;let s=n.get(o.id);return s?no(o,s):o}),i=new Set(e.assets.map(o=>o.id));for(let o of Hc(e)){if(i.has(o))continue;let s=n.get(o);s&&(r.push(no({id:o,type:"glb"},s)),i.add(o))}return{...e,assets:r}}function Hc(e){let t=[],n=new Set,r=i=>{let o=or(i);!o||n.has(o)||(n.add(o),t.push(o))};for(let i of e.assets)if(i.type==="prefab"){r(i.prefab?.sourceAssetId);for(let o of i.prefab?.nodes??[])r(o.sourceAssetId)}for(let i of e.scene.gameObjects){for(let s of i.components)s.type==="ModelRenderer"&&r(s.assetId);r(i.prefab?.sourceAssetId);let o=ir(ir(i)?.instance);r(o?.assetId)}return t}function io(e){let t=[],n=(i,o)=>{let s=or(o);s&&t.push({assetId:s,...i})};for(let i=0;i<e.scene.gameObjects.length;i+=1){let o=e.scene.gameObjects[i];for(let s=0;s<o.components.length;s+=1){let a=o.components[s];a.type!=="ModelRenderer"&&a.type!=="ImageRenderer"||n({scope:"scene-object",kind:`${a.type}.assetId`,path:`scene.gameObjects[${i}].components[${s}].assetId`,objectId:o.id,...o.name?{objectName:o.name}:{}},a.assetId)}n({scope:"scene-object",kind:"prefab.prefabId",path:`scene.gameObjects[${i}].prefab.prefabId`,objectId:o.id,...o.name?{objectName:o.name}:{}},o.prefab?.prefabId),n({scope:"scene-object",kind:"prefab.sourceAssetId",path:`scene.gameObjects[${i}].prefab.sourceAssetId`,objectId:o.id,...o.name?{objectName:o.name}:{}},o.prefab?.sourceAssetId),rt(o.overrides,`scene.gameObjects[${i}].overrides`,(s,a)=>n({scope:"scene-object",kind:"material.textureAssetId",path:s,objectId:o.id,...o.name?{objectName:o.name}:{}},a))}for(let i=0;i<e.assets.length;i+=1){let o=e.assets[i];if(!o.prefab)continue;let s=`assets[${i}].prefab`;n({scope:"prefab-asset",kind:"prefab.sourceAssetId",path:`${s}.sourceAssetId`,prefabAssetId:o.id},o.prefab.sourceAssetId),rt(o.prefab.overrides,`${s}.overrides`,(c,d)=>n({scope:"prefab-asset",kind:"material.textureAssetId",path:c,prefabAssetId:o.id},d));let a=Et(o);for(let c=0;c<a.length;c+=1){let d=a[c],u=`${s}.nodes[${c}]`;n({scope:"prefab-node",kind:"node.sourceAssetId",path:`${u}.sourceAssetId`,prefabAssetId:o.id,nodeId:d.id},d.sourceAssetId),n({scope:"prefab-node",kind:"node.childPrefabId",path:`${u}.childPrefabId`,prefabAssetId:o.id,nodeId:d.id},d.childPrefabId),rt(d.overrides,`${u}.overrides`,(l,f)=>n({scope:"prefab-node",kind:"material.textureAssetId",path:l,prefabAssetId:o.id,nodeId:d.id},f))}}let r=Array.isArray(e.scene.materialAssets)?e.scene.materialAssets:[];for(let i=0;i<r.length;i+=1){let o=r[i],s=or(o.id)??"";n({scope:"material-asset",kind:"origin.sourceAssetId",path:`scene.materialAssets[${i}].origin.sourceAssetId`,materialAssetId:s},ir(o.origin)?.sourceAssetId),rt(o.properties,`scene.materialAssets[${i}].properties`,(a,c)=>n({scope:"material-asset",kind:"material.textureAssetId",path:a,materialAssetId:s},c))}return t.sort((i,o)=>i.path.localeCompare(o.path))}function no(e,t){return{...e,guid:t.guid??e.guid,displayName:t.displayName||e.displayName,category:t.category??e.category,warmupCount:t.warmupCount??e.warmupCount,singleton:t.singleton??e.singleton,materialMode:t.materialMode??e.materialMode,defaults:yn(t.defaults??e.defaults),prefab:yn(t.prefab??e.prefab),external:yn(t.external??e.external),metadata:yn(t.metadata??e.metadata)}}function yn(e){return e==null?void 0:structuredClone(e)}function rt(e,t,n){if(!(!e||typeof e!="object")){if(Array.isArray(e)){e.forEach((r,i)=>rt(r,`${t}[${i}]`,n));return}for(let[r,i]of Object.entries(e)){let o=`${t}.${r}`;r==="textureAssetId"?n(o,i):rt(i,o,n)}}}function ir(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function or(e){return(typeof e=="string"?e.trim():"")||void 0}function oo(e){let t=dn(e);if(t.ok)return;let n=new Error(`editor_scene_material_assets_missing: ${t.missingMaterialAssetIds.join(", ")}`);throw n.details={missingMaterialAssetIds:t.missingMaterialAssetIds,missingReferences:t.missingReferences.map(r=>({materialAssetId:r.materialAssetId,gameObjectId:r.gameObjectId,bindingPath:r.bindingPath,label:r.label,kind:r.kind,...r.slotId?{slotId:r.slotId}:{},...r.ownerNodePath?{ownerNodePath:r.ownerNodePath}:{}}))},n}var fo="@fps-games/editor.playable-sdk.scene-compiler",mo="3",Wc=new Set(["shadowMode","childMaterialBindings","childMaterials"]),qc=new Set(["coordinateSpace","center","size","rotation"]),so=new Set(["root","group","model","primitive","light","prefabInstance","marker","collision"]);function Jc(e){Xc(e,!0)}function go(e){let t=Fi(e);return Jc(t.document),t}function Xc(e,t){let n=I(e);if(!n)throw new Error("editor_scene_must_be_object");if(n.schemaVersion!==1)throw y("schema.unsupportedVersion","$.schemaVersion");if(!Array.isArray(n.assets))throw new Error("editor_scene_assets_must_be_array");let r=I(n.scene);if(!Array.isArray(r?.gameObjects))throw new Error("editor_scene_game_objects_must_be_array");if(r.materialAssets!=null&&!Array.isArray(r.materialAssets))throw new Error("editor_scene_material_assets_must_be_array");if(Object.prototype.hasOwnProperty.call(r,"shadowMapExperiment"))throw y("schema.forbiddenField","$.scene.shadowMapExperiment");el(n.assets,r.gameObjects),dr(n,"$"),tl(n.assets),Qc(n.assets,r.gameObjects),nl(r.gameObjects,n.assets),rl(r.gameObjects),Yc(r.materialAssets??[]),t&&il(n.assets,r.gameObjects),oo(n),Zc(n.assets,r.gameObjects)}function Zc(e,t){for(let n=0;n<t.length;n+=1){let r=I(t[n]),i=`$.scene.gameObjects[${n}]`,o=Object.prototype.hasOwnProperty.call(r,"shadow");if(I(r.prefab)){if(o)throw y("schema.forbiddenField",`${i}.shadow`)}else if(Jn(r))ao(r.shadow,`${i}.shadow`);else if(o)throw y("schema.forbiddenField",`${i}.shadow`);if(Object.prototype.hasOwnProperty.call(r,"shadowMapExperiment"))throw y("schema.forbiddenField",`${i}.shadowMapExperiment`)}for(let n=0;n<e.length;n+=1){let r=I(e[n]),i=`$.assets[${n}]`,o=I(r.defaults);if(o?.shadow!==void 0)throw y("schema.forbiddenField",`${i}.defaults.shadow`);if(o?.shadowMapExperiment!==void 0)throw y("schema.forbiddenField",`${i}.defaults.shadowMapExperiment`);let s=I(r.prefab);if(!s)continue;let a=I(s.defaults);if(ao(a?.shadow,`${i}.prefab.defaults.shadow`),a?.shadowMapExperiment!==void 0)throw y("schema.forbiddenField",`${i}.prefab.defaults.shadowMapExperiment`);Array.isArray(s.nodes)&&s.nodes.forEach((c,d)=>{let u=I(c),l=`${i}.prefab.nodes[${d}]`,f=I(u?.defaults);if(u?.shadow!==void 0)throw y("schema.forbiddenField",`${l}.shadow`);if(f?.shadow!==void 0)throw y("schema.forbiddenField",`${l}.defaults.shadow`);if(u?.shadowMapExperiment!==void 0)throw y("schema.forbiddenField",`${l}.shadowMapExperiment`);if(f?.shadowMapExperiment!==void 0)throw y("schema.forbiddenField",`${l}.defaults.shadowMapExperiment`)})}}function ao(e,t){let n=I(e);if(!n||n.cast===void 0||n.receive===void 0)throw y("schema.invalidType",t);if(n.cast!=="enabled"&&n.cast!=="none"||n.receive!=="enabled"&&n.receive!=="none")throw y("schema.invalidValue",t);for(let r of Object.keys(n))if(r!=="cast"&&r!=="receive")throw y("schema.forbiddenField",`${t}.${r}`)}function Yc(e){let t=new Set,n=new Set;for(let r=0;r<e.length;r+=1){let i=I(e[r]),o=`$.scene.materialAssets[${r}]`;if(!i)throw y("schema.invalidType",o);if(Object.prototype.hasOwnProperty.call(i,"materialKind"))throw y("schema.deprecatedField",`${o}.materialKind`);if(Object.prototype.hasOwnProperty.call(i,"profile"))throw y("schema.deprecatedField",`${o}.profile`);let s=A(i.id);if(!s)throw y("schema.invalidType",`${o}.id`);if(t.has(s))throw y("schema.invalidValue",`${o}.id`);t.add(s);let a=A(i.guid);if(a){if(n.has(a))throw y("schema.invalidValue",`${o}.guid`);n.add(a)}if(!A(i.name))throw y("schema.invalidType",`${o}.name`);let c=A(i.shaderId);if(!c)throw y("schema.invalidValue",`${o}.shaderId`);let d=on(c),u=i.definitionVersion;if(u!=null&&(typeof u!="number"||!Number.isSafeInteger(u)||u<1))throw y("schema.invalidValue",`${o}.definitionVersion`);if(!d&&u==null)throw y("schema.invalidValue",`${o}.definitionVersion`);if(d){let l=sn(c,i.properties,`${o}.properties`);if(l[0])throw y("schema.invalidValue",l[0].path)}else if(!I(i.properties))throw y("schema.invalidType",`${o}.properties`);for(let l of Object.keys(i))if(!["id","guid","name","shaderId","definitionVersion","properties","system","origin"].includes(l))throw y("schema.unknownField",`${o}.${l}`)}}function Qc(e,t){let n=new Set(e.map(I).filter(o=>o?.type==="glb").map(o=>A(o?.id)).filter(o=>!!o)),r=new Set(e.map(I).filter(o=>o?.type==="texture").map(o=>A(o?.id)).filter(o=>!!o)),i=new Map;for(let o of e.map(I)){if(o?.type!=="prefab")continue;let s=A(o.id),a=A(I(o.prefab)?.sourceAssetId);s&&a&&i.set(s,a)}for(let o=0;o<e.length;o+=1){let s=I(e[o]);if(s?.type!=="prefab")continue;let a=I(s.prefab),c=A(a?.sourceAssetId),d=A(a?.rootNodeId);if(!c||!n.has(c))throw y("schema.invalidReference",`$.assets[${o}].prefab.sourceAssetId`);let u=Array.isArray(a?.nodes)?a.nodes:[];for(let l=0;l<u.length;l+=1){let f=I(u[l]),g=A(f?.sourceAssetId);if(f?.kind==="model"&&(!g||!n.has(g)))throw y("schema.invalidReference",`$.assets[${o}].prefab.nodes[${l}].sourceAssetId`);if(f?.kind==="prefabInstance"){let p=A(f.childPrefabId),h=p?i.get(p):null;if(A(f.id)===d&&c!==h)throw y("schema.invalidReference",`$.assets[${o}].prefab.sourceAssetId`);if(g&&g!==h)throw y("schema.invalidReference",`$.assets[${o}].prefab.nodes[${l}].sourceAssetId`)}}}for(let o=0;o<t.length;o+=1){let s=I(t[o]),a=A(I(s?.instance)?.assetId);if(a&&!n.has(a))throw y("schema.invalidReference",`$.scene.gameObjects[${o}].instance.assetId`);let c=Array.isArray(s?.components)?s.components:[];for(let d=0;d<c.length;d+=1){let u=I(c[d]);if(u?.type!=="ModelRenderer")continue;let l=A(u.assetId);if(!l||!n.has(l))throw y("schema.invalidReference",`$.scene.gameObjects[${o}].components[${d}].assetId`)}for(let d=0;d<c.length;d+=1){let u=I(c[d]);if(u?.type!=="ImageRenderer")continue;let l=A(u.assetId);if(!l||!r.has(l))throw y("schema.invalidReference",`$.scene.gameObjects[${o}].components[${d}].assetId`);let f=I(u.size);if(!f||!uo(f.width)||!uo(f.height))throw y("schema.invalidValue",`$.scene.gameObjects[${o}].components[${d}].size`)}}}function el(e,t){let n=new Set;e.forEach((o,s)=>{let a=I(o);if(!a)throw y("schema.invalidType",`$.assets[${s}]`);let c=A(a.id);if(!c||!A(a.type))throw y("schema.invalidValue",`$.assets[${s}]`);if(n.has(c))throw y("schema.invalidValue",`$.assets[${s}].id`);n.add(c)});let r=new Set,i=new Map;t.forEach((o,s)=>{let a=I(o);if(!a)throw y("schema.invalidType",`$.scene.gameObjects[${s}]`);let c=A(a.id);if(!c)throw y("schema.invalidValue",`$.scene.gameObjects[${s}].id`);if(r.has(c))throw y("schema.invalidValue",`$.scene.gameObjects[${s}].id`);if(r.add(c),i.set(c,{value:a,index:s}),!Array.isArray(a.components))throw y("schema.invalidType",`$.scene.gameObjects[${s}].components`);a.components.forEach((d,u)=>{let l=I(d);if(!l)throw y("schema.invalidType",`$.scene.gameObjects[${s}].components[${u}]`);if(!A(l.type))throw y("schema.invalidValue",`$.scene.gameObjects[${s}].components[${u}].type`)})});for(let[o,s]of i){if(!("parentId"in s.value))continue;let a=A(s.value.parentId);if(!a||!i.has(a))throw y("schema.invalidReference",`$.scene.gameObjects[${s.index}].parentId`);let c=new Set([o]),d=a;for(;d;){if(c.has(d))throw y("schema.invalidReference",`$.scene.gameObjects[${s.index}].parentId`);c.add(d);let u=i.get(d)?.value;d=u&&u.parentId!=null?A(u.parentId):null}}}function dr(e,t){if(Array.isArray(e)){e.forEach((r,i)=>dr(r,`${t}[${i}]`));return}let n=I(e);if(n)for(let[r,i]of Object.entries(n)){let o=`${t}.${r}`;if(Wc.has(r))throw y("schema.deprecatedField",o);r==="shadow"&&pt(i,o),!(r==="metadata"||r==="shadowMapExperiment")&&dr(i,o)}}function tl(e){let t=new Set(e.map(I).filter(s=>s?.type==="prefab").map(s=>A(s?.id)).filter(s=>!!s)),n=new Map;for(let s=0;s<e.length;s+=1){let a=I(e[s]);if(a?.type!=="prefab")continue;let c=I(a.prefab);if(!Array.isArray(c?.nodes))throw y("schema.unsupportedVersion",`$.assets[${s}].prefab.nodes`);co(c.defaults,`$.assets[${s}].prefab.defaults`);let d=[],u=new Set;for(let p=0;p<c.nodes.length;p+=1){let h=`$.assets[${s}].prefab.nodes[${p}]`,S=I(c.nodes[p]);if(!S)throw y("schema.invalidType",h);co(S.defaults,`${h}.defaults`);let P=A(S.id);if(!P||!so.has(String(S.kind)))throw y("schema.invalidValue",h);if(u.has(P))throw y("schema.invalidValue",`${h}.id`);u.add(P),d.push(S)}let l=A(c?.rootNodeId),f=l?d.find(p=>A(p?.id)===l):null,g=!!f&&so.has(String(f.kind))&&!Object.prototype.hasOwnProperty.call(f,"parentId");if(c?.compositionVersion!==ln||d.length===0||!g)throw y("schema.unsupportedVersion",`$.assets[${s}].prefab`);n.set(A(a.id),d.flatMap((p,h)=>{let S=A(p.childPrefabId);return S?[{prefabId:S,path:`$.assets[${s}].prefab.nodes[${h}].childPrefabId`}]:[]}));for(let p=0;p<d.length;p+=1){let h=d[p];Ki(h,new Map(d.map($=>[A($.id),$])),`$.assets[${s}].prefab.nodes[${p}]`);let S=A(h.id),P=A(h.parentId);if(S!==l&&(!P||!u.has(P)))throw y("schema.invalidReference",`$.assets[${s}].prefab.nodes[${p}].parentId`);if(h.kind==="prefabInstance"){let $=A(h.childPrefabId);if(!$||!t.has($))throw y("schema.invalidReference",`$.assets[${s}].prefab.nodes[${p}].childPrefabId`)}let D=new Set([S]),T=P;for(;T;){if(D.has(T))throw y("schema.invalidReference",`$.assets[${s}].prefab.nodes[${p}].parentId`);D.add(T);let $=d.find(_=>A(_.id)===T);T=$?A($.parentId):null}}}let r=new Set,i=new Set,o=s=>{if(!i.has(s)){r.add(s);for(let a of n.get(s)??[]){if(r.has(a.prefabId))throw y("schema.invalidReference",a.path);o(a.prefabId)}r.delete(s),i.add(s)}};for(let s of n.keys())o(s)}function co(e,t){if(e==null)return;let n=I(e);if(!n)throw y("schema.invalidType",t);if(Object.prototype.hasOwnProperty.call(n,"active")&&typeof n.active!="boolean")throw y("schema.invalidType",`${t}.active`)}function nl(e,t){let n=new Map;for(let r of t.map(I)){if(r?.type!=="prefab")continue;let i=A(r.id),o=A(I(r.prefab)?.sourceAssetId);i&&o&&n.set(i,o)}for(let r=0;r<e.length;r+=1){let i=I(e[r]);if(!i||i.prefab==null)continue;let o=I(i.prefab),s=A(o?.prefabId),a=s?n.get(s):null;if(!s||!a)throw y("schema.unsupportedVersion",`$.scene.gameObjects[${r}].prefab`);if(A(o?.sourceAssetId)!==a)throw y("schema.invalidReference",`$.scene.gameObjects[${r}].prefab.sourceAssetId`);let c=A(I(i.instance)?.assetId);if(c&&c!==a)throw y("schema.invalidReference",`$.scene.gameObjects[${r}].instance.assetId`);let d=Array.isArray(i.components)?i.components:[];for(let u=0;u<d.length;u+=1){let l=I(d[u]);if(l?.type==="ModelRenderer"&&A(l.assetId)!==a)throw y("schema.invalidReference",`$.scene.gameObjects[${r}].components[${u}].assetId`)}}}function rl(e){for(let t=0;t<e.length;t+=1){let n=I(I(I(e[t])?.marker)?.geometry);if(n?.kind!=="box")continue;for(let i of qc)if(Object.prototype.hasOwnProperty.call(n,i))throw y("schema.deprecatedField",`$.scene.gameObjects[${t}].marker.geometry.${i}`);if(!(Array.isArray(I(e[t])?.components)?I(e[t]).components:[]).some(i=>I(i)?.type==="Transform"))throw y("schema.invalidValue",`$.scene.gameObjects[${t}].components`)}}function il(e,t){let n=new Map,r=new Map;for(let i=0;i<e.length;i+=1){let o=I(e[i]),s=A(o?.id);if(!o||!s)continue;if(o.type==="prefab"){let l=A(I(o.prefab)?.sourceAssetId);l&&r.set(s,l)}let a=I(o.metadata),c=a?.materialSlots;if(c==null){n.set(s,new Set);continue}if(!Array.isArray(c))throw y("schema.invalidType",`$.assets[${i}].metadata.materialSlots`);let d=ol(a?.assetAnalysis),u=new Set;for(let l=0;l<c.length;l+=1){let f=I(c[l]),g=A(f?.slotId);if(!f||!g)throw y("schema.invalidValue",`$.assets[${i}].metadata.materialSlots[${l}]`);let p=`$.assets[${i}].metadata.materialSlots[${l}]`;for(let h of["ownerNodePath","nodeIndex","nodeIndexPath","meshIndex","primitiveIndex","sourceMaterialIndex","sourceMaterialIndices","sourceMeshName","triangleCount","boundingBox"])if(Object.prototype.hasOwnProperty.call(f,h))throw y("schema.deprecatedField",`${p}.${h}`);if(!Array.isArray(f.sourceSurfaces))throw y("schema.invalidType",`${p}.sourceSurfaces`);if(f.sourceSurfaces.length===0)throw y("schema.invalidValue",`${p}.sourceSurfaces`);for(let h=0;h<f.sourceSurfaces.length;h+=1){let S=`${p}.sourceSurfaces[${h}]`,P=I(f.sourceSurfaces[h]);if(!P||!A(P.ownerNodePath))throw y("schema.invalidValue",S);lo(P,"nodeIndex",S),lo(P,"sourceMaterialIndex",S);for(let T of["meshIndex","primitiveIndex"])if(!Number.isInteger(P[T])||P[T]<0)throw y("schema.invalidValue",`${S}.${T}`);if(P.nodeIndexPath!=null&&(!Array.isArray(P.nodeIndexPath)||P.nodeIndexPath.some(T=>!Number.isInteger(T)||T<0)))throw y("schema.invalidValue",`${S}.nodeIndexPath`);let D=P.meshIndex;if(!A(P.sourceMeshName)&&!d.has(D))throw y("schema.invalidValue",`${S}.sourceMeshName`)}if(u.has(g))throw y("schema.invalidValue",`$.assets[${i}].metadata.materialSlots[${l}].slotId`);u.add(g)}n.set(s,u)}for(let i=0;i<e.length;i+=1){let o=I(e[i]);if(o?.type!=="prefab")continue;let s=I(o.prefab),a=A(s?.sourceAssetId);sr(s?.overrides,a?n.get(a):void 0,`$.assets[${i}].prefab.overrides`);let c=Array.isArray(s?.nodes)?s.nodes:[];for(let d=0;d<c.length;d+=1){let u=I(c[d]),l=A(u?.childPrefabId),f=A(u?.sourceAssetId)??(l?r.get(l)??null:null);sr(u?.overrides,f?n.get(f):void 0,`$.assets[${i}].prefab.nodes[${d}].overrides`)}}for(let i=0;i<t.length;i+=1){let o=I(t[i]),a=(Array.isArray(o?.components)?o.components:[]).map(I).find(d=>d?.type==="ModelRenderer"),c=A(a?.assetId);sr(o?.overrides,c?n.get(c):void 0,`$.scene.gameObjects[${i}].overrides`)}}function sr(e,t,n){let r=I(e);if(!r||r.materialSlotBindings==null)return;let i=I(r.materialSlotBindings);if(!i)throw y("schema.invalidType",`${n}.materialSlotBindings`);for(let[o,s]of Object.entries(i)){if(!t?.has(o))throw y("schema.invalidReference",`${n}.materialSlotBindings.${o}`);let a=`${n}.materialSlotBindings.${o}`,c=I(s);if(!c)throw y("schema.invalidType",a);for(let d of Object.keys(c))if(d!=="materialAssetId"&&d!=="override")throw y("schema.deprecatedField",`${a}.${d}`);if("materialAssetId"in c&&c.materialAssetId!=null&&!A(c.materialAssetId))throw y("schema.invalidValue",`${a}.materialAssetId`);if("override"in c&&!I(c.override))throw y("schema.invalidType",`${a}.override`);"override"in c&&sl(c.override,`${a}.override`)}}function lo(e,t,n){let r=e[t];if(r!=null&&(!Number.isInteger(r)||r<0))throw y("schema.invalidValue",`${n}.${t}`)}function ol(e){let t=I(e),n=Array.isArray(t?.meshes)?t.meshes:[];return new Set(n.flatMap(r=>{let i=I(r),o=i?.meshIndex,s=Number.isInteger(o)?o:null;return s!=null&&A(i?.name)?[s]:[]}))}function sl(e,t){let n=I(e);if(!n)throw y("schema.invalidType",t);if(it(n,["lightingModel","baseColor","normal","metallic","roughness","metallicRoughness","occlusion","emission","alpha"],t),"lightingModel"in n&&!["lit","unlit"].includes(String(n.lightingModel)))throw y("schema.invalidValue",`${t}.lightingModel`);for(let r of["metallic","roughness"])Dt(n,r,t);al(n.baseColor,`${t}.baseColor`),ar(n.normal,`${t}.normal`,["texture","strength"]),ar(n.metallicRoughness,`${t}.metallicRoughness`,["texture"]),ar(n.occlusion,`${t}.occlusion`,["texture","strength"]),dl(n.emission,`${t}.emission`),cl(n.alpha,`${t}.alpha`)}function al(e,t){if(e==null)return;let n=ot(e,t);it(n,["color","texture","brightness","saturation","contrast","hue"],t),po(n.color,`${t}.color`),Tt(n.texture,`${t}.texture`);for(let r of["brightness","saturation","contrast","hue"])Dt(n,r,t)}function ar(e,t,n){if(e==null)return;let r=ot(e,t);it(r,n,t),Tt(r.texture,`${t}.texture`),n.includes("strength")&&Dt(r,"strength",t)}function dl(e,t){if(e==null)return;let n=ot(e,t);it(n,["color","intensity","texture","maskTexture"],t),po(n.color,`${t}.color`),Dt(n,"intensity",t),Tt(n.texture,`${t}.texture`),Tt(n.maskTexture,`${t}.maskTexture`)}function cl(e,t){if(e==null)return;let n=ot(e,t);if(it(n,["mode","opacity","cutoff","texture"],t),"mode"in n&&!["opaque","mask","blend"].includes(String(n.mode)))throw y("schema.invalidValue",`${t}.mode`);for(let r of["opacity","cutoff"])Dt(n,r,t);Tt(n.texture,`${t}.texture`)}function Tt(e,t){if(e==null)return;let n=ot(e,t);it(n,["url","textureAssetId"],t);for(let r of["url","textureAssetId"])if(r in n&&n[r]!=null&&!A(n[r]))throw y("schema.invalidValue",`${t}.${r}`)}function po(e,t){if(e==null)return;let n=ot(e,t);for(let r of["r","g","b"])ll(n,r,t)}function it(e,t,n){let r=new Set(t);for(let i of Object.keys(e))if(!r.has(i))throw y("schema.deprecatedField",`${n}.${i}`)}function Dt(e,t,n){if(t in e&&e[t]!=null&&(typeof e[t]!="number"||!Number.isFinite(e[t])))throw y("schema.invalidType",`${n}.${t}`)}function ll(e,t,n){if(!(t in e)||typeof e[t]!="number"||!Number.isFinite(e[t]))throw y("schema.invalidValue",`${n}.${t}`)}function ot(e,t){let n=I(e);if(!n)throw y("schema.invalidType",t);return n}function y(e,t){let n=new Error(`${e}: ${t}`);return Object.assign(n,{code:e,path:t}),n}function I(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function A(e){return typeof e=="string"&&e.length>0&&e===e.trim()?e:null}function uo(e){return typeof e=="number"&&Number.isFinite(e)&&e>0}function yo(e,t,n={}){let r=go(e).document,i=t;Object.prototype.hasOwnProperty.call(i,"staticShadows")&&i.staticShadows!=null&&nn(i.staticShadows,"$.staticShadows");let{scene:o,...s}=t,a=structuredClone(s),c=re(o)?o:void 0,d=Xi(r),u={...d,compilerId:fo,compilerVersion:mo,compiledAt:new Date().toISOString()};a.schemaVersion=3,a.meta={...a.meta??{},generatedFrom:u};let l=c?.rootId||"root",f=r.scene.gameObjects.filter(D=>D.id!==l),g=pl(r,n.materialShaderDefinitions,!0),p={...r,scene:{...r.scene,materialAssets:g}},h=f.flatMap(D=>Tl(D,d,p,n)),S=h.map(ho);fl(l,S),ml(l,S);let P={rootId:l,assets:p.assets.filter(hl).map(Sl),nodes:S,materialAssets:g,materials:structuredClone(c?.materials??[]),textures:structuredClone(c?.textures??[])};return a.scene=P,a.plugins=kl(a.plugins,n.shadowMapExperimentConfig,h,l,d.revision),yi(a),{sceneConfig:a,summary:{assetCount:P.assets.length,gameObjectCount:r.scene.gameObjects.length,nodeCount:P.nodes.length}}}function ho(e){if(!Object.prototype.hasOwnProperty.call(e,"shadowMapExperimentInferredUpdateClass"))return e;let{shadowMapExperimentInferredUpdateClass:t,...n}=e;return n}function fl(e,t){let n=new Set([e]);for(let r=0;r<t.length;r+=1){let i=t[r].id;if(n.has(i)){let o=new Error(`schema.invalidReference: $.scene.nodes[${r}].id`);throw Object.assign(o,{code:"schema.invalidReference",path:`$.scene.nodes[${r}].id`,nodeId:i}),o}n.add(i)}}function ml(e,t){let n=new Map(t.map(r=>[r.id,r]));for(let r=0;r<t.length;r+=1){let i=t[r];if(!(i.source?.component!=="PrefabMarker"||!("marker"in i)||!i.marker))for(let o of gl(i.marker)){let s=n.get(o.target.id);if(o.target.id!==e&&(!s||s.source?.objectId===i.source.objectId))continue;let a=`$.scene.nodes[${r}].marker.${o.path}.id`,c=new Error(`schema.invalidReference: ${a}`);throw Object.assign(c,{code:"schema.invalidReference",path:a,nodeId:i.id,targetId:o.target.id}),c}}}function gl(e){let t=[];return e.target&&t.push({path:"target",target:e.target}),e.geometry.kind==="point"&&e.geometry.target&&t.push({path:"geometry.target",target:e.geometry.target}),e.geometry.kind==="object-bounds"&&t.push({path:"geometry.target",target:e.geometry.target}),t}function pl(e,t,n=!1){let r=structuredClone(e.scene.materialAssets??[]);for(let o=0;o<r.length;o+=1){let s=r[o];if(on(s.shaderId))continue;let a=t?.get(s.shaderId);if(!a){if(!n)continue;throw cr("material.shaderDefinitionNotFound",`$.scene.materialAssets[${o}].shaderId`,`Shader Definition was not found: ${s.shaderId}`)}if(s.definitionVersion!==a.version)throw cr("material.shaderDefinitionVersionMismatch",`$.scene.materialAssets[${o}].definitionVersion`,`Material ${s.id} uses Definition v${String(s.definitionVersion)} but ${s.shaderId} is v${a.version}.`);let c=sn(s.shaderId,s.properties,`$.scene.materialAssets[${o}].properties`,t);if(c[0])throw cr("material.propertiesInvalid",c[0].path,c[0].message)}let i=dn(bl(e,r));if(!i.ok)throw new Error(`editor_scene_material_assets_missing: ${i.missingMaterialAssetIds.join(", ")}`);return r}function cr(e,t,n){return Object.assign(new Error(`${e}: ${n}`),{code:e,path:t})}function bl(e,t){let n={...e,scene:{...e.scene,materialAssets:t}};return{...n,scene:{...n.scene,gameObjects:[...n.scene.gameObjects.map(r=>{let i=To(r,n);if(i)return{...r,overrides:i};if(!("overrides"in r))return r;let o={...r};return delete o.overrides,o}),...yl(n)]}}}function yl(e){let t=[];for(let n of e.scene.gameObjects){let r=un(e,n);!r.definition||!hn(r.definition)||t.push(...So({editorDocument:e,prefabAsset:r.definition,hostGameObject:n,instanceOverrides:n.overrides,visitedPrefabIds:new Set}))}return t}function So(e){if(e.visitedPrefabIds.has(e.prefabAsset.id))return[];e.visitedPrefabIds.add(e.prefabAsset.id);let t=Ao(Et(e.prefabAsset),It(e.prefabAsset)??""),n=t.find(o=>o.id===It(e.prefabAsset));if(!n)return e.visitedPrefabIds.delete(e.prefabAsset.id),[];let r=wo(t,e.prefabAsset),i=[];for(let o of t){if(o.kind==="prefabInstance"&&o.childPrefabId){let d=e.editorDocument.assets.find(u=>u.id===o.childPrefabId);if(d&&hn(d)){i.push(...So({editorDocument:e.editorDocument,prefabAsset:d,hostGameObject:e.hostGameObject,instanceOverrides:o.overrides,visitedPrefabIds:new Set(e.visitedPrefabIds)}));continue}continue}let s=Fl(e.hostGameObject,o);if(!s)continue;let a=o.kind==="model"&&o.sourceAssetId?e.editorDocument.assets.find(d=>d.id===o.sourceAssetId):void 0,c=gr({hostGameObject:s,prefabAsset:e.prefabAsset,rootNode:n,node:o,asset:a,editorDocument:e.editorDocument,instanceOverrides:o.id===r?e.instanceOverrides:void 0});c&&i.push({...s,overrides:c})}return e.visitedPrefabIds.delete(e.prefabAsset.id),i}function hl(e){return e.type==="glb"||e.type==="texture"}function Sl(e){let t=Il(e),n=e.type==="glb"?El(e):[],r=Pl(e.external),i=xl(e.defaults);return{id:e.id,type:e.type,...e.guid?{guid:e.guid}:{},...t?{url:t}:{},...typeof e.warmupCount=="number"&&Number.isInteger(e.warmupCount)&&e.warmupCount>=0?{warmupCount:e.warmupCount}:{},...typeof e.singleton=="boolean"?{singleton:e.singleton}:{},...typeof e.materialMode=="string"?{materialMode:e.materialMode}:{},...i!==void 0?{defaults:i}:{},...r?{external:r}:{},...n.length>0?{materialSlots:n}:{}}}function xl(e){if(!e)return;let t=structuredClone(e);return re(t)?(delete t.shadowMapExperiment,Object.keys(t).length>0?t:void 0):t}function Pl(e){let t=re(e)?e:void 0,n=we(t?.platformAssetId),r=we(t?.assetUrl);if(!(!n&&!r))return{...n?{platformAssetId:n}:{},...r?{assetUrl:r}:{}}}function Il(e){let t=re(e.metadata)?e.metadata:void 0,n=re(e.external)?e.external:void 0;return we(t?.url)??we(n?.assetUrl)??void 0}function El(e){let t=re(e.metadata)?e.metadata:void 0,n=Array.isArray(t?.materialSlots)?t.materialSlots:[],r=Al(t?.assetAnalysis);return n.flatMap(i=>{if(!re(i))return[];let o=we(i.slotId);if(!o)return[];let s=we(i.label),a=(Array.isArray(i.sourceSurfaces)?i.sourceSurfaces:[]).flatMap(c=>{if(!re(c))return[];let d=we(c.ownerNodePath),u=kt(c.meshIndex),l=kt(c.primitiveIndex);if(!d||u==null||l==null)return[];let f=kt(c.nodeIndex),g=wl(Array.isArray(c.nodeIndexPath)?c.nodeIndexPath:[]),p=kt(c.sourceMaterialIndex),h=we(c.sourceMeshName)??r.get(u);return[{ownerNodePath:d,...f==null?{}:{nodeIndex:f},...g.length>0?{nodeIndexPath:g}:{},meshIndex:u,primitiveIndex:l,...p==null?{}:{sourceMaterialIndex:p},...h?{sourceMeshName:h}:{}}]});return a.length===0?[]:[{slotId:o,...s?{label:s}:{},sourceSurfaces:a}]})}function Al(e){let t=re(e)?e:void 0,n=Array.isArray(t?.meshes)?t.meshes:[];return new Map(n.flatMap(r=>{if(!re(r))return[];let i=kt(r.meshIndex),o=we(r.name);return i==null||!o?[]:[[i,o]]}))}function wl(e){return[...new Set(e.filter(t=>typeof t=="number"&&Number.isInteger(t)&&t>=0))]}function kt(e){return typeof e=="number"&&Number.isInteger(e)&&e>=0?e:void 0}function Tl(e,t,n,r){let i=un(n,e);return(i.definition&&hn(i.definition)?Cl(e,i.definition,t,n,new Set,r):[Dl(e,t,n,r)]).map(s=>{let a=s.kind==="instance"?n.assets.find(d=>d.id===s.instance.assetId):void 0,c=r.inferShadowMapExperimentUpdateClass?.({gameObject:e,runtimeNode:ho(s),...a?{asset:a}:{}})??Ml(a);return{...s,shadowMapExperimentInferredUpdateClass:c}})}function Dl(e,t,n,r={}){let i=Xn(e),o=tt(e),s=Zn(e),a=Ll(e),c=nt(e),d=To(e,n),u=Vi(e),l={sourceId:t.sourceId,sourceType:t.sourceType,revision:t.revision,...e.guid?{objectGuid:e.guid}:{},objectId:e.id,component:o?"ModelRenderer":s?"ImageRenderer":a||c==="primitive"?"PrimitiveRenderer":c==="transform"?"Transform":"GameObject"},f={id:e.id,...e.name?{name:e.name}:{},...e.parentId?{parentId:e.parentId}:{},...e.active===!1?{enabled:!1}:{},...e.shadow?{shadow:structuredClone(e.shadow)}:{},...Nl(n,e,r),...u?{rendering:u}:{},source:l,...i&&"position"in i?{transform:{position:i.position,rotation:i.rotation,...i.scale?{scale:i.scale}:{}}}:{}};if(c==="primitive")return{...f,kind:"primitive",primitive:{shape:a?.shape??"cube"},...d?{overrides:d}:{}};if(s)return{...f,kind:"image",image:{assetId:s.assetId,size:{width:s.size.width,height:s.size.height}},...d?{overrides:d}:{}};if(!o){if(c==="transform"){let g=$l(e,r),p=g.transformType;delete g.transformType;let h=bo(p)??bo(e.transformType);return{...f,kind:"transform",...h?{transformType:h}:{},...e.camera?{camera:Bl(e.camera)}:{},...e.light?{light:Do(e.light)}:{},...e.marker?{marker:{label:e.name||e.id,...structuredClone(e.marker)}}:{},...g,...d?{overrides:d}:{}}}return{...f,kind:"group"}}return{...f,kind:"instance",instance:{assetId:o.assetId},...d?{overrides:d}:{}}}function kl(e,t,n,r,i){let o=(e??[]).filter(u=>u.pluginId!==jn);if(!t)return o;let s=n.find(u=>u.id===t.lightRef),a=s?.kind==="transform"&&s.light?.type==="directional"?s:void 0;if(!s&&t.enabled)throw new Error(`shadowMapExperiment.lightMissing:${t.lightRef}`);if(s&&!a&&t.enabled)throw new Error(`shadowMapExperiment.lightUnsupported:${t.lightRef}`);let c=a?.kind==="transform"&&a.light?.type==="directional"?[a.light.direction.x,a.light.direction.y,a.light.direction.z]:[0,-1,0],d=Kr({revision:typeof i=="number"&&Number.isInteger(i)&&i>=0?i:0,scopeId:r,config:t,lightDirection:c,objects:n.filter(u=>u.kind==="instance"||u.kind==="primitive").map(u=>({entityId:u.id,renderableIds:[u.id],cast:u.shadow?.cast==="enabled",receive:u.shadow?.receive==="enabled",inferredUpdateClass:u.shadowMapExperimentInferredUpdateClass??"static"}))});return[...o,{pluginId:jn,schemaVersion:3,data:d}]}function Ml(e){let t=re(e?.metadata?.assetAnalysis)?e.metadata.assetAnalysis:void 0;if(!t)return"static";let n=lr(t.skinCount),r=lr(t.morphTargetCount);return n>0||r>0?"skinned":lr(t.animationCount)>0?"dynamic":"static"}function lr(e){return typeof e=="number"&&Number.isFinite(e)&&e>=0?e:0}function Cl(e,t,n,r,i,o){return xo({prefabAsset:t,sourceRef:n,editorDocument:r,hostGameObject:e,rootRuntimeId:e.id,rootParentId:e.parentId,rootName:e.name??t.displayName??t.id,rootTransform:Xn(e)??void 0,rootActive:e.active,instanceOverrides:e.overrides,propertyPathPrefix:`assets.${t.id}.prefab.nodes`,visitedPrefabIds:i,compilerOptions:o})}function xo(e){if(e.visitedPrefabIds.has(e.prefabAsset.id))return[ur({id:e.rootRuntimeId,name:e.rootName??e.prefabAsset.displayName??e.prefabAsset.id,parentId:e.rootParentId,transform:e.rootTransform,editorDocument:e.editorDocument,sourceRef:e.sourceRef,hostGameObject:e.hostGameObject,component:"PrefabCycle",propertyPath:e.propertyPathPrefix})];e.visitedPrefabIds.add(e.prefabAsset.id);let t=Et(e.prefabAsset),n=It(e.prefabAsset),r=n?t.find(d=>d.id===n):null;if(!r||t.length===0)return e.visitedPrefabIds.delete(e.prefabAsset.id),[ur({id:e.rootRuntimeId,name:e.rootName??e.prefabAsset.displayName??e.prefabAsset.id,parentId:e.rootParentId,transform:e.rootTransform,editorDocument:e.editorDocument,sourceRef:e.sourceRef,hostGameObject:e.hostGameObject,component:"Prefab",propertyPath:e.propertyPathPrefix})];let i={instanceId:e.rootRuntimeId,rootNodeId:r.id},o=d=>tr(i,d.id),s=Ao(t,r.id),a=wo(s,e.prefabAsset),c=[];for(let d of s){let u=o(d),l=d.id===r.id?e.rootParentId:o(t.find(f=>f.id===d.parentId)??r);if(d.kind==="prefabInstance"&&d.childPrefabId){let f=e.editorDocument.assets.find(g=>g.id===d.childPrefabId);if(f&&hn(f)){let g=d.id===r.id;c.push(...xo({prefabAsset:f,sourceRef:e.sourceRef,editorDocument:e.editorDocument,hostGameObject:e.hostGameObject,rootRuntimeId:u,rootParentId:l,rootName:g?e.rootName??d.name??f.displayName??f.id:d.name??f.displayName??f.id,rootTransform:g?e.rootTransform??d.transform:d.transform,rootActive:g?e.rootActive??d.defaults?.active??e.prefabAsset.prefab?.defaults?.active:d.defaults?.active,instanceOverrides:g?Mt(Mt(xe(e.prefabAsset.prefab?.overrides),xe(d.overrides)),xe(e.instanceOverrides)):d.overrides,propertyPathPrefix:`${e.propertyPathPrefix}.${d.id}.childPrefab.nodes`,visitedPrefabIds:new Set(e.visitedPrefabIds),compilerOptions:e.compilerOptions}));continue}c.push(ur({id:u,name:d.name??d.childPrefabId??"Prefab Instance",parentId:l,transform:d.transform,sourceRef:e.sourceRef,editorDocument:e.editorDocument,hostGameObject:e.hostGameObject,component:"UnsupportedPrefabInstance",propertyPath:`${e.propertyPathPrefix}.${d.id}`}));continue}c.push(Rl({node:d,rootNode:r,identityScope:i,prefabAsset:e.prefabAsset,runtimeId:u,parentId:l,sourceRef:e.sourceRef,editorDocument:e.editorDocument,hostGameObject:e.hostGameObject,rootRuntimeName:e.rootName,rootRuntimeTransform:e.rootTransform,rootRuntimeActive:e.rootActive,instanceOverrides:d.id===a?e.instanceOverrides:void 0,propertyPath:`${e.propertyPathPrefix}.${d.id}`,shadowFallbackMode:mr(e.compilerOptions)}))}return e.visitedPrefabIds.delete(e.prefabAsset.id),vl({compiledNodes:c,editorDocument:e.editorDocument,hostGameObject:e.hostGameObject,shadowFallbackMode:mr(e.compilerOptions)})}function Rl(e){let t=e.node.id===e.rootNode.id,n=t?e.rootRuntimeTransform??e.node.transform:e.node.transform,r=e.node.kind==="model"&&e.node.sourceAssetId?e.editorDocument.assets.find(s=>s.id===e.node.sourceAssetId):void 0,i=e.node.kind==="model"||e.node.kind==="primitive",o=Po({id:e.runtimeId,name:t?e.rootRuntimeName??e.node.name??e.prefabAsset.displayName??e.prefabAsset.id:e.node.name,parentId:e.parentId,transform:n,active:t?e.rootRuntimeActive??e.node.defaults?.active??e.prefabAsset.prefab?.defaults?.active:e.node.defaults?.active,...i?{shadow:e.prefabAsset.prefab?.defaults?.shadow}:{},editorDocument:e.editorDocument,shadowFallbackMode:e.shadowFallbackMode,sourceRef:e.sourceRef,hostGameObject:e.hostGameObject,component:e.node.kind==="model"?"PrefabModel":e.node.kind==="primitive"?"PrefabPrimitive":e.node.kind==="light"?"PrefabLight":e.node.kind==="marker"?"PrefabMarker":"PrefabNode",propertyPath:e.propertyPath});if(e.node.kind==="model"&&e.node.sourceAssetId){let s=gr({hostGameObject:e.hostGameObject,prefabAsset:e.prefabAsset,rootNode:e.rootNode,node:e.node,asset:r,editorDocument:e.editorDocument,instanceOverrides:e.instanceOverrides});return{...o,kind:"instance",instance:{assetId:e.node.sourceAssetId},...s?{overrides:s}:{}}}if(e.node.kind==="primitive"){let s=gr({hostGameObject:e.hostGameObject,prefabAsset:e.prefabAsset,rootNode:e.rootNode,node:e.node,asset:void 0,editorDocument:e.editorDocument,instanceOverrides:e.instanceOverrides});return{...o,kind:"primitive",primitive:{shape:e.node.primitive?.shape??"cube"},...s?{overrides:s}:{}}}return e.node.kind==="light"?{...o,kind:"transform",transformType:"light",...e.node.light?{light:Do(e.node.light)}:{}}:e.node.kind==="marker"&&e.node.marker?{...o,kind:"transform",marker:{label:e.node.name??e.node.id,...Hi(e.node.marker,e.identityScope)}}:{...o,kind:"group"}}function ur(e){return{...Po({id:e.id,name:e.name,parentId:e.parentId,transform:e.transform,editorDocument:e.editorDocument,shadowFallbackMode:e.shadowFallbackMode,sourceRef:e.sourceRef,hostGameObject:e.hostGameObject,component:e.component,propertyPath:e.propertyPath}),kind:"group"}}function $l(e,t){let n=t.readCustomTransformRuntimeData?.(e);return n&&typeof n=="object"&&!Array.isArray(n)?structuredClone(n):{}}function Po(e){return{id:e.id,...e.name?{name:e.name}:{},...e.parentId?{parentId:e.parentId}:{},...e.active===!1?{enabled:!1}:{},...e.shadow?{shadow:structuredClone(e.shadow)}:{},...Ol(e),source:{sourceId:e.sourceRef.sourceId,sourceType:e.sourceRef.sourceType,revision:e.sourceRef.revision,...e.hostGameObject.guid?{objectGuid:e.hostGameObject.guid}:{},objectId:e.hostGameObject.id,component:e.component,propertyPath:e.propertyPath},...e.transform&&"position"in e.transform?{transform:{position:e.transform.position,rotation:e.transform.rotation,...e.transform.scale?{scale:e.transform.scale}:{}}}:{}}}function Nl(e,t,n){let r=mn({document:e,casterId:t.id,caster:t,fallbackMode:mr(n)});return pr(r,!!t.shadow)?{shadowPlan:r}:{}}function Ol(e){if(!e.editorDocument)return{};let t=De(e.shadow),n=!!e.shadow||!!t.shadow;if(!n&&t.diagnostics.length===0)return{};let r=mn({document:e.editorDocument,casterId:e.hostGameObject.id,caster:e.hostGameObject,resolvedSettings:t.shadow,fallbackMode:e.shadowFallbackMode}),i={...r,casterId:e.id,diagnostics:[...t.diagnostics,...r.diagnostics].map(o=>({...o,casterId:o.casterId===e.hostGameObject.id||!o.casterId?e.id:o.casterId}))};return pr(i,n)?{shadowPlan:i}:{}}function pr(e,t){return t||e.backend!=="none"||e.diagnostics.length>0}function vl(e){if(e.compiledNodes.length===0)return e.compiledNodes;let t=new Set(e.compiledNodes.map(s=>s.id)),n=e.compiledNodes.map(s=>Gl(s)),r={...e.editorDocument,scene:{...e.editorDocument.scene,gameObjects:[...e.editorDocument.scene.gameObjects.filter(s=>!t.has(s.id)),...n]}},i=e.compiledNodes.filter(s=>s.shadow?.receive==="enabled").map(s=>s.id),o=n.find(s=>s.light?.type==="directional"&&s.active!==!1)?.id;return e.compiledNodes.map((s,a)=>{let c=n[a],d=mn({document:r,casterId:s.id,caster:c,explicitReceiverIds:i,...o?{defaultLightId:o}:{},fallbackMode:e.shadowFallbackMode}),u=!!s.shadow;if(!pr(d,u)){if(!s.shadowPlan)return s;let l={...s};return delete l.shadowPlan,l}return{...s,shadowPlan:d}})}function mr(e){let t=Xt(e.renderingProfile).shadows,n=t.planar.enabled?"planar":t.blob.enabled?"blob":t.staticProjected.enabled?"static":t.enabled?"dynamic":"none";return n==="planar"?"projected":n}function Gl(e){let t=[];return e.transform&&t.push({type:"Transform",position:e.transform.position,rotation:e.transform.rotation,...e.transform.scale?{scale:e.transform.scale}:{}}),e.kind==="instance"&&t.push({type:"ModelRenderer",assetId:e.instance.assetId}),e.kind==="image"&&t.push({type:"ImageRenderer",assetId:e.image.assetId,size:structuredClone(e.image.size)}),{id:e.id,...e.name?{name:e.name}:{},kind:e.kind==="image"?"transform":e.kind,...e.parentId?{parentId:e.parentId}:{},...e.enabled===!1?{active:!1}:{},...e.shadow?{shadow:{cast:e.shadow.cast==="enabled"?"enabled":"none",receive:e.shadow.receive==="enabled"?"enabled":"none"}}:{},...e.kind==="primitive"?{primitive:{shape:e.primitive.shape}}:{},...e.kind==="transform"&&e.transformType?{transformType:e.transformType}:{},...e.kind==="transform"&&e.light?{light:e.light}:{},...e.kind==="transform"&&e.camera?{camera:e.camera}:{},...e.kind==="transform"&&e.marker?{marker:structuredClone(e.marker)}:{},components:t}}function gr(e){let t=e.node.kind==="model"&&e.node.sourceAssetId?Eo(e.hostGameObject,e.node,e.node.sourceAssetId):e.hostGameObject,n=e.asset?.id,r=_l([fr(xe(e.prefabAsset.prefab?.overrides),e.prefabAsset.prefab?.sourceAssetId,e.asset),fr(xe(e.rootNode.overrides),e.rootNode.kind==="model"?e.rootNode.sourceAssetId:e.prefabAsset.prefab?.sourceAssetId,e.asset),e.node.id===e.rootNode.id?void 0:fr(xe(e.node.overrides),e.node.kind==="model"?e.node.sourceAssetId:n,e.asset)]),i=xe(e.instanceOverrides);return Io(Mt(r,i),e.asset)}function fr(e,t,n){return Io(e,t&&t===n?.id?n:void 0)}function Io(e,t){if(!e?.materialSlotBindings)return e;let n=re(t?.metadata)&&Array.isArray(t.metadata.materialSlots)?t.metadata.materialSlots:[],r=new Set(n.flatMap(s=>{let a=re(s)&&typeof s.slotId=="string"?s.slotId.trim():"";return a?[a]:[]})),i=Object.fromEntries(Object.entries(e.materialSlotBindings).filter(([s])=>r.has(s))),o=structuredClone(e);return Object.keys(i).length>0?o.materialSlotBindings=i:delete o.materialSlotBindings,Object.keys(o).length>0?o:void 0}function Eo(e,t,n){return{id:`${e.id}:${t.id}`,...t.name?{name:t.name}:{},kind:"instance",components:[...t.transform?[t.transform]:[],{type:"ModelRenderer",assetId:n}]}}function jl(e,t){return{id:`${e.id}:${t.id}`,...t.name?{name:t.name}:{},kind:"primitive",primitive:{shape:t.primitive?.shape??"cube"},components:[...t.transform?[t.transform]:[]]}}function Fl(e,t){return t.kind==="model"&&t.sourceAssetId?Eo(e,t,t.sourceAssetId):t.kind==="primitive"?jl(e,t):null}function _l(e){let t;for(let n of e){let r=xe(n);r&&(t=Mt(t,r))}return t}function Ao(e,t){let n=new Map;for(let a of e){if(!a.parentId)continue;let c=n.get(a.parentId)??[];c.push(a),n.set(a.parentId,c)}let r=[],i=new Set,o=a=>{if(!i.has(a.id)){i.add(a.id),r.push(a);for(let c of n.get(a.id)??[])o(c)}},s=e.find(a=>a.id===t);s&&o(s);for(let a of e)o(a);return r}function wo(e,t){let n=t.prefab?.sourceAssetId;return e.find(r=>r.kind==="model"&&r.sourceAssetId===n)?.id??e.find(r=>r.kind==="model")?.id}function hn(e){return cn(e)&&e.prefab.compositionVersion===ln&&Array.isArray(e.prefab.nodes)&&e.prefab.nodes.length>0&&!!It(e)}function Ll(e){return e.primitive??null}function To(e,t){let n=nt(e);if(n!=="instance"&&n!=="transform"&&n!=="primitive")return;let r=tt(e),i=r?t.assets.find(o=>o.id===r.assetId):void 0;return zl(e,t,i)}function zl(e,t,n){let r=xe(e.overrides),i=un(t,e),o=xe(i.definition?.prefab?.overrides);return Mt(o,r)}function Mt(e,t){let n=Bi(e,t);for(let r of[e,t])if(r)for(let[i,o]of Object.entries(r))Ul(i)||o===void 0||(n??={},n[i]=structuredClone(o));return n&&Object.keys(n).length>0?n:void 0}function xe(e){if(!re(e))return;let t=structuredClone(e);return Object.keys(t).length>0?t:void 0}function Ul(e){return e==="materialBinding"||e==="materialSlotBindings"}function re(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function we(e){return(typeof e=="string"?e.trim():"")||void 0}function bo(e){return typeof e=="string"?e:void 0}function Bl(e){let t=structuredClone(e);return delete t.inspectorLanguage,t}function Do(e){return e.type==="directional"?qe({schemaVersion:1,type:"directional",intensity:e.intensity,direction:ft(e.direction),diffuseColor:e.diffuseColor??Qi.diffuseColor}):qe({schemaVersion:1,type:"hemispheric",intensity:e.intensity,diffuseColor:e.diffuseColor??rr.diffuseColor,groundColor:e.groundColor??rr.groundColor})}function Vl(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function ko(e){let t=Vl(e);if(t==null)return null;let n=t%360;n>180&&(n-=360),n<=-180&&(n+=360);let r=Kl(n);return Object.is(r,-0)?0:r}function Kl(e){return Math.round(e*1e3)/1e3}var Hl=new Set(["leftToRight","rightToLeft","bottomToTop","topToBottom"]);function Ro(e){let t=Ii(e),n={uiKind:e.uiKind,size:{width:e.size.width,depth:e.size.depth},layers:e.layers.map((r,i)=>Wl(r,i)),rendering:{textureWidth:t.width,textureHeight:t.height}};return e.aspectSourceLayerId&&(n.aspectSourceLayerId=e.aspectSourceLayerId),typeof e.lockAspectToBorder=="boolean"&&(n.lockAspectToBorder=e.lockAspectToBorder),e.mask&&(n.mask={...typeof e.mask.enabled=="boolean"?{enabled:e.mask.enabled}:{},...e.mask.source==="roundedRect"||e.mask.source==="borderAlpha"||e.mask.source==="texture"?{source:e.mask.source}:{},...e.mask.textureId?{textureId:e.mask.textureId}:{},...typeof e.mask.cornerRadius=="number"&&Number.isFinite(e.mask.cornerRadius)?{cornerRadius:e.mask.cornerRadius}:{},...typeof e.mask.padding=="number"&&Number.isFinite(e.mask.padding)?{padding:e.mask.padding}:{}}),e.rendering&&(n.rendering={...n.rendering,...typeof e.rendering.alphaIndex=="number"&&Number.isFinite(e.rendering.alphaIndex)?{alphaIndex:e.rendering.alphaIndex}:{},...typeof e.rendering.diffuseTextureLevel=="number"&&Number.isFinite(e.rendering.diffuseTextureLevel)?{diffuseTextureLevel:e.rendering.diffuseTextureLevel}:{},...typeof e.rendering.emissiveTextureLevel=="number"&&Number.isFinite(e.rendering.emissiveTextureLevel)?{emissiveTextureLevel:e.rendering.emissiveTextureLevel}:{}}),n}function Wl(e,t){let n=ko(e.rotationDeg??0)??0,r={id:e.id,role:e.role,zOrder:typeof e.zOrder=="number"&&Number.isFinite(e.zOrder)?e.zOrder:t,rect:ql(e.rect),...n!==0?{rotationDeg:n}:{},...typeof e.enabled=="boolean"?{enabled:e.enabled}:{},...typeof e.opacity=="number"&&Number.isFinite(e.opacity)?{opacity:e.opacity}:{}};return e.kind==="texture"?{...r,kind:"texture",...e.textureId?{textureId:e.textureId}:{},...e.tint?{tint:st(e.tint)}:{},...e.imageFit?{imageFit:e.imageFit}:{}}:e.kind==="textureProgress"?{...r,kind:"textureProgress",...e.textureId?{textureId:e.textureId}:{},value:Co(e.value),...e.tint?{tint:st(e.tint)}:{},...e.imageFit?{imageFit:e.imageFit}:{},...Mo(e.direction)?{direction:e.direction}:{}}:e.kind==="color"?{...r,kind:"color",color:st(e.color)}:e.kind==="progress"?{...r,kind:"progress",value:Co(e.value??0),color:st(e.color),...Mo(e.direction)?{direction:e.direction}:{}}:{...r,kind:"text",text:{value:e.text.value,color:st(e.text.color),...e.text.fontFamily?{fontFamily:e.text.fontFamily}:{},...typeof e.text.fontSize=="number"&&Number.isFinite(e.text.fontSize)?{fontSize:e.text.fontSize}:{},...e.text.fontWeight!=null?{fontWeight:String(e.text.fontWeight)}:{},...e.text.strokeColor?{strokeColor:st(e.text.strokeColor)}:{},...typeof e.text.strokeWidth=="number"&&Number.isFinite(e.text.strokeWidth)?{strokeWidth:e.text.strokeWidth}:{},...e.text.align==="left"||e.text.align==="center"||e.text.align==="right"?{align:e.text.align}:{},...e.text.baseline==="top"||e.text.baseline==="middle"||e.text.baseline==="bottom"?{baseline:e.text.baseline}:{}}}}function ql(e){return{x:e.x,z:e.z,width:e.width,depth:e.depth}}function st(e){return{r:e.r,g:e.g,b:e.b,...typeof e.a=="number"?{a:e.a}:{}}}function Mo(e){return typeof e=="string"&&Hl.has(e)}function Co(e){return Number.isFinite(e)?Math.max(0,Math.min(1,e)):0}var $o=["model","texture","image","sound"],br=[".glb",".gltf"],No=[".png",".jpg",".jpeg",".webp"],Jl=[".env",".hdr",".dds",".ktx",".ktx2"],yr=[...No,...Jl],hr=[".mp3",".wav",".ogg",".flac",".aac",".m4a"],Ct=[...br,...yr,...hr];function Xl(e){return String(e??"").trim().toLowerCase().replace(/-/g,"")}function Sr(e,t){let n=Xl(t);return`${e==="model"?"asset":e==="texture"?"texture":e==="sound"?"sound":"image"}_${n}`}function xr(e){let i=String(e??"").trim().split(/[^a-zA-Z0-9_$]+/).filter(Boolean).map((o,s)=>s===0?o:`${o.charAt(0).toUpperCase()}${o.slice(1)}`).join("").replace(/[^a-zA-Z0-9_$]/g,"")||"assetUrl";return/^[a-zA-Z_$]/.test(i)?i:`asset${i}`}function Pr(e,t=""){let n=String(e??"").trim().toLowerCase();if(n==="glb"||n==="gltf"||n==="model")return"model";if(n==="groundtexture"||n==="ground-texture"||n==="texture")return"texture";if(n==="ui"||n==="image"||n==="img")return"image";if(n==="audio"||n==="sound")return"sound";let r=Zl(t);return br.includes(r)?"model":hr.includes(r)?"sound":yr.includes(r)?"texture":null}function Zl(e){let t=e.split(/[?#]/,1)[0]??"",n=Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\")),r=t.slice(n+1),i=r.lastIndexOf(".");return i>=0?r.slice(i).toLowerCase():""}function Oo(e){let t=String(e??"").trim(),n=t.toLowerCase();for(let r of[...Ct].sort((i,o)=>o.length-i.length))if(n.endsWith(r)){t=t.slice(0,-r.length);break}return t}function vo(e,t){return String(e??"").trim()||Oo(t)||"Asset"}function Go(e,t){return Oo(e||t).trim().toLowerCase().normalize("NFKD").replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"").replace(/_{2,}/g,"_")||null}function jo(e){return e==="model"?br:e==="sound"?hr:e==="texture"?yr:e==="image"?No:[]}function Sn(e,t={}){let n=t.generatedBy??"scripts/register-asset.mjs",r=t.codeKeyPolicy??"legacy",i=e.filter(d=>d.codeKey);if(r==="disabled"&&i.length>0){let d=i[0];throw Object.assign(new Error("manifest_code_key_disabled"),{name:"PlayableEditorAssetCatalogGenerationError",details:{codeKeyPolicy:r,assetId:d.assetId,codeKey:d.codeKey}})}let o=e.map(d=>`import ${xr(d.assetId)} from ${JSON.stringify(`${d.relativePath}?url`)};`).join(`
|
|
2
|
+
import jr from"node:fs/promises";import ie from"node:path";import{pathToFileURL as sf}from"node:url";var _t=class extends Error{path;reason;code="runtime.lighting.invalid";constructor(t,n){super(`Invalid Runtime Lighting data at ${t}: ${n}`),this.path=t,this.reason=n,this.name="FpsRuntimeLightingDataError"}},Lr=1e-6,ks=1e-4,Ms=new Set(["schemaVersion","type","intensity","direction","diffuseColor"]),Cs=new Set(["schemaVersion","type","intensity","diffuseColor","groundColor"]),Rs=new Set(["x","y","z"]),$s=new Set(["r","g","b"]);function ft(e,t="$.direction"){let n=zr(e,t),r=Math.hypot(n.x,n.y,n.z);return r<=Lr&&le(t,"expected a non-zero direction vector"),Object.freeze({x:n.x/r,y:n.y/r,z:n.z/r})}function qe(e,t="$.light"){let n=kn(e,t);n.schemaVersion!==1&&le(`${t}.schemaVersion`,"expected 1");let r=Ns(n.intensity,`${t}.intensity`);if(n.type==="directional"){Lt(n,Ms,t);let i=zr(n.direction,`${t}.direction`),o=Math.hypot(i.x,i.y,i.z);return o<=Lr&&le(`${t}.direction`,"expected a non-zero direction vector"),Math.abs(o-1)>ks&&le(`${t}.direction`,"expected a normalized direction vector"),Object.freeze({schemaVersion:1,type:"directional",intensity:r,direction:i,diffuseColor:Tn(n.diffuseColor,`${t}.diffuseColor`)})}if(n.type==="hemispheric")return Lt(n,Cs,t),Object.freeze({schemaVersion:1,type:"hemispheric",intensity:r,diffuseColor:Tn(n.diffuseColor,`${t}.diffuseColor`),groundColor:Tn(n.groundColor,`${t}.groundColor`)});le(`${t}.type`,"expected directional or hemispheric")}function zr(e,t){let n=kn(e,t);return Lt(n,Rs,t),Object.freeze({x:ut(n.x,`${t}.x`),y:ut(n.y,`${t}.y`),z:ut(n.z,`${t}.z`)})}function Tn(e,t){let n=kn(e,t);return Lt(n,$s,t),Object.freeze({r:Dn(n.r,`${t}.r`),g:Dn(n.g,`${t}.g`),b:Dn(n.b,`${t}.b`)})}function kn(e,t){(!e||typeof e!="object"||Array.isArray(e))&&le(t,"expected a plain object");let n=Object.getPrototypeOf(e);return n!==Object.prototype&&n!==null&&le(t,"expected a plain object"),e}function Lt(e,t,n){for(let r of Object.keys(e))t.has(r)||le(`${n}.${r}`,"unknown field")}function ut(e,t){return(typeof e!="number"||!Number.isFinite(e))&&le(t,"expected a finite number"),e}function Ns(e,t){let n=ut(e,t);return n<0&&le(t,"expected a non-negative number"),n}function Dn(e,t){let n=ut(e,t);return(n<0||n>1)&&le(t,"expected a number between 0 and 1"),n}function le(e,t){throw new _t(e,t)}var gt="medium",Mn={low:{opacity:.32,softness:.25,bias:.0015,normalBias:.02,maxDistance:24,resolution:512,cascadeCount:1,bakeSamples:8,blurKernel:2},medium:{opacity:.42,softness:.4,bias:.001,normalBias:.01,maxDistance:48,resolution:1024,cascadeCount:2,bakeSamples:24,blurKernel:4},high:{opacity:.5,softness:.58,bias:8e-4,normalBias:.006,maxDistance:80,resolution:2048,cascadeCount:4,bakeSamples:64,blurKernel:8},ultra:{opacity:.56,softness:.72,bias:6e-4,normalBias:.004,maxDistance:120,resolution:4096,cascadeCount:4,bakeSamples:128,blurKernel:12}};function zt(e=gt,t={}){let n=Mn[e]??Mn[gt];return{opacity:mt(t.opacity,n.opacity),softness:mt(t.softness,n.softness),bias:mt(t.bias,n.bias),normalBias:mt(t.normalBias,n.normalBias),maxDistance:mt(t.maxDistance,n.maxDistance),resolution:Gs(t.resolution,n.resolution),cascadeCount:js(t.cascadeCount,n.cascadeCount),bakeSamples:Os(t.bakeSamples,n.bakeSamples),blurKernel:vs(t.blurKernel,n.blurKernel)}}function mt(e,t){return typeof e=="number"&&Number.isFinite(e)?e:t}function Os(e,t){return typeof e=="number"&&Number.isFinite(e)&&e>0?Math.round(e):t}function vs(e,t){return typeof e=="number"&&Number.isFinite(e)&&e>=0?Math.round(e):t}function Gs(e,t){return e===512||e===1024||e===2048||e===4096?e:t}function js(e,t){return e===1||e===2||e===4?e:t}function Ut(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function Bt(e){return e==="inherit"||e==="none"||e==="enabled"||e==="auto"}function Vt(e){return e==="inherit"||e==="none"||e==="enabled"||e==="auto"}function Kt(e){return e==="inherit"||e==="none"||e==="dynamic"||e==="static"||e==="blob"||e==="projected"||e==="auto"}function Ht(e){return e==="inherit"||e==="low"||e==="medium"||e==="high"||e==="ultra"}function Wt(e){return e==="inherit"||e==="scene-main"||e==="nearest"||e==="explicit"}function Ur(e){let t=Ut(e);if(!t)return;let n={};Bt(t.cast)&&(n.cast=t.cast),Vt(t.receive)&&(n.receive=t.receive),Kt(t.mode)&&(n.mode=t.mode),Ht(t.quality)&&(n.quality=t.quality);let r=Ut(t.light);if(r){let o={};Wt(r.mode)&&(o.mode=r.mode),typeof r.lightId=="string"&&r.lightId.trim()&&(o.lightId=r.lightId.trim()),Object.keys(o).length>0&&(n.light=o)}let i=Fs(t.params);return i&&(n.params=i),Object.keys(n).length>0?n:void 0}function De(e){let t=Ur(e);return t?{shadow:t,diagnostics:[]}:{diagnostics:[]}}function Cn(e,t="none"){let n=e?.mode;return!n||n==="inherit"||n==="auto"?t:n}function Rn(e,t=gt){let n=e?.quality;return n&&n!=="inherit"?n:t}function Fs(e){let t=Ut(e);if(!t)return;let n={};return typeof t.opacity=="number"&&Number.isFinite(t.opacity)&&(n.opacity=t.opacity),typeof t.softness=="number"&&Number.isFinite(t.softness)&&(n.softness=t.softness),typeof t.bias=="number"&&Number.isFinite(t.bias)&&(n.bias=t.bias),typeof t.normalBias=="number"&&Number.isFinite(t.normalBias)&&(n.normalBias=t.normalBias),typeof t.maxDistance=="number"&&Number.isFinite(t.maxDistance)&&(n.maxDistance=t.maxDistance),(t.resolution===512||t.resolution===1024||t.resolution===2048||t.resolution===4096)&&(n.resolution=t.resolution),(t.cascadeCount===1||t.cascadeCount===2||t.cascadeCount===4)&&(n.cascadeCount=t.cascadeCount),typeof t.bakeSamples=="number"&&Number.isFinite(t.bakeSamples)&&(n.bakeSamples=t.bakeSamples),typeof t.blurKernel=="number"&&Number.isFinite(t.blurKernel)&&(n.blurKernel=t.blurKernel),Object.keys(n).length>0?n:void 0}var _s=new Set(["cast","receive","mode","quality","light","params"]),Ls=new Set(["mode","lightId"]),zs=new Set(["opacity","softness","bias","normalBias","maxDistance","resolution","cascadeCount","bakeSamples","blurKernel"]);function pt(e,t="$.shadow"){let n=Nn(e);if(!n)throw Q("schema.invalidType",t);if($n(n,_s,t),"cast"in n&&!Bt(n.cast))throw Q("schema.invalidValue",`${t}.cast`);if("receive"in n&&!Vt(n.receive))throw Q("schema.invalidValue",`${t}.receive`);if("mode"in n&&!Kt(n.mode))throw Q("schema.invalidValue",`${t}.mode`);if("quality"in n&&!Ht(n.quality))throw Q("schema.invalidValue",`${t}.quality`);"light"in n&&Us(n.light,`${t}.light`),"params"in n&&Bs(n.params,`${t}.params`)}function Us(e,t){let n=Nn(e);if(!n)throw Q("schema.invalidType",t);if($n(n,Ls,t),"mode"in n&&!Wt(n.mode))throw Q("schema.invalidValue",`${t}.mode`);if("lightId"in n&&(typeof n.lightId!="string"||!n.lightId.trim()))throw Q("schema.invalidValue",`${t}.lightId`);if(n.mode==="explicit"&&(typeof n.lightId!="string"||!n.lightId.trim()))throw Q("schema.invalidValue",`${t}.lightId`)}function Bs(e,t){let n=Nn(e);if(!n)throw Q("schema.invalidType",t);if($n(n,zs,t),Ge(n,"opacity",t,r=>r>=0&&r<=1),Ge(n,"softness",t,r=>r>=0),Ge(n,"bias",t,()=>!0),Ge(n,"normalBias",t,()=>!0),Ge(n,"maxDistance",t,r=>r>0),Ge(n,"bakeSamples",t,r=>r>0),Ge(n,"blurKernel",t,r=>r>=0),"resolution"in n&&![512,1024,2048,4096].includes(n.resolution))throw Q("schema.invalidValue",`${t}.resolution`);if("cascadeCount"in n&&![1,2,4].includes(n.cascadeCount))throw Q("schema.invalidValue",`${t}.cascadeCount`)}function Ge(e,t,n,r){if(!(t in e))return;let i=e[t];if(typeof i!="number"||!Number.isFinite(i)||!r(i))throw Q("schema.invalidValue",`${n}.${t}`)}function $n(e,t,n){for(let r of Object.keys(e))if(!t.has(r))throw Q("schema.deprecatedField",`${n}.${r}`)}function Q(e,t){let n=new Error(`${e}: ${t}`);return Object.assign(n,{code:e,path:t}),n}function Nn(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}var jn="fps.shadow-map-experiment";function Vs(e,t="$.scene.shadowMapExperiment"){let n=ue(e,t);ye(n,["qualityProfile","behaviorProfile"],t),n.qualityProfile!==void 0&&be(n.qualityProfile,`${t}.qualityProfile`),n.behaviorProfile!==void 0&&be(n.behaviorProfile,`${t}.behaviorProfile`)}function Ks(e,t="$.shadowMapExperiment"){let n=ue(e,t);ye(n,["behaviorProfile"],t),be(n.behaviorProfile,`${t}.behaviorProfile`)}function Hs(e,t="$"){let n=ue(e,t);ye(n,["schemaVersion","enabled","lightRef","defaultQualityProfile","defaultBehaviorProfile","qualityProfiles","behaviorProfiles"],t),n.schemaVersion!==1&&N(`${t}.schemaVersion`,"expected 1"),typeof n.enabled!="boolean"&&N(`${t}.enabled`,"expected boolean"),be(n.lightRef,`${t}.lightRef`);let r=be(n.defaultQualityProfile,`${t}.defaultQualityProfile`),i=be(n.defaultBehaviorProfile,`${t}.defaultBehaviorProfile`),o=Vr(n.qualityProfiles,`${t}.qualityProfiles`),s=Vr(n.behaviorProfiles,`${t}.behaviorProfiles`);for(let[a,c]of Object.entries(o))qs(c,`${t}.qualityProfiles.${a}`);for(let[a,c]of Object.entries(s))Js(c,`${t}.behaviorProfiles.${a}`);Object.prototype.hasOwnProperty.call(o,r)||N(`${t}.defaultQualityProfile`,`unknown quality profile: ${r}`),Object.prototype.hasOwnProperty.call(s,i)||N(`${t}.defaultBehaviorProfile`,`unknown behavior profile: ${i}`)}function Kr(e){Hs(e.config),e.settings!==void 0&&Vs(e.settings),(!Number.isInteger(e.revision)||e.revision<0)&&N("$.revision","expected a non-negative integer");let t=e.settings?.qualityProfile??e.config.defaultQualityProfile,n=e.settings?.behaviorProfile??e.config.defaultBehaviorProfile,r=vn(e.config.qualityProfiles,t,"$.settings.qualityProfile","quality");vn(e.config.behaviorProfiles,n,"$.settings.behaviorProfile","behavior");let i=e.objects.map((a,c)=>{let d=`$.objects[${c}]`;a.override!==void 0&&Ks(a.override,`${d}.override`);let u=a.override?.behaviorProfile??n,l=vn(e.config.behaviorProfiles,u,`${d}.override.behaviorProfile`,"behavior");return Object.freeze({entityId:be(a.entityId,`${d}.entityId`),renderableIds:Object.freeze(ra(a.renderableIds,`${d}.renderableIds`)),cast:Br(a.cast,`${d}.cast`)??l.cast==="enabled",receive:Br(a.receive,`${d}.receive`)??l.receive==="enabled",updateClass:l.updateClass!=="auto"?l.updateClass:a.inferredUpdateClass??"static",behaviorProfileId:u})}).sort((a,c)=>a.entityId.localeCompare(c.entityId)),o=e.config.enabled?i:[];ta(o);let s=Object.fromEntries(Object.entries(e.config.behaviorProfiles).sort(([a],[c])=>a.localeCompare(c)).map(([a,c])=>[a,Object.freeze({cast:c.cast==="enabled",receive:c.receive==="enabled",updateClass:c.updateClass})]));return Hr({schemaVersion:3,revision:e.revision,enabled:e.config.enabled,scopeId:be(e.scopeId,"$.scopeId"),light:{entityId:e.config.lightRef,direction:yt(e.lightDirection,"$.lightDirection")},qualityProfileId:t,generator:{maps:{...r.maps},...r.cascadeCount===void 0?{}:{cascadeCount:r.cascadeCount},filter:r.receiverFilter,bias:r.bias,normalBias:r.normalBias,darkness:r.darkness,...r.softness===void 0?{}:{softness:r.softness},bounds:na(r.bounds),backend:{...r.backend}},culling:{...r.culling},diagnosticThresholds:{...r.diagnostics},behaviorProfiles:s,objects:o,diagnostics:[]})}function Br(e,t){if(e!==void 0)return typeof e!="boolean"&&N(t,"expected a boolean"),e}function Ws(e,t){let n=ue(e,t);ye(n,["mode","center","extent","near","far"],t),n.mode!=="fixed"&&N(`${t}.mode`,"expected fixed"),yt(n.center,`${t}.center`),yt(n.extent,`${t}.extent`).some(s=>s<=0)&&N(`${t}.extent`,"expected positive values");let i=qt(n.near,`${t}.near`),o=qt(n.far,`${t}.far`);(i<0||o<=i)&&N(t,"expected 0 <= near < far")}function qs(e,t){let n=ue(e,t);ye(n,["maps","cascadeCount","receiverFilter","bias","normalBias","darkness","softness","bounds","backend","culling","diagnostics"],t),Xs(n.maps,`${t}.maps`),n.cascadeCount!==void 0&&Zs(n.cascadeCount,`${t}.cascadeCount`),n.receiverFilter!=="hard"&&n.receiverFilter!=="low-pcf"&&N(`${t}.receiverFilter`,"expected hard or low-pcf"),bt(n.bias,`${t}.bias`,0,.1),bt(n.normalBias,`${t}.normalBias`,0,1),bt(n.darkness,`${t}.darkness`,0,1),n.softness!==void 0&&bt(n.softness,`${t}.softness`,0,1),Ws(n.bounds,`${t}.bounds`),Ys(n.backend,`${t}.backend`),Qs(n.culling,`${t}.culling`),ea(n.diagnostics,`${t}.diagnostics`)}function Js(e,t){let n=ue(e,t);ye(n,["cast","receive","updateClass"],t),n.cast!=="enabled"&&n.cast!=="disabled"&&N(`${t}.cast`,"expected enabled or disabled"),n.receive!=="enabled"&&n.receive!=="disabled"&&N(`${t}.receive`,"expected enabled or disabled"),["auto","static","dynamic","skinned"].includes(String(n.updateClass))||N(`${t}.updateClass`,"expected auto, static, dynamic, or skinned")}function Xs(e,t){let n=ue(e,t);ye(n,["staticResolution","dynamicResolution","compositeResolution"],t),On(n.staticResolution,`${t}.staticResolution`),On(n.dynamicResolution,`${t}.dynamicResolution`),On(n.compositeResolution,`${t}.compositeResolution`)}function On(e,t){e!==512&&e!==1024&&e!==2048&&e!==4096&&N(t,"expected 512, 1024, 2048, or 4096")}function Zs(e,t){e!==1&&e!==2&&e!==4&&N(t,"expected 1, 2, or 4")}function Ys(e,t){let n=ue(e,t);ye(n,["mode","fallback"],t),["auto","split","single"].includes(String(n.mode))||N(`${t}.mode`,"expected auto, split, or single"),n.fallback!=="single-map"&&n.fallback!=="disable"&&N(`${t}.fallback`,"expected single-map or disable")}function Qs(e,t){let n=ue(e,t);ye(n,["enabled","guardBandRatio"],t),typeof n.enabled!="boolean"&&N(`${t}.enabled`,"expected boolean"),bt(n.guardBandRatio,`${t}.guardBandRatio`,0,4)}function ea(e,t){let n=ue(e,t);ye(n,["staticCasterCountWarning","dynamicCasterCountWarning","renderableCountWarning"],t),Gn(n.staticCasterCountWarning,`${t}.staticCasterCountWarning`),Gn(n.dynamicCasterCountWarning,`${t}.dynamicCasterCountWarning`),Gn(n.renderableCountWarning,`${t}.renderableCountWarning`)}function ta(e){let t=new Set,n=new Set;for(let r of e){t.has(r.entityId)&&N("$.objects",`duplicate entity id: ${r.entityId}`),t.add(r.entityId);for(let i of r.renderableIds)n.has(i)&&N("$.objects",`duplicate renderable id: ${i}`),n.add(i)}}function Vr(e,t){let n=ue(e,t);Object.keys(n).length===0&&N(t,"expected at least one profile");for(let r of Object.keys(n))be(r,`${t} key`);return n}function vn(e,t,n,r){return Object.prototype.hasOwnProperty.call(e,t)||N(n,`unknown ${r} profile: ${t}`),e[t]}function na(e){return Object.freeze({mode:"fixed",center:yt(e.center,"$.bounds.center"),extent:yt(e.extent,"$.bounds.extent"),near:e.near,far:e.far})}function yt(e,t){let n=ia(e,t);return n.length!==3&&N(t,"expected exactly three numbers"),Object.freeze(n.map((r,i)=>qt(r,`${t}[${i}]`)))}function ra(e,t){let n=e.map((r,i)=>be(r,`${t}[${i}]`));return new Set(n).size!==n.length&&N(t,"expected unique strings"),n}function qt(e,t){return(typeof e!="number"||!Number.isFinite(e))&&N(t,"expected a finite number"),e}function bt(e,t,n,r){let i=qt(e,t);return(i<n||i>r)&&N(t,`expected ${n}..${r}`),i}function Gn(e,t){return(!Number.isInteger(e)||e<0)&&N(t,"expected a non-negative integer"),e}function be(e,t){return(typeof e!="string"||!e.trim()||e!==e.trim())&&N(t,"expected a trimmed non-empty string"),e}function ue(e,t){(!e||typeof e!="object"||Array.isArray(e))&&N(t,"expected an object");let n=Object.getPrototypeOf(e);return n!==Object.prototype&&n!==null&&N(t,"expected a plain object"),e}function ia(e,t){return Array.isArray(e)||N(t,"expected an array"),e}function ye(e,t,n){let r=new Set(t);for(let i of Object.keys(e))r.has(i)||N(`${n}.${i}`,"unknown field")}function Hr(e){if(!e||typeof e!="object"||Object.isFrozen(e))return e;for(let t of Object.values(e))Hr(t);return Object.freeze(e)}function N(e,t){throw new Error(`shadow_map_experiment_invalid:${e}:${t}`)}var Wr=["useBlobShadow","blobSettings"],oa=["resolution","maxSize"],sa=new Set(["none","blob","static","planar","dynamic"]);function qr(e){let t=je(e);if(!t)throw v("schema.invalidType","$");for(let i of Wr)if(Object.prototype.hasOwnProperty.call(t,i))throw v("schema.deprecatedField",`$.${i}`);if(O(t,["globalVolume","materials","renderingGroups","shadowMeshes","shadows"],"$"),ca(t.globalVolume,"$.globalVolume"),la(t.materials,"$.materials"),aa(t.renderingGroups,"$.renderingGroups"),da(t.globalVolume,"$.globalVolume"),ba(t.shadowMeshes,"$.shadowMeshes"),!Object.prototype.hasOwnProperty.call(t,"shadows"))return;let n=je(t.shadows);if(!n)throw v("schema.invalidType","$.shadows");for(let i of Wr)if(Object.prototype.hasOwnProperty.call(n,i))throw v("schema.deprecatedField",`$.shadows.${i}`);if(O(n,["defaultMode","enabled","useCsm","settings","blob","staticProjected","planar","shadowRange","shadowOrtho","csm"],"$.shadows"),"defaultMode"in n&&!sa.has(String(n.defaultMode)))throw v("schema.invalidValue","$.shadows.defaultMode");ee(n,"enabled","$.shadows"),ee(n,"useCsm","$.shadows");let r=je(n.settings);if(Object.prototype.hasOwnProperty.call(n,"settings")&&!r)throw v("schema.invalidType","$.shadows.settings");if(r){O(r,["mapSize","darkness","blurKernel","bias","normalBias","shadowMinZ","shadowMaxZ","useBlurExponentialShadowMap","shadowColor"],"$.shadows.settings");for(let i of["mapSize","darkness","blurKernel","bias","normalBias","shadowMinZ","shadowMaxZ"])X(r,i,"$.shadows.settings");ee(r,"useBlurExponentialShadowMap","$.shadows.settings"),Jt(r.shadowColor,"$.shadows.settings.shadowColor",!1)}fa(n.blob,"$.shadows.blob"),ma(n.staticProjected,"$.shadows.staticProjected"),ga(n.planar,"$.shadows.planar"),Fe(n.shadowRange,"$.shadows.shadowRange",["minZ","maxZ"]),Fe(n.shadowOrtho,"$.shadows.shadowOrtho",["left","right","top","bottom"]),pa(n.csm,"$.shadows.csm")}function aa(e,t){if(e===void 0)return;let n=je(e);if(!n||!Array.isArray(n.slots))throw v("schema.invalidType",t);O(n,["slots"],t),n.slots.forEach((r,i)=>{let o=`${t}.slots[${i}]`,s=je(r);if(!s)throw v("schema.invalidType",o);if(O(s,["renderingGroupId","name","alphaIndexPresets"],o),![0,1,2,3].includes(s.renderingGroupId))throw v("schema.invalidValue",`${o}.renderingGroupId`);if(typeof s.name!="string"||!s.name.trim())throw v("schema.invalidValue",`${o}.name`);if(!Array.isArray(s.alphaIndexPresets))throw v("schema.invalidType",`${o}.alphaIndexPresets`);s.alphaIndexPresets.forEach((a,c)=>{let d=`${o}.alphaIndexPresets[${c}]`,u=je(a);if(!u)throw v("schema.invalidType",d);if(O(u,["name","alphaIndex"],d),typeof u.name!="string"||!u.name.trim())throw v("schema.invalidValue",`${d}.name`);_n(u,"alphaIndex",d)})})}function da(e,t){if(e===void 0)return;let n=K(e,t);for(let o of["samples","camera","lights"])if(o in n)throw v("schema.deprecatedField",`${t}.${o}`);if(O(n,["enabled","hdr","environment","imageProcessing","toneMapping","antialiasing","postProcessing","rendering","textures"],t),ee(n,"enabled",t),ee(n,"hdr",t),n.environment!==void 0){let o=K(n.environment,`${t}.environment`);for(let s of["textureAssetId","textureUrl","intensity"])if(s in o)throw v("schema.deprecatedField",`${t}.environment.${s}`);if(O(o,["texture","iblIntensity","rotationY","useCocosIBL"],`${t}.environment`),o.texture!==void 0&&o.texture!==null){let s=K(o.texture,`${t}.environment.texture`);for(let a of Object.keys(s))if(a!=="textureAssetId"&&a!=="url")throw v("schema.deprecatedField",`${t}.environment.texture.${a}`);for(let a of["textureAssetId","url"])if(a in s&&s[a]!=null&&(typeof s[a]!="string"||!s[a].trim()))throw v("schema.invalidValue",`${t}.environment.texture.${a}`)}X(o,"iblIntensity",`${t}.environment`),X(o,"rotationY",`${t}.environment`),ee(o,"useCocosIBL",`${t}.environment`)}if(Fe(n.imageProcessing,`${t}.imageProcessing`,["exposure","contrast"]),n.toneMapping!==void 0){let o=K(n.toneMapping,`${t}.toneMapping`);if(O(o,["enabled","type"],`${t}.toneMapping`),ee(o,"enabled",`${t}.toneMapping`),"type"in o&&!["standard","aces","khr-pbr-neutral"].includes(String(o.type)))throw v("schema.invalidValue",`${t}.toneMapping.type`)}if(n.antialiasing!==void 0){let o=K(n.antialiasing,`${t}.antialiasing`);if(O(o,["samples"],`${t}.antialiasing`),"samples"in o&&![1,2,4,8].includes(o.samples))throw v("schema.invalidValue",`${t}.antialiasing.samples`)}let r=fe(n.postProcessing,`${t}.postProcessing`);r&&O(r,["bloom"],`${t}.postProcessing`);let i=r?fe(r.bloom,`${t}.postProcessing.bloom`):null;if(i){O(i,["enabled","threshold","weight","kernel","scale"],`${t}.postProcessing.bloom`),ee(i,"enabled",`${t}.postProcessing.bloom`);for(let o of["threshold","weight","kernel","scale"])X(i,o,`${t}.postProcessing.bloom`)}}function ca(e,t){if(e===void 0)return;let n=K(e,t),r=fe(n.rendering,`${t}.rendering`);r&&(O(r,["maxDpr","hardwareScalingLevel"],`${t}.rendering`),X(r,"maxDpr",`${t}.rendering`),ua(r,"hardwareScalingLevel",`${t}.rendering`));let i=fe(n.textures,`${t}.textures`);if(i&&(O(i,["anisotropicFilteringLevel","samplingMode"],`${t}.textures`),X(i,"anisotropicFilteringLevel",`${t}.textures`),"samplingMode"in i&&(typeof i.samplingMode!="string"||!i.samplingMode.trim())))throw v("schema.invalidValue",`${t}.textures.samplingMode`)}function la(e,t){if(e===void 0)return;let n=K(e,t);O(n,["sceneMaterials","plantMaterials"],t);for(let r of["sceneMaterials","plantMaterials"])r in n&&K(n[r],`${t}.${r}`)}function ua(e,t,n){!(t in e)||e[t]==null||X(e,t,n)}function fa(e,t){if(e===void 0)return;let n=K(e,t);O(n,["enabled","plane","appearance","size"],t),ee(n,"enabled",t),Fe(n.plane,`${t}.plane`,["height","yOffset"]);let r=fe(n.appearance,`${t}.appearance`);r&&(O(r,["color","edgeSoftness"],`${t}.appearance`),Jt(r.color,`${t}.appearance.color`,!0),X(r,"edgeSoftness",`${t}.appearance`)),Fe(n.size,`${t}.size`,["sizeMultiplier","minSize","maxSize"])}function ma(e,t){if(e===void 0)return;let n=K(e,t);O(n,["enabled","plane","appearance","bake"],t),ee(n,"enabled",t),Fe(n.plane,`${t}.plane`,["height","yOffset"]);let r=fe(n.appearance,`${t}.appearance`);if(r&&(O(r,["color"],`${t}.appearance`),Jt(r.color,`${t}.appearance.color`,!0)),n.bake===void 0)return;let i=K(n.bake,`${t}.bake`);for(let o of oa)if(o in i)throw v("schema.deprecatedField",`${t}.bake.${o}`);O(i,["padding","blur","texelsPerMeter","atlasSize","maxAtlasPages","sdfRadiusPx","spatialChunkSize","targetChunkCount"],`${t}.bake`);for(let o of["padding","blur","texelsPerMeter","atlasSize","maxAtlasPages","sdfRadiusPx","spatialChunkSize","targetChunkCount"])X(i,o,`${t}.bake`)}function ga(e,t){if(e===void 0)return;let n=K(e,t);O(n,["enabled","plane","appearance","projection","stencil","casters","receivers"],t),ee(n,"enabled",t);let r=fe(n.plane,`${t}.plane`);if(r){O(r,["normal","height","bias","heightMode"],`${t}.plane`),ya(r.normal,`${t}.plane.normal`);for(let c of["height","bias"])X(r,c,`${t}.plane`);if("heightMode"in r&&!["fixed","receiver"].includes(String(r.heightMode)))throw v("schema.invalidValue",`${t}.plane.heightMode`)}let i=fe(n.appearance,`${t}.appearance`);i&&(O(i,["color"],`${t}.appearance`),Jt(i.color,`${t}.appearance.color`,!0)),Fe(n.projection,`${t}.projection`,["footprintScale"]);let o=fe(n.stencil,`${t}.stencil`);if(o){O(o,["enabled","receiverRenderingGroup","shadowRenderingGroup"],`${t}.stencil`),ee(o,"enabled",`${t}.stencil`);for(let c of["receiverRenderingGroup","shadowRenderingGroup"])X(o,c,`${t}.stencil`)}let s=fe(n.casters,`${t}.casters`);if(s){O(s,["autoDetectAll","includePatterns","excludePatterns","rootBoundaryPatterns","minVolume"],`${t}.casters`),ee(s,"autoDetectAll",`${t}.casters`);for(let c of["includePatterns","excludePatterns","rootBoundaryPatterns"])Fn(s[c],`${t}.casters.${c}`);X(s,"minVolume",`${t}.casters`)}let a=fe(n.receivers,`${t}.receivers`);a&&(O(a,["patterns"],`${t}.receivers`),Fn(a.patterns,`${t}.receivers.patterns`))}function pa(e,t){if(e===void 0)return;let n=K(e,t);O(n,["numCascades","lambda","cascadeBlendPercentage","stabilizeCascades"],t);for(let r of["numCascades","lambda","cascadeBlendPercentage"])X(n,r,t);ee(n,"stabilizeCascades",t)}function ba(e,t){if(e===void 0)return;let n=K(e,t);O(n,["shadowReceivers","shadowCasters","excludeFromShadow"],t);for(let r of["shadowReceivers","shadowCasters","excludeFromShadow"])Fn(n[r],`${t}.${r}`)}function Fe(e,t,n){if(e===void 0)return;let r=K(e,t);O(r,n,t);for(let i of n)X(r,i,t)}function Jt(e,t,n){if(e===void 0)return;let r=K(e,t),i=n?["r","g","b","a"]:["r","g","b"];O(r,i,t);for(let o of i)_n(r,o,t)}function ya(e,t){if(e===void 0)return;let n=K(e,t);O(n,["x","y","z"],t);for(let r of["x","y","z"])_n(n,r,t)}function Fn(e,t){if(e!==void 0&&(!Array.isArray(e)||e.some(n=>typeof n!="string")))throw v("schema.invalidType",t)}function _n(e,t,n){if(!(t in e))throw v("schema.invalidValue",`${n}.${t}`);X(e,t,n)}function fe(e,t){return e===void 0?null:K(e,t)}function K(e,t){let n=je(e);if(!n)throw v("schema.invalidType",t);return n}function ee(e,t,n){if(t in e&&typeof e[t]!="boolean")throw v("schema.invalidValue",`${n}.${t}`)}function X(e,t,n){if(!(t in e))return;let r=e[t];if(typeof r!="number"||!Number.isFinite(r))throw v("schema.invalidValue",`${n}.${t}`)}function O(e,t,n){let r=new Set(t);for(let i of Object.keys(e))if(!r.has(i))throw v("schema.unknownField",`${n}.${i}`)}function v(e,t){let n=new Error(`${e}: ${t}`);return Object.assign(n,{code:e,path:t}),n}function je(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function M(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}function Jr(e,t){let n=M(e);return{x:H(n.x,t.x),y:H(n.y,t.y),z:H(n.z,t.z)}}function Ln(e,t){let n=M(e);return{r:Pe(n.r,t.r,0,1),g:Pe(n.g,t.g,0,1),b:Pe(n.b,t.b,0,1)}}function ht(e,t){let n=M(e);return{...Ln(n,t),a:Pe(n.a,t.a,0,1)}}function ke(e){return Array.isArray(e)?e.map(t=>typeof t=="string"?t.trim():"").filter((t,n,r)=>t.length>0&&r.indexOf(t)===n):[]}function zn(e){return(typeof e=="string"?e.trim():"")||null}function Un(e,t){return(typeof e=="string"?e.trim():"")||t}function te(e,t){return typeof e=="boolean"?e:t}function Xr(e){return e===0||e===1||e===2||e===3?e:null}function Zr(e,t){return e==="standard"||e==="aces"||e==="khr-pbr-neutral"?e:t}function Yr(e,t){return e===1||e===2||e===4||e===8?e:t}function Qr(e,t){return e==="fixed"||e==="receiver"?e:t}function ei(e,t){return e==="none"||e==="blob"||e==="static"||e==="planar"||e==="dynamic"?e:t}function H(e,t){return typeof e=="number"&&Number.isFinite(e)?e:t}function G(e,t){let n=H(e,t);return Math.max(0,n)}function Me(e,t){let n=H(e,t);return n>0?n:t}function Pe(e,t,n,r){let i=H(e,t);return Math.min(r,Math.max(n,i))}var ti=["editor","grid","gizmo","helper","camera","light","decal","texture","trigger","collision","ui","_shadow","_planarShadow"],ni=[...ti,"_blobShadow"],ha=[...ni,"_staticProjectedShadow"];var ri=[{renderingGroupId:0,name:"\u666E\u901A\u573A\u666F",alphaIndexPresets:[{name:"\u9ED8\u8BA4\u900F\u660E\u987A\u5E8F",alphaIndex:0},{name:"\u5730\u8868\u8D34\u82B1",alphaIndex:100},{name:"\u8FD1\u666F\u8986\u76D6",alphaIndex:200}]},{renderingGroupId:1,name:"\u6C34\u9762 / \u900F\u660E\u5730\u8868",alphaIndexPresets:[{name:"\u6C34\u9762",alphaIndex:0},{name:"\u900F\u660E\u5730\u8868",alphaIndex:100},{name:"\u6C34\u9762\u9AD8\u5149",alphaIndex:200}]},{renderingGroupId:2,name:"\u7279\u6548",alphaIndexPresets:[{name:"\u666E\u901A\u7279\u6548",alphaIndex:0},{name:"\u524D\u666F\u7279\u6548",alphaIndex:100},{name:"\u6700\u524D\u7279\u6548",alphaIndex:200}]},{renderingGroupId:3,name:"\u4E16\u754C\u7A7A\u95F4 UI / \u5F15\u5BFC\u7BAD\u5934",alphaIndexPresets:[{name:"\u4E16\u754C\u7A7A\u95F4 UI",alphaIndex:0},{name:"\u5F15\u5BFC\u7BAD\u5934",alphaIndex:100},{name:"\u9876\u5C42\u63D0\u793A",alphaIndex:200}]}];function Xt(e){e!=null&&qr(e);let t=M(e),n=M(t.shadows),r=M(n.settings),i=M(n.blob),o=Sa(i),s=Pa(n.staticProjected),a=M(n.shadowRange),c=M(n.shadowOrtho),d=M(n.csm),u=M(t.shadowMeshes);return{renderingGroups:ii(t.renderingGroups),environment:Ia(t.globalVolume),postProcess:Ea(t.globalVolume),shadows:{defaultMode:ei(n.defaultMode,"none"),enabled:te(n.enabled,!1),useCsm:te(n.useCsm,!1),settings:{mapSize:G(r.mapSize,1024),darkness:G(r.darkness,.3),blurKernel:G(r.blurKernel,16),bias:G(r.bias,5e-5),normalBias:G(r.normalBias,.02),useBlurExponentialShadowMap:te(r.useBlurExponentialShadowMap,!0),shadowMinZ:G(r.shadowMinZ,1),shadowMaxZ:G(r.shadowMaxZ,60),shadowColor:Ln(r.shadowColor,{r:0,g:0,b:0})},blob:o,staticProjected:s,shadowRange:{minZ:G(a.minZ,1),maxZ:G(a.maxZ,60)},shadowOrtho:{left:H(c.left,-20),right:H(c.right,20),top:H(c.top,20),bottom:H(c.bottom,-20)},csm:{numCascades:G(d.numCascades,2),lambda:Pe(d.lambda,.5,0,1),cascadeBlendPercentage:Pe(d.cascadeBlendPercentage,.1,0,1),stabilizeCascades:te(d.stabilizeCascades,!0)},planar:xa(n.planar)},shadowMeshes:{shadowReceivers:ke(u.shadowReceivers),shadowCasters:ke(u.shadowCasters),excludeFromShadow:ke(u.excludeFromShadow)}}}function Sa(e){let t=M(e),n=M(t.plane),r=M(t.appearance),i=M(t.size),o=ht(r.color,{r:0,g:0,b:0,a:.35});return{enabled:te(t.enabled,!0),plane:{height:H(n.height,0),yOffset:G(n.yOffset,.08)},appearance:{color:ht(r.color,o),edgeSoftness:Pe(r.edgeSoftness,.55,0,.98)},size:{sizeMultiplier:G(i.sizeMultiplier,1.25),minSize:G(i.minSize,.25),maxSize:Me(i.maxSize,20)}}}function ii(e){let t=M(e),n=Array.isArray(t.slots)?t.slots:[];return{slots:ri.map(r=>{let i=n.find(s=>Xr(M(s).renderingGroupId)===r.renderingGroupId),o=M(i);return{renderingGroupId:r.renderingGroupId,name:Un(o.name,r.name),alphaIndexPresets:oi(o.alphaIndexPresets,r.alphaIndexPresets)}})}}function oi(e,t){let n=Array.isArray(e)?e:t,r=new Set,i=[];return n.forEach((o,s)=>{let a=M(o),c=H(a.alphaIndex,Number.NaN);!Number.isFinite(c)||r.has(c)||(r.add(c),i.push({name:Un(a.name,`Order ${s+1}`),alphaIndex:c}))}),i}function xa(e){let t=M(e),n=M(t.plane),r=M(t.appearance),i=M(t.projection),o=M(t.stencil),s=M(t.casters),a=M(t.receivers);return{enabled:te(t.enabled,!0),plane:{normal:Jr(n.normal,{x:0,y:1,z:0}),height:H(n.height,0),heightMode:Qr(n.heightMode,"receiver"),bias:G(n.bias,.4)},appearance:{color:ht(r.color,{r:0,g:0,b:0,a:.35})},projection:{footprintScale:Pe(i.footprintScale,1,0,2)},stencil:{enabled:te(o.enabled,!0),receiverRenderingGroup:G(o.receiverRenderingGroup,0),shadowRenderingGroup:G(o.shadowRenderingGroup,1)},casters:{autoDetectAll:te(s.autoDetectAll,!0),includePatterns:ke(s.includePatterns),excludePatterns:ke(s.excludePatterns),rootBoundaryPatterns:ke(s.rootBoundaryPatterns),minVolume:G(s.minVolume,.001)},receivers:{patterns:ke(a.patterns)}}}function Pa(e){let t=M(e),n=M(t.plane),r=M(t.appearance),i=M(t.bake),o=Me(i.spatialChunkSize,16);return{enabled:te(t.enabled,!1),plane:{height:H(n.height,0),yOffset:G(n.yOffset,.08)},appearance:{color:ht(r.color,{r:0,g:0,b:0,a:.35})},bake:{padding:G(i.padding,.15),blur:G(i.blur,0),texelsPerMeter:Me(i.texelsPerMeter,256),atlasSize:Me(i.atlasSize,4096),maxAtlasPages:Me(i.maxAtlasPages,8),sdfRadiusPx:G(i.sdfRadiusPx,8),spatialChunkSize:o,targetChunkCount:Me(i.targetChunkCount,64)}}}function Ia(e){let t=M(e),n=M(t.environment),r=M(n.texture),i=zn(r.textureAssetId),o=zn(r.url);return{texture:i||o?{...i?{textureAssetId:i}:{},...o?{url:o}:{}}:null,iblIntensity:G(n.iblIntensity,1),rotationY:H(n.rotationY,0)}}function Ea(e){let t=M(e),n=M(t.imageProcessing),r=M(t.toneMapping),i=M(t.antialiasing),o=M(t.postProcessing),s=M(o.bloom);return{enabled:te(t.enabled,!0),hdr:te(t.hdr,!0),imageProcessing:{exposure:H(n.exposure,1),contrast:H(n.contrast,1)},toneMapping:{enabled:te(r.enabled,!0),type:Zr(r.type,"aces")},antialiasing:{samples:Yr(i.samples,4)},bloom:{enabled:te(s.enabled,!1),threshold:G(s.threshold,.9),weight:G(s.weight,.2),kernel:G(s.kernel,64),scale:Me(s.scale,.5)}}}var Aa=new Set([".glb",".gltf",".png",".jpg",".jpeg",".webp",".env",".hdr",".dds",".ktx",".ktx2",".mp3",".wav",".ogg",".flac",".aac",".m4a"]);function si(e){let t=String(e??"").trim().toLowerCase();if(/^\.[a-z0-9]+$/.test(t))return t;let n=t.split(/[?#]/,1)[0]??"",r=n.slice(n.lastIndexOf("/")+1),i=r.lastIndexOf(".");return i<=0||i===r.length-1?null:r.slice(i)}function ai(e){return Aa.has(e)}function Zt(e){return e==="fps.builtin.pbr"||e==="fps.builtin.standard"?e:void 0}function di(e){if(!e||typeof e!="object")return;let t={};(e.lightingModel==="lit"||e.lightingModel==="unlit")&&(t.lightingModel=e.lightingModel);let n={},r=ci(e.baseColor?.color);r&&(n.color=r);let i=_e(e.baseColor?.texture);i!==void 0&&(n.texture=i),Ie(e.baseColor,n,"brightness"),Ie(e.baseColor,n,"saturation"),Ie(e.baseColor,n,"contrast"),Ie(e.baseColor,n,"hue"),Object.keys(n).length>0&&(t.baseColor=n);let o={},s=_e(e.normal?.texture);s!==void 0&&(o.texture=s),Ie(e.normal,o,"strength"),Object.keys(o).length>0&&(t.normal=o),Xe(e.metallic)&&(t.metallic=e.metallic),Xe(e.roughness)&&(t.roughness=e.roughness);let a={},c=_e(e.metallicRoughness?.texture);c!==void 0&&(a.texture=c),Object.keys(a).length>0&&(t.metallicRoughness=a);let d={},u=_e(e.occlusion?.texture);u!==void 0&&(d.texture=u),Ie(e.occlusion,d,"strength"),Object.keys(d).length>0&&(t.occlusion=d);let l={},f=ci(e.emission?.color);f&&(l.color=f),Ie(e.emission,l,"intensity");let g=_e(e.emission?.texture);g!==void 0&&(l.texture=g);let p=_e(e.emission?.maskTexture);p!==void 0&&(l.maskTexture=p),Object.keys(l).length>0&&(t.emission=l);let h={};(e.alpha?.mode==="opaque"||e.alpha?.mode==="mask"||e.alpha?.mode==="blend")&&(h.mode=e.alpha.mode),Ie(e.alpha,h,"opacity"),Ie(e.alpha,h,"cutoff");let S=_e(e.alpha?.texture);return S!==void 0&&(h.texture=S),Object.keys(h).length>0&&(t.alpha=h),Object.keys(t).length>0?t:void 0}function Bn(...e){let t={};for(let n of e){let r=di(n);r&&(r.lightingModel&&(t.lightingModel=r.lightingModel),Je(t,r,"baseColor"),Je(t,r,"normal"),r.metallic!==void 0&&(t.metallic=r.metallic),r.roughness!==void 0&&(t.roughness=r.roughness),Je(t,r,"metallicRoughness"),Je(t,r,"occlusion"),Je(t,r,"emission"),Je(t,r,"alpha"))}return di(t)??{}}function Je(e,t,n){let r=t[n];r&&Object.assign(e,{[n]:{...e[n]??{},...r}})}function ci(e){return e&&Xe(e.r)&&Xe(e.g)&&Xe(e.b)?{r:e.r,g:e.g,b:e.b}:void 0}function _e(e){if(e===null)return null;if(!e||typeof e!="object")return;let t=typeof e.url=="string"?e.url.trim():"",n=typeof e.textureAssetId=="string"?e.textureAssetId.trim():"";if(!(!t&&!n))return{...t?{url:t}:{},...n?{textureAssetId:n}:{}}}function Ie(e,t,n){Xe(e?.[n])&&(t[n]=e[n])}function Xe(e){return typeof e=="number"&&Number.isFinite(e)}function wa(e){let t=Ae(e);if(!t)return null;let n=B(t.sourceHash),r=B(t.lightHash),i=B(t.profileHash);if(!n||!r||!i)return null;let o={sourceHash:n,lightHash:r,profileHash:i,...typeof t.generatedAt=="string"&&t.generatedAt.trim()?{generatedAt:t.generatedAt.trim()}:{},...(()=>{let u=Na(t.stats);return u?{stats:u}:{}})()};if(t.version!==2||t.format!=="sdf-atlas"||!Array.isArray(t.pages)||!Array.isArray(t.chunks))return null;let s=[],a=new Map;for(let u of t.pages){let l=Ta(u);if(!l||a.has(l.id))return null;s.push(l),a.set(l.id,l)}let c=[],d=new Set;for(let u of t.chunks){let l=Da(u,a);if(!l||d.has(l.id))return null;c.push(l),d.add(l.id)}return{version:2,format:"sdf-atlas",pages:s,chunks:c,...o}}function nn(e,t="$.staticShadows"){let n=wa(e);if(n)return n;let r=new Error(`schema.unsupportedVersion: ${t}`);throw Object.assign(r,{code:"schema.unsupportedVersion",path:t}),r}function Ta(e){let t=Ae(e);if(!t)return null;let n=B(t.id),r=tn(t.width),i=tn(t.height),o=Oa(t.sdfTextureDataUrl);return!n||r==null||i==null||!o?null:{id:n,width:r,height:i,sdfTextureDataUrl:o}}function Da(e,t){let n=Ae(e);if(!n)return null;let r=B(n.id),i=Ra(n.bounds),o=$a(n.plane),s=B(n.pageId),a=Ma(n.atlasRect),c=Ca(n.atlasUv),d=va(n.sourceNodeIds),u=B(n.sourceHash),l=B(n.lightHash),f=B(n.profileHash);if(!r||!i||!o||!s||!a||!c||!d||!u||!l||!f)return null;let g=t.get(s);return!g||a.x+a.width>g.width||a.y+a.height>g.height?null:{id:r,bounds:i,plane:o,pageId:s,atlasRect:a,atlasUv:c,sourceNodeIds:d,sourceHash:u,lightHash:l,profileHash:f,...(()=>{let p=ka(n.binding);return p?{binding:p}:{}})()}}function ka(e){let t=Ae(e);if(!t)return null;let n=B(t.id),r=B(t.ownerCasterId),i=B(t.receiverId),o=B(t.generatedAt),s=B(t.sourceHash);if(!n||!r||!i||!o||!s||t.visibleWhenOwnerVisible!==!0||t.staleWhenOwnerTransformChanges!==!0||t.staleWhenLightChanges!==!0)return null;let a=B(t.lightId),c=B(t.textureAssetId),d=B(t.projectionNodeId);return{id:n,ownerCasterId:r,receiverId:i,...a?{lightId:a}:{},...c?{textureAssetId:c}:{},...d?{projectionNodeId:d}:{},visibleWhenOwnerVisible:!0,staleWhenOwnerTransformChanges:!0,staleWhenLightChanges:!0,generatedAt:o,sourceHash:s}}function Ma(e){let t=Ae(e);if(!t)return null;let n=Ce(t.x),r=Ce(t.y),i=tn(t.width),o=tn(t.height);return n==null||r==null||i==null||o==null?null:{x:n,y:r,width:i,height:o}}function Ca(e){let t=Ae(e);if(!t)return null;let n=Yt(t.u0),r=Yt(t.v0),i=Yt(t.u1),o=Yt(t.v1);return n==null||r==null||i==null||o==null||i<=n||o<=r?null:{u0:n,v0:r,u1:i,v1:o}}function Ra(e){let t=Ae(e);if(!t)return null;let n=he(t.minX),r=he(t.maxX),i=he(t.minZ),o=he(t.maxZ),s=he(t.y);return n==null||r==null||i==null||o==null||s==null||r<=n||o<=i?null:{minX:n,maxX:r,minZ:i,maxZ:o,y:s}}function $a(e){let t=Ae(e);if(!t)return null;let n=he(t.height),r=he(t.yOffset);return n==null||r==null||r<0?null:{height:n,yOffset:r}}function Na(e){let t=Ae(e);if(!t)return null;let n=Ce(t.sourceRootCount),r=Ce(t.sourceMeshCount),i=Ce(t.attemptedChunkCount),o=Ce(t.chunkCount),s=Ce(t.textureCount);return n==null||r==null||i==null||o==null||s==null?null:{sourceRootCount:n,sourceMeshCount:r,attemptedChunkCount:i,chunkCount:o,textureCount:s,...Qt(t.skippedChunkCount,"skippedChunkCount"),...Qt(t.pageCount,"pageCount"),...Ee(t.resolution,"resolution"),...Ee(t.chunkSize,"chunkSize"),...Ee(t.atlasSize,"atlasSize"),...en(t.atlasUsedPixels,"atlasUsedPixels"),...en(t.atlasAllocatedPixels,"atlasAllocatedPixels"),...Ga(t.atlasOccupancy,"atlasOccupancy"),...Ee(t.texelsPerMeter,"texelsPerMeter"),...Ee(t.effectiveTexelsPerMeter,"effectiveTexelsPerMeter"),...Ee(t.maxAtlasPages,"maxAtlasPages"),...en(t.sdfRadiusPx,"sdfRadiusPx"),...Ee(t.spatialChunkSize,"spatialChunkSize"),...Ee(t.effectiveSpatialChunkSize,"effectiveSpatialChunkSize"),...Ee(t.targetChunkCount,"targetChunkCount"),...Qt(t.bakedChunkCount,"bakedChunkCount"),...Qt(t.reusedChunkCount,"reusedChunkCount"),...en(t.durationMs,"durationMs")}}function Oa(e){let t=B(e);return t&&/^data:image\/png[;,]/i.test(t)?t:null}function va(e){if(!Array.isArray(e)||e.length===0)return null;let t=[],n=new Set;for(let r of e){let i=B(r);if(!i)return null;n.has(i)||t.push(i),n.add(i)}return t}function B(e){return typeof e=="string"&&e.trim()?e.trim():null}function he(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function Ce(e){return typeof e=="number"&&Number.isInteger(e)&&e>=0?e:null}function tn(e){return typeof e=="number"&&Number.isInteger(e)&&e>0?e:null}function Yt(e){return typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=1?e:null}function Qt(e,t){let n=Ce(e);return n==null?{}:{[t]:n}}function Ee(e,t){let n=he(e);return n==null||n<=0?{}:{[t]:n}}function en(e,t){let n=he(e);return n==null||n<0?{}:{[t]:n}}function Ga(e,t){let n=he(e);return n==null||n<0||n>1?{}:{[t]:n}}function Ae(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}var ja="@fps-games/editor.playable-sdk.scene-compiler",Fa="2",_a=1e-4,se={nodeKinds:["group","instance","transform","primitive","image"],primitiveShapes:["cube","sphere","plane","capsule"],transformTypes:["plain","light","camera","groundDecal"],assetTypes:["glb","texture"],materialScopes:["sharedAsset","nodeMaterial"],materialModes:["shared","instance"],materialShaderIds:["fps.builtin.pbr","fps.builtin.standard"],materialAssetSystemPresets:["default-pbr","default-standard"],runtimeV3:{assetFields:["id","guid","type","url","external","warmupCount","singleton","materialMode","defaults","materialSlots"],materialSlotFields:["slotId","label","sourceSurfaces"],materialSlotSourceSurfaceFields:["ownerNodePath","nodeIndex","nodeIndexPath","meshIndex","primitiveIndex","sourceMaterialIndex","sourceMeshName"]},hierarchy:{parentTargets:["root","sceneNode"]},runtimeOnlyTokens:["/@fs","assetUrl","sourceAssetUrl","sourceAssetPath"]},La=new Set(se.nodeKinds),za=new Set(se.primitiveShapes),Ua=new Set(se.assetTypes),Ba=new Set(se.materialModes),Va=new Set(se.materialScopes),Ka=new Set(se.materialAssetSystemPresets),Ha=new Set(se.transformTypes),St=new Set(se.hierarchy.parentTargets),Wa=se.runtimeOnlyTokens,qa=new Set(se.runtimeV3.assetFields),Ja=new Set(se.runtimeV3.materialSlotFields),Xa=new Set(se.runtimeV3.materialSlotSourceSurfaceFields);function Za(e,t={}){let{allowOrphanSharedMaterials:n=!0,allowOrphanNodeMaterials:r=!0,strictAssetIds:i=[],strictNodeIds:o=[],maxErrors:s=50}=t,a=Number.isInteger(s)&&s>0?s:50,c=[],d=new Set(i),u=new Set(o),l=(m,L)=>{c.length<a&&c.push({path:m,message:L})};if(!x(e))return l("$","scene json must be an object"),c;let f=e.schemaVersion;f!==2&&f!==3&&l("$.schemaVersion","schemaVersion must be 2 or 3"),fd(e.meta?.generatedFrom,"$.meta.generatedFrom",l);let g=Pd(e),p=e.scene;if(!x(p))return l("$.scene","scene must be an object"),c;if(E(p.rootId)||l("$.scene.rootId","rootId must be a non-empty string"),Array.isArray(p.assets)||l("$.scene.assets","assets must be an array"),Array.isArray(p.nodes)||l("$.scene.nodes","nodes must be an array"),Array.isArray(p.materialAssets)||l("$.scene.materialAssets","materialAssets must be an array"),Array.isArray(p.materials)||l("$.scene.materials","materials must be an array"),Array.isArray(p.textures)||l("$.scene.textures","textures must be an array"),c.length>0)return c;e.staticShadows!=null&&li(()=>nn(e.staticShadows,"$.staticShadows"),"$.staticShadows",l);let h=new Set,S=new Map,P=new Map,D=new Set,T=new Set([p.rootId]),$=new Map,_=new Map,q=new Set;return p.assets.forEach((m,L)=>{let b=`$.scene.assets[${L}]`;if(!x(m)){l(b,"asset must be an object");return}if(E(m.id)?h.has(m.id)?l(`${b}.id`,`duplicate asset id: ${m.id}`):(h.add(m.id),S.set(m.id,m.type)):l(`${b}.id`,"asset.id must be a non-empty string"),Ua.has(m.type)||l(`${b}.type`,"asset.type must be glb or texture"),m.guid!=null&&!E(m.guid)&&l(`${b}.guid`,"asset.guid must be a non-empty string when present"),m.url!=null&&!E(m.url)&&l(`${b}.url`,"url must be a non-empty string when present"),m.external!=null&&!x(m.external)&&l(`${b}.external`,"external must be an object when present"),m.warmupCount!=null&&(!Number.isInteger(m.warmupCount)||m.warmupCount<0)&&l(`${b}.warmupCount`,"warmupCount must be a non-negative integer when present"),m.singleton!=null&&typeof m.singleton!="boolean"&&l(`${b}.singleton`,"singleton must be a boolean when present"),m.materialMode!=null&&!Ba.has(m.materialMode)&&l(`${b}.materialMode`,"materialMode must be shared or instance"),ud(m.defaults,`${b}.defaults`,l),f===3)for(let z of Object.keys(m))qa.has(z)||l(`${b}.${z}`,`runtime schema v3 asset field is not allowed: ${z}`);else m.displayName!=null&&!E(m.displayName)&&l(`${b}.displayName`,"displayName must be a non-empty string when present"),m.category!=null&&!E(m.category)&&l(`${b}.category`,"category must be a non-empty string when present"),m.metadata!=null&&!x(m.metadata)&&l(`${b}.metadata`,"metadata must be an object when present");let j=f===3?m.materialSlots:x(m.metadata)?m.metadata.materialSlots:void 0,W=f===3?`${b}.materialSlots`:`${b}.metadata.materialSlots`,J=new Set;j!=null&&(Array.isArray(j)?j.forEach((z,jt)=>{let We=`${W}[${jt}]`;if(!x(z)||!E(z.slotId)){l(We,f===3?"material slot must contain a stable slotId":"material slot must contain stable slotId and ownerNodePath");return}if(f!==3&&!E(z.ownerNodePath)){l(We,"material slot must contain stable slotId and ownerNodePath");return}J.has(z.slotId)?l(`${We}.slotId`,`duplicate material slot id: ${z.slotId}`):J.add(z.slotId),f===3&&ld(z,We,l)}):l(W,"materialSlots must be an array when present")),E(m.id)&&P.set(m.id,J),d.has(m.id)&&mi(m,b,l)}),p.nodes.forEach((m,L)=>{let b=`$.scene.nodes[${L}]`;if(!x(m)){l(b,"node must be an object");return}E(m.id)&&$.set(m.id,m),E(m.id)?T.has(m.id)?l(`${b}.id`,`duplicate node id: ${m.id}`):(T.add(m.id),typeof m.kind=="string"&&_.set(m.id,m.kind),m.kind==="transform"&&Object.prototype.hasOwnProperty.call(m,"marker")&&q.add(m.id)):l(`${b}.id`,"node.id must be a non-empty string"),La.has(m.kind)||l(`${b}.kind`,"node.kind must be group, instance, transform, primitive, or image")}),p.materialAssets.forEach((m,L)=>{let b=`$.scene.materialAssets[${L}]`;if(!x(m)){l(b,"material asset must be an object");return}E(m.id)?D.has(m.id)?l(`${b}.id`,`duplicate material asset id: ${m.id}`):D.add(m.id):l(`${b}.id`,"material asset id must be a non-empty string"),m.name!=null&&!E(m.name)&&l(`${b}.name`,"material asset name must be a non-empty string when present"),m.guid!=null&&!E(m.guid)&&l(`${b}.guid`,"material asset guid must be a non-empty string when present"),Object.prototype.hasOwnProperty.call(m,"materialKind")&&l(`${b}.materialKind`,"materialKind is not supported; use shaderId"),Object.prototype.hasOwnProperty.call(m,"profile")&&l(`${b}.profile`,"profile is not supported; use properties");let j=Zt(m.shaderId),W=nd(m.shaderId);!j&&!W&&l(`${b}.shaderId`,"shaderId must be a built-in id or a namespaced lowercase project id"),m.definitionVersion!=null&&!rd(m.definitionVersion)?l(`${b}.definitionVersion`,"definitionVersion must be a positive integer when present"):W&&m.definitionVersion==null&&l(`${b}.definitionVersion`,"definitionVersion is required for project shader material assets"),j?pi(m.properties,`${b}.properties`,l):id(m.properties,`${b}.properties`,l);for(let J of Object.keys(m))["id","guid","name","shaderId","definitionVersion","properties","system","origin"].includes(J)||l(`${b}.${J}`,`material asset field is not allowed: ${J}`);od(m.system,`${b}.system`,l),sd(m.origin,`${b}.origin`,l),ad(m,b,l)}),p.nodes.forEach((m,L)=>{if(!x(m))return;let b=`$.scene.nodes[${L}]`,j=Object.prototype.hasOwnProperty.call(m,"parentId");j&&!E(m.parentId)&&l(`${b}.parentId`,"parentId must be a non-empty string when present");let W=j?m.parentId:p.rootId;E(W)&&dd(W,p.rootId,T,`${b}.parentId`,l),E(m.id)&&cd(m.id,p.rootId,$,`${b}.parentId`,l),md(m.source,`${b}.source`,l),hi(m.transform,`${b}.transform`,l),$d(m.rendering,`${b}.rendering`,l),m.shadow!=null&&li(()=>pt(m.shadow,`${b}.shadow`),`${b}.shadow`,l),Object.prototype.hasOwnProperty.call(m,"shadowMode")&&l(`${b}.shadowMode`,"deprecated field; use shadow.mode");let J=null;m.kind==="instance"&&(x(m.instance)?h.has(m.instance.assetId)?S.get(m.instance.assetId)!=="glb"?l(`${b}.instance.assetId`,"instance.assetId must reference a glb asset"):J=E(m.instance.assetId)?m.instance.assetId:null:l(`${b}.instance.assetId`,`assetId must reference scene.assets: ${m.instance.assetId}`):l(`${b}.instance`,"instance node must contain instance object")),m.kind==="primitive"&&(x(m.primitive)?za.has(m.primitive.shape)||l(`${b}.primitive.shape`,"primitive.shape must be cube, sphere, plane, or capsule"):l(`${b}.primitive`,"primitive node must contain primitive object")),m.kind==="image"&&(x(m.image)?(h.has(m.image.assetId)?S.get(m.image.assetId)!=="texture"&&l(`${b}.image.assetId`,"image.assetId must reference a texture asset"):l(`${b}.image.assetId`,`assetId must reference scene.assets: ${m.image.assetId}`),x(m.image.size)?(fi(m.image.size.width)||l(`${b}.image.size.width`,"image.size.width must be positive"),fi(m.image.size.height)||l(`${b}.image.size.height`,"image.size.height must be positive")):l(`${b}.image.size`,"image.size must be an object")):l(`${b}.image`,"image node must contain image object")),m.kind==="transform"&&m.transformType!=null&&!Ha.has(m.transformType)&&l(`${b}.transformType`,"transformType must be plain, light, camera, or groundDecal"),m.kind==="transform"&&m.transformType==="groundDecal"?Ad(m.groundDecal,`${b}.groundDecal`,l):Object.prototype.hasOwnProperty.call(m,"groundDecal")&&l(`${b}.groundDecal`,"groundDecal is only allowed on transform nodes with transformType groundDecal"),m.kind==="transform"&&(xd(m.camera,`${b}.camera`,l),Id(m.light,`${b}.light`,l,g)),Object.prototype.hasOwnProperty.call(m,"marker")&&(m.kind!=="transform"?l(`${b}.marker`,"marker is only allowed on transform nodes"):(gd(m.marker,`${b}.marker`,l),pd(m.marker,m.id,T,q,`${b}.marker`,l))),(m.kind==="instance"||m.kind==="transform"||m.kind==="primitive"||m.kind==="image")&&Qa(m.overrides,`${b}.overrides`,D,J?P.get(J):void 0,f===3?"materialSlots":"metadata.materialSlots",l),u.has(m.id)&&mi(m,b,l)}),p.materials.forEach((m,L)=>{let b=`$.scene.materials[${L}]`;if(!x(m)){l(b,"material must be an object");return}if(E(m.id)||l(`${b}.id`,"material.id must be a non-empty string"),m.scope!=null&&!Va.has(m.scope)&&l(`${b}.scope`,"material scope must be sharedAsset or nodeMaterial"),m.scope==="sharedAsset"&&(!E(m.assetId)||!h.has(m.assetId))&&!n&&l(`${b}.assetId`,`shared material assetId must reference scene.assets: ${m.assetId}`),m.scope==="nodeMaterial"){if((!E(m.nodeId)||!T.has(m.nodeId))&&!r)l(`${b}.nodeId`,`node material nodeId must reference scene.nodes: ${m.nodeId}`);else if(E(m.nodeId)&&T.has(m.nodeId)){let j=_.get(m.nodeId);j!=="instance"&&j!=="transform"&&j!=="primitive"&&l(`${b}.nodeId`,`node material nodeId must reference an instance, transform, or primitive node: ${m.nodeId}`)}}E(m.materialName)||l(`${b}.materialName`,"materialName must be a non-empty string"),x(m.properties)?xi(m.properties,`${b}.properties`,l):l(`${b}.properties`,"properties must be an object")}),c}function Ya(e,t={}){let n=Za(e,t);return{ok:n.length===0,errors:n}}function li(e,t,n){try{e()}catch(r){let i=typeof r?.path=="string"?r.path:t,o=typeof r?.code=="string"?r.code:"schema.invalidValue";n(i,o)}}function Qa(e,t,n,r,i,o){if(e!=null){if(!x(e)){o(t,"overrides must be an object when present");return}gi(e.materialBinding,`${t}.materialBinding`,n,o),ed(e.materialSlotBindings,`${t}.materialSlotBindings`,"slotId",n,r,i,o),Object.prototype.hasOwnProperty.call(e,"childMaterialBindings")&&o(`${t}.childMaterialBindings`,"deprecated field; use materialSlotBindings keyed by slotId"),Object.prototype.hasOwnProperty.call(e,"childMaterials")&&o(`${t}.childMaterials`,"deprecated field; use materialSlotBindings keyed by slotId")}}function ed(e,t,n,r,i,o,s){if(e!=null){if(!x(e)){s(t,"material binding map must be an object when present");return}for(let[a,c]of Object.entries(e)){let d=`${t}.${a}`;E(a)||s(d,`${n} must be a non-empty string`),i?i.has(a)||s(d,`${n} must reference asset ${o}`):s(d,`${n} requires an instance asset with ${o}`),c==null?s(d,"material binding must be an object"):gi(c,d,r,s)}}}function gi(e,t,n,r){if(e!=null){if(!x(e)){r(t,"material binding must be an object when present");return}e.materialAssetId!=null&&(E(e.materialAssetId)?n.has(e.materialAssetId)||r(`${t}.materialAssetId`,`materialAssetId must reference scene.materialAssets: ${e.materialAssetId}`):r(`${t}.materialAssetId`,"materialAssetId must be non-empty when present")),e.override!=null&&pi(e.override,`${t}.override`,r)}}function pi(e,t,n){if(!x(e)){n(t,"material asset profile must be an object");return}if(e.lightingModel!=null&&e.lightingModel!=="lit"&&e.lightingModel!=="unlit"&&n(`${t}.lightingModel`,"lightingModel must be lit or unlit"),e.baseColor!=null)if(!x(e.baseColor))n(`${t}.baseColor`,"baseColor must be an object");else{rn(e.baseColor.color,`${t}.baseColor.color`,n),Le(e.baseColor.texture,`${t}.baseColor.texture`,n);for(let r of["brightness","saturation","contrast","hue"])e.baseColor[r]!=null&&!oe(e.baseColor[r])&&n(`${t}.baseColor.${r}`,`${r} must be a finite number`)}for(let r of["metallic","roughness"])e[r]!=null&&!oe(e[r])&&n(`${t}.${r}`,`${r} must be a finite number`);e.normal!=null&&(x(e.normal)?(Le(e.normal.texture,`${t}.normal.texture`,n),e.normal.strength!=null&&!oe(e.normal.strength)&&n(`${t}.normal.strength`,"normal strength must be a finite number")):n(`${t}.normal`,"normal must be an object")),e.metallicRoughness!=null&&(x(e.metallicRoughness)?Le(e.metallicRoughness.texture,`${t}.metallicRoughness.texture`,n):n(`${t}.metallicRoughness`,"metallicRoughness must be an object")),e.occlusion!=null&&(x(e.occlusion)?(Le(e.occlusion.texture,`${t}.occlusion.texture`,n),e.occlusion.strength!=null&&!oe(e.occlusion.strength)&&n(`${t}.occlusion.strength`,"occlusion strength must be a finite number")):n(`${t}.occlusion`,"occlusion must be an object")),e.emission!=null&&(x(e.emission)?(rn(e.emission.color,`${t}.emission.color`,n),e.emission.intensity!=null&&!oe(e.emission.intensity)&&n(`${t}.emission.intensity`,"emission intensity must be a finite number"),Le(e.emission.texture,`${t}.emission.texture`,n),Le(e.emission.maskTexture,`${t}.emission.maskTexture`,n)):n(`${t}.emission`,"emission must be an object")),e.alpha!=null&&(x(e.alpha)?(e.alpha.mode!=null&&e.alpha.mode!=="opaque"&&e.alpha.mode!=="mask"&&e.alpha.mode!=="blend"&&n(`${t}.alpha.mode`,"alpha mode must be opaque, mask, or blend"),e.alpha.opacity!=null&&!oe(e.alpha.opacity)&&n(`${t}.alpha.opacity`,"alpha opacity must be a finite number"),e.alpha.cutoff!=null&&!oe(e.alpha.cutoff)&&n(`${t}.alpha.cutoff`,"alpha cutoff must be a finite number"),Le(e.alpha.texture,`${t}.alpha.texture`,n)):n(`${t}.alpha`,"alpha must be an object"))}var td=/^[a-z0-9]+(?:[._-][a-z0-9]+)+$/;function Hn(e){return typeof e=="string"&&!e.startsWith("fps.builtin.")&&td.test(e)}function nd(e){return Hn(e)?e:null}function rd(e){return Number.isSafeInteger(e)&&e>0}function id(e,t,n){if(!x(e)){n(t,"project shader material properties must be an object");return}Vn(e,t,n)}function Vn(e,t,n){if(!(e===null||typeof e=="string"||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||n(t,"project shader material numbers must be finite");return}if(Array.isArray(e)){e.forEach((r,i)=>Vn(r,`${t}[${i}]`,n));return}if(x(e)){for(let[r,i]of Object.entries(e))Vn(i,`${t}.${r}`,n);return}n(t,"project shader material properties must be JSON-safe")}}function Le(e,t,n){if(e!=null){if(!x(e)){n(t,"texture ref must be an object");return}e.url!=null&&!E(e.url)&&n(`${t}.url`,"texture url must be non-empty when present"),e.textureAssetId!=null&&!E(e.textureAssetId)&&n(`${t}.textureAssetId`,"textureAssetId must be non-empty when present")}}function od(e,t,n){if(e!=null){if(!x(e)){n(t,"material asset system must be an object");return}e.readonly!=null&&typeof e.readonly!="boolean"&&n(`${t}.readonly`,"readonly must be boolean"),e.preset!=null&&!Ka.has(e.preset)&&n(`${t}.preset`,"preset must be default-pbr or default-standard")}}function sd(e,t,n){if(e!=null){if(!x(e)){n(t,"material asset origin must be an object");return}e.type!=="imported"&&e.type!=="created"&&e.type!=="duplicated"&&e.type!=="preset"&&n(`${t}.type`,"origin type must be imported, created, duplicated, or preset"),e.sourceAssetGuid!=null&&!E(e.sourceAssetGuid)&&n(`${t}.sourceAssetGuid`,"sourceAssetGuid must be non-empty when present"),e.sourceAssetId!=null&&!E(e.sourceAssetId)&&n(`${t}.sourceAssetId`,"sourceAssetId must be non-empty when present"),e.sourceSlotId!=null&&!E(e.sourceSlotId)&&n(`${t}.sourceSlotId`,"sourceSlotId must be non-empty when present"),e.sourceMaterialIndex!=null&&!Number.isInteger(e.sourceMaterialIndex)&&n(`${t}.sourceMaterialIndex`,"sourceMaterialIndex must be an integer when present"),e.sourceMaterialName!=null&&!E(e.sourceMaterialName)&&n(`${t}.sourceMaterialName`,"sourceMaterialName must be non-empty when present"),e.sourceMaterialAssetId!=null&&!E(e.sourceMaterialAssetId)&&n(`${t}.sourceMaterialAssetId`,"sourceMaterialAssetId must be non-empty when present")}}function ad(e,t,n){let r=x(e.system)?e.system.preset:void 0;r==="default-pbr"&&e.shaderId!=="fps.builtin.pbr"&&n(`${t}.shaderId`,"default-pbr material assets must use shaderId fps.builtin.pbr"),r==="default-standard"&&e.shaderId!=="fps.builtin.standard"&&n(`${t}.shaderId`,"default-standard material assets must use shaderId fps.builtin.standard")}function dd(e,t,n,r,i){if(e===t){St.has("root")||i(r,`parentId must point to scene node: ${e}`);return}if(St.has("sceneNode")&&n.has(e))return;let o=St.has("root")&&St.has("sceneNode")?"root or scene node":St.has("sceneNode")?"scene node":"root";i(r,`parentId must point to ${o}: ${e}`)}function cd(e,t,n,r,i){if(!E(t))return;let o=new Set([e]),s=E(n.get(e)?.parentId)?n.get(e)?.parentId:t;for(;E(s)&&s!==t;){if(o.has(s)){i(r,`parentId creates a node cycle involving ${e}`);return}o.add(s);let a=n.get(s);if(!a)return;s=E(a.parentId)?a.parentId:t}}function ld(e,t,n){for(let r of Object.keys(e))Ja.has(r)||n(`${t}.${r}`,`runtime schema v3 material slot field is not allowed: ${r}`);if(e.label!=null&&!E(e.label)&&n(`${t}.label`,"label must be a non-empty string when present"),!Array.isArray(e.sourceSurfaces)||e.sourceSurfaces.length===0){n(`${t}.sourceSurfaces`,"sourceSurfaces must be a non-empty array");return}for(let r=0;r<e.sourceSurfaces.length;r+=1){let i=`${t}.sourceSurfaces[${r}]`,o=e.sourceSurfaces[r];if(!x(o)){n(i,"source surface must be an object");continue}for(let s of Object.keys(o))Xa.has(s)||n(`${i}.${s}`,`runtime schema v3 material slot source surface field is not allowed: ${s}`);E(o.ownerNodePath)||n(`${i}.ownerNodePath`,"ownerNodePath must be a non-empty string");for(let s of["meshIndex","primitiveIndex"])(!Number.isInteger(o[s])||o[s]<0)&&n(`${i}.${s}`,`${s} must be a non-negative integer`);for(let s of["nodeIndex","sourceMaterialIndex"])o[s]!=null&&(!Number.isInteger(o[s])||o[s]<0)&&n(`${i}.${s}`,`${s} must be a non-negative integer when present`);o.nodeIndexPath!=null&&(!Array.isArray(o.nodeIndexPath)||o.nodeIndexPath.some(s=>!Number.isInteger(s)||s<0))&&n(`${i}.nodeIndexPath`,"nodeIndexPath must contain non-negative integers"),E(o.sourceMeshName)||n(`${i}.sourceMeshName`,"sourceMeshName is required")}}function ud(e,t,n){if(e!=null){if(!x(e)){n(t,"defaults must be an object");return}if(hi(e.transform,`${t}.transform`,n),ui(e.outline,`${t}.outline`,n),e.childOutlines!=null)if(!x(e.childOutlines))n(`${t}.childOutlines`,"childOutlines must be an object");else for(let[r,i]of Object.entries(e.childOutlines))ui(i,`${t}.childOutlines.${r}`,n)}}function fd(e,t,n){if(e!=null){if(!x(e)){n(t,"generatedFrom must be an object when present");return}bi(e,t,n),E(e.compilerId)||n(`${t}.compilerId`,"compilerId must be a non-empty string"),E(e.compilerVersion)||n(`${t}.compilerVersion`,"compilerVersion must be a non-empty string"),E(e.compiledAt)||n(`${t}.compiledAt`,"compiledAt must be a non-empty string")}}function md(e,t,n){if(e!=null){if(!x(e)){n(t,"source must be an object when present");return}bi(e,t,n),e.objectGuid!=null&&!E(e.objectGuid)&&n(`${t}.objectGuid`,"objectGuid must be a non-empty string when present"),e.objectId!=null&&!E(e.objectId)&&n(`${t}.objectId`,"objectId must be a non-empty string when present"),e.component!=null&&!E(e.component)&&n(`${t}.component`,"component must be a non-empty string when present"),e.propertyPath!=null&&!E(e.propertyPath)&&n(`${t}.propertyPath`,"propertyPath must be a non-empty string when present")}}function bi(e,t,n){E(e.sourceId)||n(`${t}.sourceId`,"sourceId must be a non-empty string"),E(e.sourceType)||n(`${t}.sourceType`,"sourceType must be a non-empty string"),e.revision!=null&&(typeof e.revision!="number"||!Number.isFinite(e.revision))&&n(`${t}.revision`,"revision must be a finite number when present")}function yi(e,t){let n=Ya(e,t);if(n.ok)return;let r=new Error(`scene_json_schema_failed:
|
|
3
|
+
${JSON.stringify(n.errors,null,2)}`);throw Object.assign(r,{code:"scene_json_schema_failed",diagnostics:n.errors}),r}function x(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function E(e){return typeof e=="string"&&e.trim().length>0}function hi(e,t,n){if(e!=null){if(!x(e)){n(t,"transform must be an object");return}Se(e.position,`${t}.position`,n),Se(e.rotation,`${t}.rotation`,n),Se(e.rotationDeg,`${t}.rotationDeg`,n),typeof e.scale=="number"?Number.isFinite(e.scale)||n(`${t}.scale`,"scale number must be finite"):Se(e.scale,`${t}.scale`,n)}}function gd(e,t,n){if(!x(e)){n(t,"marker must be an object");return}Re(e,["schemaVersion","label","type","kind","tags","note","color","target","semanticFrame","geometry","metadata"],t,n),e.schemaVersion!==1&&n(`${t}.schemaVersion`,"marker.schemaVersion must be 1"),E(e.label)||n(`${t}.label`,"marker.label must be a non-empty string"),E(e.type)||n(`${t}.type`,"marker.type must be a non-empty string"),e.kind!=null&&!E(e.kind)&&n(`${t}.kind`,"marker.kind must be a non-empty string when present"),e.tags!=null&&(Array.isArray(e.tags)?e.tags.forEach((r,i)=>{typeof r!="string"&&n(`${t}.tags[${i}]`,"marker tag must be a string")}):n(`${t}.tags`,"marker.tags must be an array when present")),e.note!=null&&typeof e.note!="string"&&n(`${t}.note`,"marker.note must be a string when present"),e.color!=null&&hd(e.color,`${t}.color`,n),e.target!=null&&Kn(e.target,`${t}.target`,n),e.semanticFrame!=null&&bd(e.semanticFrame,`${t}.semanticFrame`,n),yd(e.geometry,`${t}.geometry`,n),e.metadata!=null&&!x(e.metadata)&&n(`${t}.metadata`,"marker.metadata must be an object when present")}function pd(e,t,n,r,i,o){if(!x(e))return;let s=[];e.target!=null&&s.push({value:e.target,path:`${i}.target`}),x(e.geometry)&&e.geometry.target!=null&&s.push({value:e.geometry.target,path:`${i}.geometry.target`});for(let a of s)x(a.value)&&(a.value.kind!=="scene-object"&&a.value.kind!=="marker"&&o(`${a.path}.kind`,"runtime marker target kind must be scene-object or marker"),E(a.value.id)&&(a.value.id===t?o(`${a.path}.id`,"runtime marker target must not reference its marker node"):n.has(a.value.id)?a.value.kind==="marker"&&!r.has(a.value.id)?o(`${a.path}.id`,`runtime marker target must reference a marker node: ${a.value.id}`):a.value.kind==="scene-object"&&r.has(a.value.id)&&o(`${a.path}.id`,`runtime scene-object target must not reference a marker node: ${a.value.id}`):o(`${a.path}.id`,`runtime marker target must reference scene.nodes: ${a.value.id}`)))}function Kn(e,t,n){if(!x(e)){n(t,"marker target must be an object");return}Re(e,["kind","id","label","path","metadata"],t,n),E(e.kind)||n(`${t}.kind`,"marker target kind must be a non-empty string"),E(e.id)||n(`${t}.id`,"marker target id must be a non-empty string");for(let r of["label","path"])e[r]!=null&&typeof e[r]!="string"&&n(`${t}.${r}`,`marker target ${r} must be a string when present`);e.metadata!=null&&!x(e.metadata)&&n(`${t}.metadata`,"marker target metadata must be an object when present")}function bd(e,t,n){if(!x(e)){n(t,"marker semanticFrame must be an object");return}Re(e,["origin","forward","right","up","label","description"],t,n),x(e.origin)?Se(e.origin,`${t}.origin`,n):n(`${t}.origin`,"marker semanticFrame.origin must be a vector object");for(let r of["forward","right","up"])e[r]!=null&&Se(e[r],`${t}.${r}`,n);for(let r of["label","description"])e[r]!=null&&typeof e[r]!="string"&&n(`${t}.${r}`,`marker semanticFrame ${r} must be a string when present`)}function yd(e,t,n){if(!x(e)){n(t,"marker.geometry must be an object");return}if(e.kind==="box"){Re(e,["kind"],t,n);return}if(e.kind==="point"){Re(e,["kind","coordinateSpace","position","offset","target"],t,n),e.coordinateSpace!=null&&e.coordinateSpace!=="world"&&e.coordinateSpace!=="local"&&n(`${t}.coordinateSpace`,"point marker coordinateSpace must be world or local"),e.position!=null&&Se(e.position,`${t}.position`,n),e.offset!=null&&Se(e.offset,`${t}.offset`,n),e.target!=null&&Kn(e.target,`${t}.target`,n);return}if(e.kind==="object-bounds"){Re(e,["kind","target"],t,n),Kn(e.target,`${t}.target`,n);return}if(e.kind==="polyhedron"){Re(e,["kind","coordinateSpace","vertices","faces"],t,n),e.coordinateSpace!=null&&e.coordinateSpace!=="world"&&n(`${t}.coordinateSpace`,"polyhedron marker coordinateSpace must be world"),Array.isArray(e.vertices)?e.vertices.forEach((r,i)=>{let o=`${t}.vertices[${i}]`;x(r)?Se(r,o,n):n(o,"polyhedron marker vertex must be a vector object")}):n(`${t}.vertices`,"polyhedron marker vertices must be an array"),e.faces!=null&&(Array.isArray(e.faces)?e.faces.forEach((r,i)=>{Array.isArray(r)?r.forEach((o,s)=>{(!Number.isInteger(o)||o<0)&&n(`${t}.faces[${i}][${s}]`,"polyhedron marker index must be a non-negative integer")}):n(`${t}.faces[${i}]`,"polyhedron marker face must be an array")}):n(`${t}.faces`,"polyhedron marker faces must be an array when present"));return}n(`${t}.kind`,"marker.geometry.kind must be box, point, object-bounds, or polyhedron")}function hd(e,t,n){if(!x(e)){n(t,"marker color must be an object");return}Re(e,["r","g","b"],t,n);for(let r of["r","g","b"])Si(e[r])||n(`${t}.${r}`,"marker color component must be between 0 and 1")}function Re(e,t,n,r){let i=new Set(t);for(let o of Object.keys(e))i.has(o)||r(`${n}.${o}`,`field is not allowed: ${o}`)}function Se(e,t,n){if(e!=null){if(!x(e)){n(t,"value must be a vector object");return}for(let r of["x","y","z"])(typeof e[r]!="number"||!Number.isFinite(e[r]))&&n(`${t}.${r}`,"vector component must be a finite number")}}function Sd(e,t,n){if(e!=null){if(!x(e)){n(t,"value must be a vector object");return}for(let r of["x","y"])(typeof e[r]!="number"||!Number.isFinite(e[r]))&&n(`${t}.${r}`,"vector component must be a finite number")}}function oe(e){return typeof e=="number"&&Number.isFinite(e)}function ze(e){return oe(e)&&e>0}function Si(e){return oe(e)&&e>=0&&e<=1}function rn(e,t,n){if(e!=null){if(!x(e)){n(t,"color must be an object");return}for(let r of["r","g","b"])(typeof e[r]!="number"||!Number.isFinite(e[r]))&&n(`${t}.${r}`,"color component must be a finite number")}}function xd(e,t,n){if(e!=null){if(!x(e)){n(t,"camera must be an object");return}e.projection!=null&&e.projection!=="orthographic"&&e.projection!=="perspective"&&n(`${t}.projection`,"camera projection must be orthographic or perspective");for(let r of["alpha","beta"])e[r]!=null&&!oe(e[r])&&n(`${t}.${r}`,"camera property must be a finite number when present");for(let r of["radius","orthoSize"])e[r]!=null&&!ze(e[r])&&n(`${t}.${r}`,"camera property must be a positive finite number when present");e.fov!=null&&!ze(e.fov)&&n(`${t}.fov`,"camera fov must be a positive finite number"),Se(e.targetOffset,`${t}.targetOffset`,n),Sd(e.targetScreenOffset,`${t}.targetScreenOffset`,n);for(let r of["minZ","maxZ","lowerRadiusLimit","upperRadiusLimit"])e[r]!=null&&!ze(e[r])&&n(`${t}.${r}`,"camera property must be a positive finite number");for(let r of["lowerBetaLimit","upperBetaLimit"])e[r]!=null&&!oe(e[r])&&n(`${t}.${r}`,"camera property must be a finite number");e.inertia!=null&&!Si(e.inertia)&&n(`${t}.inertia`,"camera inertia must be between 0 and 1"),ze(e.minZ)&&ze(e.maxZ)&&e.maxZ<=e.minZ&&n(`${t}.maxZ`,"camera maxZ must be greater than minZ"),oe(e.lowerBetaLimit)&&oe(e.upperBetaLimit)&&e.upperBetaLimit<e.lowerBetaLimit&&n(`${t}.upperBetaLimit`,"camera upperBetaLimit must be greater than or equal to lowerBetaLimit"),ze(e.lowerRadiusLimit)&&ze(e.upperRadiusLimit)&&e.upperRadiusLimit<e.lowerRadiusLimit&&n(`${t}.upperRadiusLimit`,"camera upperRadiusLimit must be greater than or equal to lowerRadiusLimit")}}function Pd(e){let t=e.meta?.generatedFrom;return x(t)&&t.compilerId===ja&&t.compilerVersion===Fa}function Id(e,t,n,r=!1){if(e==null)return;let i=r&&x(e)&&!Object.prototype.hasOwnProperty.call(e,"schemaVersion")?Ed(e,t):e;try{qe(i,t)}catch(o){let s=o;n(typeof s.path=="string"?s.path:t,typeof s.reason=="string"?s.reason:typeof s.message=="string"?s.message:"light does not satisfy the Engine Runtime Light contract")}}function Ed(e,t){let n={...e,schemaVersion:1};if(e.type!=="directional"||!x(e.direction))return n;let{x:r,y:i,z:o}=e.direction;if(![r,i,o].every(a=>typeof a=="number"&&Number.isFinite(a)))return n;let s=Math.hypot(r,i,o);return s<=0||Math.abs(s-1)>_a?n:{...n,direction:ft(e.direction,`${t}.direction`)}}function ui(e,t,n){if(e!=null){if(!x(e)){n(t,"outline must be an object");return}e.renderOutline!=null&&typeof e.renderOutline!="boolean"&&n(`${t}.renderOutline`,"renderOutline must be boolean"),e.outlineWidth!=null&&(typeof e.outlineWidth!="number"||!Number.isFinite(e.outlineWidth))&&n(`${t}.outlineWidth`,"outlineWidth must be a finite number"),rn(e.outlineColor,`${t}.outlineColor`,n)}}function Ad(e,t,n){if(e==null){n(t,"groundDecal is required when transformType is groundDecal");return}if(!x(e)){n(t,"groundDecal must be an object");return}wd(e,t,n)}function wd(e,t,n){if(E(e.uiKind)||n(`${t}.uiKind`,"groundDecal UI kind must be non-empty"),!x(e.size))n(`${t}.size`,"groundDecal.size must be an object");else for(let r of["width","depth"])(typeof e.size[r]!="number"||!Number.isFinite(e.size[r])||e.size[r]<=0)&&n(`${t}.size.${r}`,"groundDecal size must be a positive finite number");if(e.aspectSourceLayerId!=null&&!E(e.aspectSourceLayerId)&&n(`${t}.aspectSourceLayerId`,"aspectSourceLayerId must be non-empty when present"),e.lockAspectToBorder!=null&&typeof e.lockAspectToBorder!="boolean"&&n(`${t}.lockAspectToBorder`,"lockAspectToBorder must be boolean when present"),e.editorPreviewActive!=null&&n(`${t}.editorPreviewActive`,"editorPreviewActive is editor-only and must not appear in runtime scene data"),Td(e.mask,`${t}.mask`,n),Dd(e.rendering,`${t}.rendering`,n),!Array.isArray(e.layers)){n(`${t}.layers`,"groundDecal UI layers must be an array");return}e.layers.forEach((r,i)=>kd(r,`${t}.layers[${i}]`,n)),Md(e.layers,`${t}.layers`,n)}function Td(e,t,n){if(e!=null){if(!x(e)){n(t,"groundDecal UI mask must be an object");return}e.enabled!=null&&typeof e.enabled!="boolean"&&n(`${t}.enabled`,"mask.enabled must be boolean"),e.source!=null&&e.source!=="roundedRect"&&e.source!=="borderAlpha"&&e.source!=="texture"&&n(`${t}.source`,"mask.source must be roundedRect, borderAlpha, or texture"),e.textureId!=null&&!E(e.textureId)&&n(`${t}.textureId`,"mask.textureId must be non-empty when present");for(let r of["cornerRadius","padding"])e[r]!=null&&(typeof e[r]!="number"||!Number.isFinite(e[r])||e[r]<0)&&n(`${t}.${r}`,`${r} must be a non-negative finite number`)}}function Dd(e,t,n){if(e!=null){if(!x(e)){n(t,"groundDecal UI rendering must be an object");return}for(let r of["textureWidth","textureHeight"])e[r]!=null&&(!Number.isInteger(e[r])||e[r]<=0)&&n(`${t}.${r}`,`${r} must be a positive integer`);for(let r of["alphaIndex","diffuseTextureLevel","emissiveTextureLevel"])e[r]!=null&&(typeof e[r]!="number"||!Number.isFinite(e[r]))&&n(`${t}.${r}`,`${r} must be a finite number`)}}function kd(e,t,n){if(!x(e)){n(t,"groundDecal UI layer must be an object");return}E(e.id)||n(`${t}.id`,"layer.id must be non-empty"),E(e.role)||n(`${t}.role`,"layer.role must be non-empty"),e.editorPreviewPercent!=null&&n(`${t}.editorPreviewPercent`,"editorPreviewPercent is editor-only and must not appear in runtime scene data"),e.enabled!=null&&typeof e.enabled!="boolean"&&n(`${t}.enabled`,"layer.enabled must be boolean"),(typeof e.zOrder!="number"||!Number.isFinite(e.zOrder))&&n(`${t}.zOrder`,"layer.zOrder must be a finite number"),e.opacity!=null&&(typeof e.opacity!="number"||!Number.isFinite(e.opacity))&&n(`${t}.opacity`,"layer.opacity must be finite"),e.rotationDeg!=null&&(typeof e.rotationDeg!="number"||!Number.isFinite(e.rotationDeg)||e.rotationDeg<=-180||e.rotationDeg>180)&&n(`${t}.rotationDeg`,"layer.rotationDeg must be in the range (-180, 180]"),Cd(e.rect,`${t}.rect`,n),e.kind==="texture"?(e.textureId!=null&&!E(e.textureId)&&n(`${t}.textureId`,"texture layer textureId must be non-empty when present"),e.imageFit!=null&&e.imageFit!=="contain"&&e.imageFit!=="stretch"&&n(`${t}.imageFit`,"texture layer imageFit must be contain or stretch"),Ze(e.tint,`${t}.tint`,n)):e.kind==="textureProgress"?(e.textureId!=null&&!E(e.textureId)&&n(`${t}.textureId`,"texture progress layer textureId must be non-empty when present"),e.imageFit!=null&&e.imageFit!=="contain"&&e.imageFit!=="stretch"&&n(`${t}.imageFit`,"texture progress layer imageFit must be contain or stretch"),(typeof e.value!="number"||!Number.isFinite(e.value)||e.value<0||e.value>1)&&n(`${t}.value`,"texture progress value must be between 0 and 1"),e.direction!=null&&!["leftToRight","rightToLeft","bottomToTop","topToBottom"].includes(String(e.direction))&&n(`${t}.direction`,"texture progress direction is invalid"),Ze(e.tint,`${t}.tint`,n)):e.kind==="color"?Ze(e.color,`${t}.color`,n):e.kind==="progress"?((typeof e.value!="number"||!Number.isFinite(e.value)||e.value<0||e.value>1)&&n(`${t}.value`,"progress value must be between 0 and 1"),e.direction!=null&&!["leftToRight","rightToLeft","bottomToTop","topToBottom"].includes(String(e.direction))&&n(`${t}.direction`,"progress direction is invalid"),Ze(e.color,`${t}.color`,n)):e.kind==="text"?Rd(e.text,`${t}.text`,n):n(`${t}.kind`,"layer.kind must be texture, textureProgress, color, progress, or text")}function Md(e,t,n){let r=new Map;e.forEach((i,o)=>{if(!x(i)||!E(i.id))return;let s=r.get(i.id);if(s!=null){n(`${t}[${o}].id`,`layer.id must be unique; duplicate of layers[${s}]`);return}r.set(i.id,o)})}function Cd(e,t,n){if(!x(e)){n(t,"layer.rect must be an object");return}for(let r of["x","z","width","depth"])(typeof e[r]!="number"||!Number.isFinite(e[r]))&&n(`${t}.${r}`,`rect.${r} must be a finite number`);for(let r of["width","depth"])typeof e[r]=="number"&&e[r]<=0&&n(`${t}.${r}`,`rect.${r} must be positive`)}function Rd(e,t,n){if(!x(e)){n(t,"text layer text must be an object");return}typeof e.value!="string"&&n(`${t}.value`,"text.value must be a string"),e.fontFamily!=null&&typeof e.fontFamily!="string"&&n(`${t}.fontFamily`,"fontFamily must be a string"),e.fontSize!=null&&(typeof e.fontSize!="number"||!Number.isFinite(e.fontSize)||e.fontSize<=0)&&n(`${t}.fontSize`,"fontSize must be a positive finite number"),e.fontWeight!=null&&typeof e.fontWeight!="string"&&n(`${t}.fontWeight`,"fontWeight must be a string"),Ze(e.color,`${t}.color`,n),Ze(e.strokeColor,`${t}.strokeColor`,n),e.strokeWidth!=null&&(typeof e.strokeWidth!="number"||!Number.isFinite(e.strokeWidth)||e.strokeWidth<0)&&n(`${t}.strokeWidth`,"strokeWidth must be a non-negative finite number")}function Ze(e,t,n){if(e!=null){if(!x(e)){n(t,"color must be an object");return}for(let r of["r","g","b"])(typeof e[r]!="number"||!Number.isFinite(e[r]))&&n(`${t}.${r}`,`color.${r} must be finite`);e.a!=null&&(typeof e.a!="number"||!Number.isFinite(e.a))&&n(`${t}.a`,"color.a must be finite")}}function $d(e,t,n){if(e!=null){if(!x(e)){n(t,"rendering must be an object");return}e.renderingGroupId!=null&&e.renderingGroupId!==0&&e.renderingGroupId!==1&&e.renderingGroupId!==2&&e.renderingGroupId!==3&&n(`${t}.renderingGroupId`,"renderingGroupId must be 0, 1, 2, or 3"),e.alphaIndex!=null&&(typeof e.alphaIndex!="number"||!Number.isFinite(e.alphaIndex))&&n(`${t}.alphaIndex`,"alphaIndex must be a finite number")}}function fi(e){return typeof e=="number"&&Number.isFinite(e)&&e>0}function xi(e,t,n){for(let[r,i]of Object.entries(e)){let o=`${t}.${r}`;["albedoColor","diffuseColor","emissiveColor","outlineColor"].includes(r)&&rn(i,o,n),["metallic","roughness","contrast","brightness","saturation","hue","colorDensity","alpha","alphaCutOff","transparencyMode"].includes(r)&&(typeof i!="number"||!Number.isFinite(i))&&n(o,`${r} must be a finite number`),r==="backFaceCulling"&&typeof i!="boolean"&&n(o,"backFaceCulling must be boolean"),["albedoTexture","normalTexture","metallicTexture"].includes(r)&&(x(i)?i.url!=null&&!E(i.url)&&n(`${o}.url`,"texture url must be non-empty when present"):n(o,`${r} must be an object`)),["pbr","standard"].includes(r)&&(x(i)?xi(i,o,n):n(o,`${r} must be an object`))}}function mi(e,t,n){let r=JSON.stringify(e),i=Wa.filter(o=>r.includes(o));i.length>0&&n(t,`contains runtime-only asset fields: ${i.join(", ")}`)}function Nd(e,t,n){let r=Pi(e)??512,i=Pi(t)??512;if(!Number.isFinite(n)||n<=0)return{width:r,height:i};let o=r,s=Math.max(1,Math.round(o/n));return s>i&&(s=i,o=Math.max(1,Math.round(s*n))),{width:o,height:s}}function Ii(e){let t=e.rendering?.textureWidth??512,n=e.rendering?.textureHeight??512,r=e.size.width>0&&e.size.depth>0?e.size.width/e.size.depth:t/n;return Nd(t,n,r)}function Pi(e){return typeof e!="number"||!Number.isFinite(e)||e<=0?null:Math.max(64,Math.min(2048,Math.round(e)))}var me=(e,t)=>({kind:"number",...e!=null?{min:e}:{},...t!=null?{max:t}:{}}),Ue={kind:"texture"},Ei={kind:"color"},Od={kind:"enum",values:["lit","unlit"]},vd={kind:"enum",values:["opaque","mask","blend"]},Ti={lightingModel:Od,baseColor:{kind:"object",properties:{color:Ei,texture:Ue,brightness:me(0),saturation:me(0),contrast:me(0),hue:me(-180,180)}},normal:{kind:"object",properties:{texture:Ue,strength:me(0)}},emission:{kind:"object",properties:{color:Ei,intensity:me(0),texture:Ue,maskTexture:Ue}},alpha:{kind:"object",properties:{mode:vd,opacity:me(0,1),cutoff:me(0,1),texture:Ue}}},Gd={kind:"object",properties:{...Ti,metallic:me(0,1),roughness:me(0,1),metallicRoughness:{kind:"object",properties:{texture:Ue}},occlusion:{kind:"object",properties:{texture:Ue,strength:me(0)}}}},jd={kind:"object",properties:Ti},Fd={lightingModel:"lit",baseColor:{color:{r:1,g:1,b:1},brightness:1,saturation:1,contrast:1,hue:0},metallic:0,roughness:1,emission:{color:{r:0,g:0,b:0},intensity:0}},_d={lightingModel:"lit",baseColor:{color:{r:1,g:1,b:1},brightness:1,saturation:1,contrast:1,hue:0},emission:{color:{r:0,g:0,b:0},intensity:0}},Ai=[{id:"surface",title:"Surface",order:40},{id:"geometry",title:"Geometry",order:50},{id:"emission",title:"Emission",order:60},{id:"alpha",title:"Alpha",order:70}],Be={path:"properties.lightingModel",operator:"equals",value:"lit",inactiveReasonKey:"litMaterial"},Di=[Qe("properties.lightingModel","surface",1,"enum","assetLightingModel","lightingModel","lit",{options:[{value:"lit",labelKey:"assetLightingModelLit"},{value:"unlit",labelKey:"assetLightingModelUnlit"}],binding:"lightingModel",updateClass:"define"}),Qe("properties.baseColor.color","surface",2,"color","assetBaseColor","baseColor",{r:1,g:1,b:1},{binding:"baseColor.color"}),et("properties.baseColor.texture.textureAssetId","properties.baseColor.texture","surface",3,"assetBaseTexture","baseTexture","baseColor.texture"),ge("properties.baseColor.brightness","surface",4,"assetBrightness","brightness",1,{softMin:0,softMax:4,step:.05,conditions:[Ye("properties.baseColor.texture.textureAssetId","baseTexture")]}),ge("properties.baseColor.saturation","surface",5,"assetSaturation","saturation",1,{softMin:0,softMax:2,step:.05,conditions:[Ye("properties.baseColor.texture.textureAssetId","baseTexture")]}),ge("properties.baseColor.contrast","surface",6,"assetContrast","contrast",1,{softMin:0,softMax:2,step:.05,conditions:[Ye("properties.baseColor.texture.textureAssetId","baseTexture")]}),ge("properties.baseColor.hue","surface",7,"assetHue","hue",0,{step:1,conditions:[Ye("properties.baseColor.texture.textureAssetId","baseTexture")]}),et("properties.normal.texture.textureAssetId","properties.normal.texture","geometry",10,"assetNormalTexture","normalTexture","normal.texture",[Be]),ge("properties.normal.strength","geometry",11,"assetNormalStrength","normalStrength",1,{softMin:0,softMax:4,step:.05,conditions:[Be,Ye("properties.normal.texture.textureAssetId","normalTexture")]}),Qe("properties.emission.color","emission",50,"color","assetEmissionColor","emissionColor",{r:0,g:0,b:0},{binding:"emission.color"}),ge("properties.emission.intensity","emission",51,"assetEmissionIntensity","emissionIntensity",0,{softMin:0,softMax:8,step:.05}),et("properties.emission.texture.textureAssetId","properties.emission.texture","emission",52,"assetEmissionTexture","emissionTexture","emission.texture"),Qe("properties.alpha.mode","alpha",60,"enum","assetAlphaMode","alphaMode","opaque",{options:[{value:"opaque",labelKey:"assetAlphaModeOpaque"},{value:"mask",labelKey:"assetAlphaModeMask"},{value:"blend",labelKey:"assetAlphaModeBlend"}],binding:"alpha.mode",updateClass:"pipeline"}),ge("properties.alpha.opacity","alpha",61,"assetAlphaOpacity","alphaOpacity",1,{step:.05,conditions:[{path:"properties.alpha.mode",operator:"equals",value:"blend",inactiveReasonKey:"alphaBlend"}]}),ge("properties.alpha.cutoff","alpha",62,"assetAlphaCutoff","alphaCutoff",.5,{step:.01,conditions:[{path:"properties.alpha.mode",operator:"equals",value:"mask",inactiveReasonKey:"alphaMask"}]}),et("properties.alpha.texture.textureAssetId","properties.alpha.texture","alpha",63,"assetAlphaTexture","alphaTexture","alpha.texture",[{path:"properties.alpha.mode",operator:"not-equals",value:"opaque",inactiveReasonKey:"alphaTransparency"}])],Ld=[...Di,ge("properties.metallic","geometry",20,"assetMetallic","metallic",0,{step:.05,conditions:[Be]}),ge("properties.roughness","geometry",21,"assetRoughness","roughness",1,{step:.05,conditions:[Be]}),et("properties.metallicRoughness.texture.textureAssetId","properties.metallicRoughness.texture","geometry",22,"assetMetallicRoughnessTexture","metallicRoughnessTexture","metallicRoughness.texture",[Be]),et("properties.occlusion.texture.textureAssetId","properties.occlusion.texture","geometry",23,"assetOcclusionTexture","occlusionTexture","occlusion.texture",[Be]),ge("properties.occlusion.strength","geometry",24,"assetOcclusionStrength","occlusionStrength",1,{softMin:0,softMax:4,step:.05,conditions:[Be,Ye("properties.occlusion.texture.textureAssetId","occlusionTexture")]})],zd=[{shaderId:"fps.builtin.pbr",version:1,runtimeKind:"pbr",displayName:"PBR",propertiesSchema:Gd,defaultProperties:Fd,inspector:{sections:Ai,fields:Ld}},{shaderId:"fps.builtin.standard",version:1,runtimeKind:"standard",displayName:"Standard",propertiesSchema:jd,defaultProperties:_d,inspector:{sections:Ai,fields:Di}}],ki=Ud(zd);function Ud(e){let t=new Map;for(let r of e){Bd(r,t);let i=Vd(r);t.set(r.shaderId,$i(i))}let n=Object.freeze([...t.values()]);return Object.freeze({get(r){return typeof r=="string"?t.get(r)??null:null},list(){return n}})}function Mi(e,t=ki){return t.get(e)}function on(e){return Mi(e)}function sn(e,t,n="properties",r=ki){let i=Mi(e,r);if(!i)return[{path:"shaderId",message:`Unknown material shader: ${String(e)}`}];let o=[];return qn(i.propertiesSchema,t,n,o),o}function Qe(e,t,n,r,i,o,s,a){return{path:e,sectionId:t,order:n,control:r,labelKey:i,tooltipKey:o,defaultValue:s,updateClass:"uniform",...a}}function ge(e,t,n,r,i,o,s={}){return Qe(e,t,n,"number",r,i,o,{binding:e.replace(/^properties\./,""),step:s.step??.05,displayPrecision:2,precision:2,...s})}function et(e,t,n,r,i,o,s,a){return Qe(e,n,r,"texture",i,o,"",{schemaPath:t,binding:s,updateClass:"texture",...a?{conditions:a}:{}})}function Ye(e,t){return{path:e,operator:"truthy",inactiveReasonKey:t}}function Bd(e,t){if(!Zt(e.shaderId)&&!Hn(e.shaderId))throw new Error("Material Shader Definition shaderId must be a supported built-in id or a lowercase namespaced project id.");if(!Number.isInteger(e.version)||e.version<=0)throw new Error(`Material Shader Definition ${e.shaderId} must use a positive integer version.`);if(t.has(e.shaderId))throw new Error(`Duplicate Material Shader Definition: ${e.shaderId}`);if(e.sourceFile!=null&&!Hd(e.sourceFile))throw new Error(`Material Shader Definition ${e.shaderId} sourceFile must be a safe project-relative path.`);Ci(e.shaderId,e.propertiesSchema,"properties");let n=[];if(qn(e.propertiesSchema,e.defaultProperties,"properties",n),n.length>0){let o=n[0];throw new Error(`Material Shader Definition ${e.shaderId} default ${o.path} ${o.message}.`)}let r=new Set;for(let o of e.inspector.sections){if(!o.id.trim()||r.has(o.id))throw new Error(`Material Shader Definition ${e.shaderId} contains an invalid or duplicate section: ${o.id}`);r.add(o.id)}let i=new Set;for(let o of e.inspector.fields){if(!o.path.startsWith("properties.")||i.has(o.path))throw new Error(`Material Shader Definition ${e.shaderId} contains an invalid or duplicate field: ${o.path}`);if(!r.has(o.sectionId))throw new Error(`Material Shader Definition ${e.shaderId} field ${o.path} references an unknown section.`);Kd(e,o),i.add(o.path)}}function Vd(e){let t=structuredClone(e);return{...t,inspector:{...t.inspector,fields:t.inspector.fields.map(n=>{if(n.control!=="number")return n;let r=Ri(t.propertiesSchema,n.schemaPath??n.path);return r?.kind!=="number"?n:{...n,...r.min!=null?{min:r.min}:{},...r.max!=null?{max:r.max}:{}}})}}}function Kd(e,t){let n=[["min",t.min],["max",t.max],["softMin",t.softMin],["softMax",t.softMax]];for(let[i,o]of n)if(o!=null&&!Number.isFinite(o))throw new Error(`Material Shader Definition ${e.shaderId} field ${t.path} ${i} must be finite.`);if(t.control!=="number"){if(n.some(([,i])=>i!=null))throw new Error(`Material Shader Definition ${e.shaderId} field ${t.path} uses numeric ranges with a non-number control.`);return}let r=Ri(e.propertiesSchema,t.schemaPath??t.path);if(r?.kind!=="number")throw new Error(`Material Shader Definition ${e.shaderId} field ${t.path} must reference a number schema.`);for(let[i,o,s]of[["min",t.min,r.min],["max",t.max,r.max]])if(o!=null&&o!==s)throw new Error(`Material Shader Definition ${e.shaderId} field ${t.path} ${i} must match propertiesSchema.`);if(t.softMin!=null&&t.softMax!=null&&t.softMin>t.softMax)throw new Error(`Material Shader Definition ${e.shaderId} field ${t.path} softMin must not exceed softMax.`);if(r.min!=null&&t.softMin!=null&&t.softMin<r.min)throw new Error(`Material Shader Definition ${e.shaderId} field ${t.path} softMin must not be below the schema minimum.`);if(r.max!=null&&t.softMax!=null&&t.softMax>r.max)throw new Error(`Material Shader Definition ${e.shaderId} field ${t.path} softMax must not exceed the schema maximum.`)}function Ci(e,t,n){if(t.kind==="object"){for(let[r,i]of Object.entries(t.properties))Ci(e,i,`${n}.${r}`);return}if(t.kind==="number"){if(t.min!=null&&!Number.isFinite(t.min))throw new Error(`Material Shader Definition ${e} number field ${n} min must be finite.`);if(t.max!=null&&!Number.isFinite(t.max))throw new Error(`Material Shader Definition ${e} number field ${n} max must be finite.`);if(t.min!=null&&t.max!=null&&t.min>t.max)throw new Error(`Material Shader Definition ${e} number field ${n} min must not exceed max.`);return}if(t.kind==="color"&&t.channels!=null&&t.channels!==3&&t.channels!==4)throw new Error(`Material Shader Definition ${e} color field ${n} channels must be 3 or 4.`)}function Hd(e){let t=e.trim();return!t||t.startsWith("/")||t.includes("\\")||t.includes(":")?!1:!t.split("/").includes("..")}function Wd(e){let t=e.trim();return t.startsWith("properties.")?t:`properties.${t}`}function Ri(e,t){let n=Wd(t).replace(/^properties\./,"").split(".").filter(Boolean);if(n.length===0)return null;let r=e;for(let i of n){if(r.kind!=="object")return null;let o=r.properties[i];if(!o)return null;r=o}return r}function qn(e,t,n,r){if(e.kind==="object"){if(!Wn(t)){r.push({path:n,message:"must be an object"});return}for(let o of Object.keys(t))Object.prototype.hasOwnProperty.call(e.properties,o)||r.push({path:`${n}.${o}`,message:"is not supported by the selected shader"});for(let[o,s]of Object.entries(e.properties))t[o]!==void 0&&qn(s,t[o],`${n}.${o}`,r);return}if(e.kind==="number"){if(typeof t!="number"||!Number.isFinite(t)){r.push({path:n,message:"must be a finite number"});return}e.min!=null&&t<e.min&&r.push({path:n,message:`must be greater than or equal to ${e.min}`}),e.max!=null&&t>e.max&&r.push({path:n,message:`must be less than or equal to ${e.max}`});return}if(e.kind==="boolean"){typeof t!="boolean"&&r.push({path:n,message:"must be a boolean"});return}if(e.kind==="string"){t!==null&&typeof t!="string"?r.push({path:n,message:"must be a string"}):t===null&&!e.nullable&&r.push({path:n,message:"must not be null"});return}if(e.kind==="enum"){(typeof t!="string"||!e.values.includes(t))&&r.push({path:n,message:`must be one of: ${e.values.join(", ")}`});return}if(e.kind==="color"){let o=e.channels===4?["r","g","b","a"]:["r","g","b"];wi(t,n,o,r,e.channels===4?"an RGBA object":"an RGB object");return}if(e.kind==="vec2"||e.kind==="vec3"){wi(t,n,e.kind==="vec2"?["x","y"]:["x","y","z"],r,`a ${e.kind} object`);return}if(t===null)return;if(!Wn(t)){r.push({path:n,message:"must be a texture reference object or null"});return}Object.keys(t).some(o=>o!=="url"&&o!=="textureAssetId")&&r.push({path:n,message:"must contain only url or textureAssetId"});for(let o of["url","textureAssetId"]){let s=t[o];s!==void 0&&(typeof s!="string"||!s.trim())&&r.push({path:`${n}.${o}`,message:"must be a non-empty string"})}}function wi(e,t,n,r,i){if(!Wn(e)){r.push({path:t,message:`must be ${i}`});return}Object.keys(e).some(o=>!n.includes(o))&&r.push({path:t,message:`must contain only ${n.join(", ")}`});for(let o of n)(typeof e[o]!="number"||!Number.isFinite(e[o]))&&r.push({path:`${t}.${o}`,message:"must be a finite number"})}function $i(e){if(e&&typeof e=="object"&&!Object.isFrozen(e)){Object.freeze(e);for(let t of Object.values(e))$i(t)}return e}function Wn(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Ni(e){return e.trim().replace(/^\/+|\/+$/g,"")}function qd(e){let t=[],n=new Map(e.assets.map(r=>[r.id,r]));for(let r of e.scene.gameObjects){let i=oc(r),o=an(r.overrides?.materialBinding);o&&t.push({kind:"root",scope:"scene",gameObjectId:r.id,gameObjectName:r.name,materialAssetId:o,bindingPath:"overrides.materialBinding.materialAssetId",label:i});let s=Jd(e,r,n),a=new Map(s.filter(d=>!!d.slotId).map(d=>[d.slotId,d])),c=r.overrides?.materialSlotBindings??{};for(let[d,u]of Object.entries(c)){let l=an(u);if(!l)continue;let f=a.get(d),g=sc(f,d);t.push({kind:"slot",scope:"scene",gameObjectId:r.id,gameObjectName:r.name,materialAssetId:l,bindingPath:`overrides.materialSlotBindings.${d}.materialAssetId`,label:`${i} / ${g}`,slotId:d,ownerNodePath:Gi(f)??d})}}for(let r of e.assets)if(!(r.type!=="prefab"||!r.prefab)){Oi(t,{ownerId:r.id,ownerName:r.displayName??r.id,prefabAssetId:r.id,path:`assets.${r.id}.prefab.overrides`,overrides:r.prefab.overrides});for(let i of r.prefab.nodes??[])Oi(t,{ownerId:`${r.id}:${i.id}`,ownerName:`${r.displayName??r.id} / ${i.name??i.id}`,prefabAssetId:r.id,prefabNodeId:i.id,path:`assets.${r.id}.prefab.nodes.${i.id}.overrides`,overrides:i.overrides})}return t}function Oi(e,t){let n=an(t.overrides?.materialBinding);n&&e.push({kind:"root",scope:"prefab",gameObjectId:t.ownerId,gameObjectName:t.ownerName,materialAssetId:n,bindingPath:`${t.path}.materialBinding.materialAssetId`,label:t.ownerName,prefabAssetId:t.prefabAssetId,...t.prefabNodeId?{prefabNodeId:t.prefabNodeId}:{}});for(let[r,i]of Object.entries(t.overrides?.materialSlotBindings??{})){let o=an(i);o&&e.push({kind:"slot",scope:"prefab",gameObjectId:t.ownerId,gameObjectName:t.ownerName,materialAssetId:o,bindingPath:`${t.path}.materialSlotBindings.${r}.materialAssetId`,label:`${t.ownerName} / ${r}`,slotId:r,ownerNodePath:r,prefabAssetId:t.prefabAssetId,...t.prefabNodeId?{prefabNodeId:t.prefabNodeId}:{}})}}function dn(e){let t=[...new Set((e.scene.materialAssets??[]).map(a=>a.id?.trim()).filter(a=>!!a))],n=new Set(t),r=qd(e),i=r.filter(a=>!n.has(a.materialAssetId)),o=new Map;for(let a of i){let c=o.get(a.materialAssetId)??[];c.push(a),o.set(a.materialAssetId,c)}let s=[...o.entries()].map(([a,c])=>({kind:"missing-material-asset",materialAssetId:a,usages:c}));return{ok:s.length===0,materialAssetIds:t,references:r,missingMaterialAssetIds:s.map(a=>a.materialAssetId),missingReferences:i,issues:s}}function Jd(e,t,n){let r=new Map;for(let i of Xd(e,t,n))r.set(i.slotId,i);return[...r.values()].sort((i,o)=>(i.label??i.slotId).localeCompare(o.label??o.slotId)||i.slotId.localeCompare(o.slotId))}function Gi(e){return e?.sourceSurfaces[0]?.ownerNodePath??null}function Xd(e,t,n){let r=tt(t);if(!r)return[];let o=(n?.get(r.assetId)??e.assets.find(a=>a.id===r.assetId))?.metadata?.materialSlots;if(!Array.isArray(o))return[];let s=[];for(let a of o){let c=Zd(a);c&&s.push(c)}return s}function Zd(e){if(!e||typeof e!="object"||Array.isArray(e))return null;let t=e,n=typeof t.slotId=="string"&&t.slotId.trim()?t.slotId.trim():"",r=Array.isArray(t.sourceSurfaces)?t.sourceSurfaces:null,i=Yd(r);if(!n||!r||i.length===0||i.length!==r.length)return null;let o=typeof t.label=="string"&&t.label.trim()?t.label.trim():i[0].ownerNodePath,s=typeof t.materialName=="string"&&t.materialName.trim()?t.materialName.trim():"",a=Array.isArray(t.materialNames)?t.materialNames.filter(d=>typeof d=="string"&&!!d.trim()).map(d=>d.trim()):void 0,c=ec(t.sourceMaterialProfiles);return{slotId:n,label:o,sourceSurfaces:i,...s?{materialName:s}:{},...a&&a.length>0?{materialNames:a}:{},...c&&c.length>0?{sourceMaterialProfiles:c}:{}}}function Yd(e){return Array.isArray(e)?e.flatMap(t=>{let n=ic(t);if(!n)return[];let r=Ni(typeof n.ownerNodePath=="string"?n.ownerNodePath:""),i=Number.isInteger(n.meshIndex)&&n.meshIndex>=0?n.meshIndex:void 0,o=Number.isInteger(n.primitiveIndex)&&n.primitiveIndex>=0?n.primitiveIndex:void 0;if(!r||i==null||o==null)return[];let s=Number.isInteger(n.nodeIndex)&&n.nodeIndex>=0?n.nodeIndex:void 0,a=Array.isArray(n.nodeIndexPath)?n.nodeIndexPath.filter(f=>Number.isInteger(f)&&f>=0):void 0,c=Number.isInteger(n.sourceMaterialIndex)&&n.sourceMaterialIndex>=0?n.sourceMaterialIndex:void 0,d=typeof n.sourceMeshName=="string"&&n.sourceMeshName.trim()?n.sourceMeshName.trim():void 0,u=typeof n.triangleCount=="number"&&Number.isFinite(n.triangleCount)&&n.triangleCount>=0?n.triangleCount:void 0,l=Qd(n.boundingBox);return[{ownerNodePath:r,...s!=null?{nodeIndex:s}:{},...a&&a.length>0?{nodeIndexPath:a}:{},meshIndex:i,primitiveIndex:o,...c!=null?{sourceMaterialIndex:c}:{},...d?{sourceMeshName:d}:{},...u!=null?{triangleCount:u}:{},...l?{boundingBox:l}:{}}]}):[]}function Qd(e){if(!e||typeof e!="object"||Array.isArray(e))return;let t=e,n=vi(t.min),r=vi(t.max);if(!(!n&&!r))return{...n?{min:n}:{},...r?{max:r}:{}}}function vi(e){if(!Array.isArray(e)||e.length<3)return null;let[t,n,r]=e;return typeof t=="number"&&Number.isFinite(t)&&typeof n=="number"&&Number.isFinite(n)&&typeof r=="number"&&Number.isFinite(r)?[t,n,r]:null}function ec(e){if(!Array.isArray(e))return;let t=e.map(tc).filter(n=>!!n);return t.length>0?t:void 0}function tc(e){if(!e||typeof e!="object"||Array.isArray(e))return null;let t=e;if(!Number.isInteger(t.sourceMaterialIndex))return null;let n=typeof t.materialName=="string"&&t.materialName.trim()?t.materialName.trim():"",r=t.profile&&typeof t.profile=="object"&&!Array.isArray(t.profile)?t.profile:void 0,i=nc(t.textureHints);return{sourceMaterialIndex:t.sourceMaterialIndex,...n?{materialName:n}:{},...r?{profile:r}:{},...i&&i.length>0?{textureHints:i}:{}}}function nc(e){if(!Array.isArray(e))return;let t=e.map(rc).filter(n=>!!n);return t.length>0?t:void 0}function rc(e){if(!e||typeof e!="object"||Array.isArray(e))return null;let t=e,n=typeof t.profilePath=="string"&&t.profilePath.trim()?t.profilePath.trim():"",r=typeof t.reason=="string"&&t.reason.trim()?t.reason.trim():"";return!n||!r?null:{profilePath:n,reason:r,...Number.isInteger(t.textureIndex)?{textureIndex:t.textureIndex}:{},...Number.isInteger(t.imageIndex)?{imageIndex:t.imageIndex}:{},...Number.isInteger(t.bufferView)?{bufferView:t.bufferView}:{},...typeof t.mimeType=="string"&&t.mimeType.trim()?{mimeType:t.mimeType.trim()}:{},...typeof t.uri=="string"&&t.uri.trim()?{uri:t.uri.trim()}:{}}}function ic(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function oc(e){return e.name?.trim()||e.id}function an(e){return typeof e?.materialAssetId=="string"?e.materialAssetId.trim():""}function sc(e,t){return e?.label?.trim()||Gi(e)?.trim()||e?.slotId?.trim()||t}var ln=1;function Fi(e){let t=structuredClone(e),n={ordinaryObjects:0,prefabRoots:0,discardedFields:0},r=ne(t.scene);return r&&(Z(r,"shadowMapExperiment",n),Array.isArray(r.gameObjects)&&r.gameObjects.forEach(i=>ac(i,n))),Array.isArray(t.assets)&&t.assets.forEach(i=>dc(i,n)),{document:t,summary:n}}function Jn(e){let t=ne(e);return!t||t.prefab!=null||t.transformType==="camera"||t.transformType==="light"||t.camera!=null||t.light!=null?!1:t.kind==="primitive"||ne(t.primitive)?!0:Array.isArray(t.components)&&t.components.some(n=>{let r=ne(n)?.type;return r==="ModelRenderer"||r==="ImageRenderer"})}function ac(e,t){let n=ne(e);if(!n)return;let r=ne(n.shadow);Z(n,"shadowMode",t),Z(n,"shadowMapExperiment",t),Jn(n)?(n.shadow=_i(r),t.ordinaryObjects+=1):Z(n,"shadow",t)}function dc(e,t){let n=ne(e);if(!n)return;let r=ne(n.defaults);r&&(Z(r,"shadowMode",t),Z(r,"shadow",t),Z(r,"shadowMapExperiment",t));let i=ne(n.prefab);if(!i)return;let o=ne(i.defaults);o&&Z(o,"shadowMode",t),i.defaults={...o??{},shadow:_i(o?.shadow)},t.prefabRoots+=1;let s=ne(i.defaults);if(Z(s,"shadowMapExperiment",t),Array.isArray(i.nodes))for(let a of i.nodes){let c=ne(a);if(!c)continue;Z(c,"shadowMode",t),Z(c,"shadow",t),Z(c,"shadowMapExperiment",t);let d=ne(c.defaults);d&&(Z(d,"shadowMode",t),Z(d,"shadow",t),Z(d,"shadowMapExperiment",t))}}function _i(e){let t=ne(e);return{cast:t?.cast==="enabled"?"enabled":"none",receive:t?.receive==="enabled"?"enabled":"none"}}function Z(e,t,n){Object.prototype.hasOwnProperty.call(e,t)&&(delete e[t],n.discardedFields+=1)}function ne(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}var Am=Symbol("unsupported-editor-scene-authored-clone-value");function Xn(e){return e.components.find(fc)??null}function tt(e){return e.components.find(mc)??null}function Zn(e){return e.components.find(gc)??null}function cn(e){return e?.type==="prefab"&&U(e.prefab?.sourceAssetId)!=null}function Li(e){return U(e?.prefab?.prefabId)!=null}function ji(e){return U(e?.prefab?.sourceAssetId)}function It(e){if(!e?.prefab)return null;let t=zi(e.prefab),n=U(e.prefab.rootNodeId);if(n&&t.some(i=>i.id===n))return n;let r=t.find(i=>i.kind==="root"&&!i.parentId);return r?r.id:null}function Et(e){return e?.prefab?zi(e.prefab):[]}function zi(e){if(!Array.isArray(e.nodes))return[];let t=[];for(let n of e.nodes){let r=cc(n);r&&!t.some(i=>i.id===r.id)&&t.push(r)}return structuredClone(t)}function cc(e){if(!e||typeof e!="object"||Array.isArray(e))return null;let t=e,n=U(t.id);return!n||!lc(t.kind)?null:{id:n,...U(t.guid)?{guid:U(t.guid)}:{},...U(t.name)?{name:U(t.name)}:{},...U(t.parentId)?{parentId:U(t.parentId)}:{},kind:t.kind,...t.transform?{transform:structuredClone(t.transform)}:{},...U(t.sourceAssetId)?{sourceAssetId:U(t.sourceAssetId)}:{},...U(t.sourceNodePath)?{sourceNodePath:U(t.sourceNodePath)}:{},...U(t.childPrefabId)?{childPrefabId:U(t.childPrefabId)}:{},...t.primitive?{primitive:structuredClone(t.primitive)}:{},...t.light?{light:structuredClone(t.light)}:{},...t.marker?{marker:structuredClone(t.marker)}:{},...t.defaults?{defaults:structuredClone(t.defaults)}:{},...t.overrides?{overrides:structuredClone(t.overrides)}:{},...t.metadata?{metadata:structuredClone(t.metadata)}:{}}}function lc(e){return e==="root"||e==="group"||e==="model"||e==="primitive"||e==="light"||e==="prefabInstance"||e==="marker"||e==="collision"}function Ui(e,t){let n=U(e?.materialAssetId),r=U(t?.materialAssetId),i=Bn(e?.override,t?.override);return yc({...r??n?{materialAssetId:r??n}:{},...Pt(i)?{override:i}:{}})}function Bi(e,t){let n={},r=Ui(e?.materialBinding,t?.materialBinding);r&&(n.materialBinding=r);let i=hc(e?.materialSlotBindings,t?.materialSlotBindings);return i&&(n.materialSlotBindings=i),Pt(n)?n:void 0}function un(e,t){let n=typeof t=="string"?bc(e,t):t,r=typeof t=="string"?t:t.id,i=[],o=Li(n)?n.prefab:null;if(!n||!o)return i.push({code:"not-prefab-instance",severity:"info",message:n?`GameObject "${n.id}" is not a prefab instance.`:`GameObject "${r}" was not found.`}),{gameObject:n,prefab:null,definition:null,sourceAsset:null,diagnostics:i};let s=e.assets.find(d=>d.id===o.prefabId&&cn(d));s||i.push({code:"missing-prefab-definition",severity:"error",message:`Prefab definition "${o.prefabId}" was not found.`,prefabId:o.prefabId});let a=ji(s)??U(o.sourceAssetId);s&&o.sourceAssetId&&a&&o.sourceAssetId!==a&&i.push({code:"source-asset-mismatch",severity:"warning",message:`Prefab instance source "${o.sourceAssetId}" does not match definition source "${a}".`,prefabId:o.prefabId,expectedSourceAssetId:a,actualSourceAssetId:o.sourceAssetId});let c=a?e.assets.find(d=>d.id===a):void 0;if(a&&!c&&i.push({code:"missing-source-asset",severity:"error",message:`Prefab source asset "${a}" was not found.`,prefabId:o.prefabId,sourceAssetId:a}),a){let d=e.assets.filter(u=>cn(u)&&ji(u)===a).map(u=>u.id);d.length>1&&i.push({code:"duplicate-source-prefab",severity:"info",message:`Source asset "${a}" is referenced by ${d.length} prefab definitions.`,prefabId:o.prefabId,sourceAssetId:a})}return{gameObject:n,prefab:o,definition:s??null,sourceAsset:c??null,diagnostics:i}}function nt(e){return e.kind==="group"||e.kind==="instance"||e.kind==="transform"||e.kind==="primitive"?e.kind:Li(e)?"instance":e.primitive?"primitive":tt(e)?"instance":Zn(e)||e.transformType?"transform":"group"}function Vi(e){let t=e.rendering&&typeof e.rendering=="object"&&!Array.isArray(e.rendering)?e.rendering:void 0,n=uc(t?.renderingGroupId),r=pc(t?.alphaIndex),i={};return n!=null&&(i.renderingGroupId=n),r!=null&&(i.alphaIndex=r),Object.keys(i).length>0?i:void 0}function uc(e){return e===0||e===1||e===2||e===3?e:null}function fc(e){return e.type==="Transform"}function mc(e){return e.type==="ModelRenderer"}function gc(e){return e.type==="ImageRenderer"}function pc(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function U(e){return typeof e=="string"&&e.trim().length>0?e.trim():null}function bc(e,t){return e.scene.gameObjects.find(n=>n.id===t)??null}function yc(e){if(!e||typeof e!="object"||Array.isArray(e))return;let t=e,n=U(t.materialAssetId),r=Bn(t.override),i={...n?{materialAssetId:n}:{},...Pt(r)?{override:r}:{}};return Pt(i)?i:void 0}function hc(e,t){let n=new Set([...Object.keys(e??{}),...Object.keys(t??{})]),r={};for(let i of n){let o=Ui(e?.[i],t?.[i]);o&&(r[i]=o)}return Pt(r)?r:void 0}function Pt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length>0}var Sc=new Set(["id","guid","name","parentId","kind","transform","marker","metadata"]);function Ki(e,t,n){if(e.kind!=="marker"){Object.prototype.hasOwnProperty.call(e,"marker")&&k("schema.invalidValue",`${n}.marker`);return}for(let a of Object.keys(e))Sc.has(a)||k("schema.invalidValue",`${n}.${a}`);At(e.parentId)||k("schema.invalidReference",`${n}.parentId`),Ec(e.transform,`${n}.transform`),xc(e.marker,`${n}.marker`);let r=At(e.id),i=e.marker,o=Pc(i,`${n}.marker`),s=o[0]??null;for(let a of o){a.target.id===r&&k("schema.invalidReference",`${a.path}.id`),s&&(a.target.kind!==s.target.kind||a.target.id!==s.target.id)&&k("schema.invalidReference",a.path);let c=t.get(a.target.id);c&&(a.target.kind==="marker"&&c.kind!=="marker"&&k("schema.invalidReference",`${a.path}.kind`),a.target.kind==="scene-object"&&c.kind==="marker"&&k("schema.invalidReference",`${a.path}.kind`))}}function xc(e,t){let n=Ne(e);n||k("schema.invalidType",t),ae(n,["schemaVersion","type","kind","tags","note","color","target","semanticFrame","geometry","metadata"],t),n.schemaVersion!==1&&k("schema.unsupportedVersion",`${t}.schemaVersion`),At(n.type)||k("schema.invalidValue",`${t}.type`),n.kind!==void 0&&!At(n.kind)&&k("schema.invalidValue",`${t}.kind`),n.tags!==void 0&&Tc(n.tags,`${t}.tags`),n.note!==void 0&&typeof n.note!="string"&&k("schema.invalidType",`${t}.note`),n.color!==void 0&&wc(n.color,`${t}.color`),n.target!==void 0&&Yn(n.target,`${t}.target`),n.semanticFrame!==void 0&&Ac(n.semanticFrame,`${t}.semanticFrame`),Ic(n.geometry,`${t}.geometry`),n.metadata!==void 0&&Dc(n.metadata,`${t}.metadata`)}function Pc(e,t){let n=[];return e.target&&n.push({target:e.target,path:`${t}.target`}),e.geometry.kind==="point"&&e.geometry.target&&n.push({target:e.geometry.target,path:`${t}.geometry.target`}),e.geometry.kind==="object-bounds"&&n.push({target:e.geometry.target,path:`${t}.geometry.target`}),n}function Ic(e,t){let n=Ne(e);if(n||k("schema.invalidType",t),n.kind==="box"){ae(n,["kind"],t);return}if(n.kind==="cylinder"){ae(n,["kind"],t);return}if(n.kind==="point"){ae(n,["kind","coordinateSpace","position","offset","target"],t),n.coordinateSpace!==void 0&&n.coordinateSpace!=="world"&&n.coordinateSpace!=="local"&&k("schema.invalidValue",`${t}.coordinateSpace`),n.position!==void 0&&$e(n.position,`${t}.position`),n.offset!==void 0&&$e(n.offset,`${t}.offset`),n.target!==void 0&&Yn(n.target,`${t}.target`);return}if(n.kind==="object-bounds"){ae(n,["kind","target"],t),Yn(n.target,`${t}.target`);return}if(n.kind==="polyhedron"){ae(n,["kind","coordinateSpace","vertices","faces"],t),n.coordinateSpace!==void 0&&n.coordinateSpace!=="world"&&k("schema.invalidValue",`${t}.coordinateSpace`),Array.isArray(n.vertices)||k("schema.invalidType",`${t}.vertices`),n.vertices.forEach((r,i)=>$e(r,`${t}.vertices[${i}]`)),n.faces!==void 0&&(Array.isArray(n.faces)||k("schema.invalidType",`${t}.faces`),n.faces.forEach((r,i)=>{Array.isArray(r)||k("schema.invalidType",`${t}.faces[${i}]`),r.forEach((o,s)=>{(!Number.isInteger(o)||o<0)&&k("schema.invalidValue",`${t}.faces[${i}][${s}]`)})}));return}k("schema.invalidValue",`${t}.kind`)}function Yn(e,t){let n=Ne(e);n||k("schema.invalidType",t),ae(n,["kind","id","label"],t),n.kind!=="marker"&&n.kind!=="scene-object"&&k("schema.invalidValue",`${t}.kind`),At(n.id)||k("schema.invalidValue",`${t}.id`),n.label!==void 0&&typeof n.label!="string"&&k("schema.invalidType",`${t}.label`)}function Ec(e,t){let n=Ne(e);if(n||k("schema.invalidType",t),n.type!=="Transform"&&k("schema.invalidValue",`${t}.type`),n.mode==="matrix"){ae(n,["type","mode","matrix"],t),(!Array.isArray(n.matrix)||n.matrix.length!==16)&&k("schema.invalidType",`${t}.matrix`),n.matrix.forEach((r,i)=>fn(r,`${t}.matrix[${i}]`));return}ae(n,["type","mode","position","rotation","scale"],t),n.mode!==void 0&&n.mode!=="trs"&&k("schema.invalidValue",`${t}.mode`),$e(n.position,`${t}.position`),$e(n.rotation,`${t}.rotation`),n.scale!==void 0&&$e(n.scale,`${t}.scale`)}function Ac(e,t){let n=Ne(e);n||k("schema.invalidType",t),ae(n,["origin","forward","right","up","label","description"],t),$e(n.origin,`${t}.origin`);for(let r of["forward","right","up"])n[r]!==void 0&&$e(n[r],`${t}.${r}`);for(let r of["label","description"])n[r]!==void 0&&typeof n[r]!="string"&&k("schema.invalidType",`${t}.${r}`)}function wc(e,t){let n=Ne(e);n||k("schema.invalidType",t),ae(n,["r","g","b"],t);for(let r of["r","g","b"])fn(n[r],`${t}.${r}`),(n[r]<0||n[r]>1)&&k("schema.invalidValue",`${t}.${r}`)}function $e(e,t){let n=Ne(e);n||k("schema.invalidType",t),ae(n,["x","y","z"],t);for(let r of["x","y","z"])fn(n[r],`${t}.${r}`)}function Tc(e,t){Array.isArray(e)||k("schema.invalidType",t),e.forEach((n,r)=>{typeof n!="string"&&k("schema.invalidType",`${t}[${r}]`)})}function Dc(e,t){let n=Ne(e);n||k("schema.invalidType",t),Qn(n,t,new Set)}function Qn(e,t,n){if(e===null||typeof e=="string"||typeof e=="boolean")return;if(typeof e=="number"){fn(e,t);return}(!e||typeof e!="object")&&k("schema.invalidType",t),n.has(e)&&k("schema.invalidValue",t);let r=Object.getPrototypeOf(e);Array.isArray(e)?r!==Array.prototype&&k("schema.invalidType",t):r!==Object.prototype&&r!==null&&k("schema.invalidType",t),n.add(e);try{if(Array.isArray(e))e.forEach((i,o)=>Qn(i,`${t}[${o}]`,n));else for(let[i,o]of Object.entries(e))Qn(o,`${t}.${i}`,n)}finally{n.delete(e)}}function ae(e,t,n){let r=new Set(t);for(let i of Object.keys(e))r.has(i)||k("schema.invalidValue",`${n}.${i}`)}function fn(e,t){(typeof e!="number"||!Number.isFinite(e))&&k("schema.invalidValue",t)}function Ne(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function At(e){return typeof e=="string"&&e.trim()?e.trim():null}function k(e,t){throw new Error(`${e}: ${t}`)}function tr(e,t){return t===e.rootNodeId?e.instanceId:`${e.instanceId}:${kc(t)}`}function kc(e){return encodeURIComponent(e)}function er(e,t){return{...structuredClone(e),id:tr(t,e.id)}}function Hi(e,t){let n=structuredClone(e);return n.target&&(n.target=er(n.target,t)),n.geometry.kind==="point"&&n.geometry.target&&(n.geometry.target=er(n.geometry.target,t)),n.geometry.kind==="object-bounds"&&(n.geometry.target=er(n.geometry.target,t)),n}var Wi={x:-.3,y:-1,z:-.2};var qi="scene.main",Ji="scene";function Xi(e){let t=e.meta?.authoringSource;return{sourceId:t?.sourceId||qi,sourceType:t?.sourceType||Ji,revision:typeof t?.revision=="number"?t.revision:1}}var Mc="sun_light";function Cc(e,t){let n=typeof t.prefab?.prefabId=="string"?t.prefab.prefabId:null,r=n?e.assets.find(o=>o.id===n)?.prefab?.defaults?.shadow:void 0,i=De(r??t.shadow);return{settings:i.shadow,diagnostics:i.diagnostics}}function Rc(e){let t=new Map,n=e.casterId;for(let r of e.explicitReceiverIds??[]){let i=gn(e.document,r);!i||i.id===n||i.active===!1||t.set(i.id,{receiverId:i.id,source:"explicit",score:120,...nr(i,"explicit",120,["explicit receiver id"])})}for(let r of e.document.scene.gameObjects){if(r.id===n||r.active===!1)continue;De(r.shadow).shadow?.receive==="enabled"&&Oc(t,{receiverId:r.id,source:"explicit",score:100,...nr(r,"explicit",100,["shadow.receive enabled"])})}return[...t.values()].sort((r,i)=>i.score-r.score||r.receiverId.localeCompare(i.receiverId))}function mn(e){let t=e.caster?.id===e.casterId?e.caster:gn(e.document,e.casterId),n=[];if(!t)return{casterId:e.casterId,receiverIds:[],backend:"none",mode:"none",quality:e.fallbackQuality??"medium",params:zt(e.fallbackQuality??"medium"),diagnostics:[{code:"shadow.invalidTarget",severity:"error",message:`Shadow caster "${e.casterId}" was not found.`,casterId:e.casterId}]};let r=e.resolvedSettings!==void 0?(()=>{let g=De(e.resolvedSettings);return{settings:g.shadow,diagnostics:g.diagnostics}})():Cc(e.document,t);n.push(...r.diagnostics);let o=r.settings?.cast==="enabled"?Cn(r.settings,e.fallbackMode??"none"):"none",s=Rn(r.settings,e.fallbackQuality??"medium"),a=zt(s,r.settings?.params),c=$c(o),d=vc(e.explicitReceiverIds),u=c==="none"?{candidates:[],diagnostics:[]}:d.length>0&&e.strictExplicitReceivers===!0?Gc(e.document,t.id,d):{candidates:Rc({document:e.document,casterId:t.id,explicitReceiverIds:d.length>0?d:void 0}),diagnostics:[]};n.push(...u.diagnostics);let l=u.candidates;c!=="none"&&l.length===0&&n.push({code:"shadow.receiverNotFound",severity:"warning",message:`No shadow receiver was found for caster "${t.id}".`,casterId:t.id});let f=c==="none"?null:Nc(e.document,r.settings??void 0,e.defaultLightId);return f?.diagnostic&&n.push(f.diagnostic),{casterId:t.id,receiverIds:l.map(g=>g.receiverId),...f?.lightId?{lightId:f.lightId}:{},backend:c,mode:o,quality:s,params:a,diagnostics:n}}function $c(e){return e==="dynamic"?"dynamic-map":e==="static"?"static-baked":e==="blob"?"blob":e==="projected"?"projected":"none"}function Nc(e,t,n){if(t?.light?.mode==="explicit"){let o=t?.light?.lightId;return o&&Zi(e,o)?{lightId:o}:{diagnostic:{code:"shadow.lightNotFound",severity:"warning",message:o?`Explicit shadow light "${o}" was not found.`:"Shadow light mode is explicit, but no lightId was configured.",...o?{lightId:o}:{}}}}let r=n??Mc;if(Zi(e,r))return{lightId:r};let i=e.scene.gameObjects.find(o=>Yi(o)&&o.active!==!1);return i?{lightId:i.id}:{diagnostic:{code:"shadow.lightNotFound",severity:"warning",message:"No directional shadow light was found."}}}function Zi(e,t){let n=gn(e,t);return!!n&&n.active!==!1&&Yi(n)}function Yi(e){return nt(e)==="transform"&&e.light?.type==="directional"}function Oc(e,t){let n=e.get(t.receiverId);(!n||t.score>n.score)&&e.set(t.receiverId,t)}function vc(e){let t=new Set,n=[];for(let r of e??[]){let i=typeof r=="string"?r.trim():"";!i||t.has(i)||(t.add(i),n.push(i))}return n}function Gc(e,t,n){let r=[],i=[];for(let o of n){let s=gn(e,o);if(!s){i.push({code:"shadow.receiverNotFound",severity:"warning",message:`Explicit shadow receiver "${o}" was not found.`,casterId:t,receiverId:o,details:{source:"explicit"}});continue}if(s.id===t){i.push({code:"shadow.receiverNotFound",severity:"warning",message:`Shadow caster "${t}" cannot be used as its own receiver.`,casterId:t,receiverId:o,details:{source:"explicit",reason:"self"}});continue}if(s.active===!1){i.push({code:"shadow.receiverNotFound",severity:"warning",message:`Explicit shadow receiver "${o}" is inactive.`,casterId:t,receiverId:o,details:{source:"explicit",reason:"inactive"}});continue}r.push({receiverId:s.id,source:"explicit",score:120,...nr(s,"explicit",120,["explicit receiver id"])})}return{candidates:r,diagnostics:i}}function nr(e,t,n,r){let i=De(e.shadow).shadow;return{active:e.active!==!1,visible:e.active!==!1,...i?.receive?{receive:i.receive}:{},suitability:{score:n,material:nt(e)==="primitive"?"primitive":t,reasons:r}}}function gn(e,t){return e.scene.gameObjects.find(n=>n.id===t)??null}var Qi={type:"directional",intensity:2,direction:{...Wi},diffuseColor:{r:1,g:1,b:1},inspectorLanguage:"zh"},rr={type:"hemispheric",intensity:.8,diffuseColor:{r:1,g:1,b:1},groundColor:{r:.48,g:.52,b:.62},inspectorLanguage:"zh"};function to(e){return e.filter(t=>t.kind==="model"||t.kind==="texture").map(jc).sort(Lc)}function jc(e){let t=e.kind==="texture"?"texture":e.kind==="prefab"?"prefab":"glb",n=Ve(e.guid),r=Uc(e);return{id:e.assetId,...n?{guid:n}:{},assetId:e.assetId,type:t,kind:e.kind==="texture"?"texture":e.kind==="prefab"?"prefab":"model",displayName:e.displayName,category:e.category??zc(e),warmupCount:e.warmupCount,singleton:e.singleton,materialMode:e.materialMode,defaults:bn(e.defaults),prefab:bn(e.prefab),external:bn(e.external),metadata:r,origin:e.origin??"project",dedupeKey:e.dedupeKey??n??Kc(e.external)??e.assetId,placeable:_c(e)}}function Fc(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;let t=e;return t.kind==="texture"||t.type==="texture"}function _c(e){return Fc(e)?!0:!e||typeof e!="object"||Array.isArray(e)||e.placeable!==!1}function Lc(e,t){return(e.category??"").localeCompare(t.category??"")||e.displayName.localeCompare(t.displayName)||e.assetId.localeCompare(t.assetId)||e.type.localeCompare(t.type)}function zc(e){return e.kind==="prefab"?"Prefab":e.kind==="texture"?"Texture":e.kind==="image"?"Image":e.kind==="sound"?"Sound":"Model"}function Uc(e){return Bc({originalFileName:e.originalFileName,relativePath:e.relativePath,codeKey:e.codeKey,contentHash:e.contentHash,byteSize:e.byteSize,...bn(e.metadata)})}function Bc(e){if(!Array.isArray(e.materialSlots))return e;let t=pn(e.assetAnalysis),n=Array.isArray(t?.meshes)?t.meshes:[],r=Array.isArray(t?.nodes)?t.nodes:[],i=new Map(n.flatMap(c=>{let d=pn(c),u=wt(d?.meshIndex),l=Ve(d?.name);return u==null||!l?[]:[[u,l]]})),o=new Map(r.flatMap(c=>{let d=pn(c),u=wt(d?.nodeIndex),l=Ve(d?.meshName);return u==null||!l?[]:[[u,l]]})),s=eo(t,"meshCount",n.length)||eo(t,"nodeCount",r.length),a=e.materialSlots.map(c=>{let d=pn(c);if(!d||Ve(d.sourceMeshName))return c;let u=wt(d.meshIndex);if(u==null)return c;let l=wt(d.nodeIndex),f=i.get(u)??(l==null?void 0:o.get(l))??(s?Vc(d):void 0);return f?{...d,sourceMeshName:f}:c});return{...e,materialSlots:a}}function Vc(e){let t=Ve(e.label);if(t){let n=t.replace(/\s+\/\s+Primitive\s+\d+$/,"").trim();if(n)return n}return Ve(e.ownerNodePath)?.split("/").filter(Boolean).pop()}function eo(e,t,n){let r=wt(e?.[t]);return r!=null&&r>n}function Kc(e){return!e||typeof e!="object"||Array.isArray(e)?null:Ve(e.platformAssetId)}function Ve(e){return typeof e=="string"&&e.trim()?e.trim():null}function wt(e){return Number.isInteger(e)&&e>=0?e:null}function pn(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function bn(e){return e==null?void 0:structuredClone(e)}function ro(e,t){let n=new Map(t.filter(o=>o.type==="glb").map(o=>[o.assetId,o])),r=e.assets.map(o=>{if(o.type!=="glb")return o;let s=n.get(o.id);return s?no(o,s):o}),i=new Set(e.assets.map(o=>o.id));for(let o of Hc(e)){if(i.has(o))continue;let s=n.get(o);s&&(r.push(no({id:o,type:"glb"},s)),i.add(o))}return{...e,assets:r}}function Hc(e){let t=[],n=new Set,r=i=>{let o=or(i);!o||n.has(o)||(n.add(o),t.push(o))};for(let i of e.assets)if(i.type==="prefab"){r(i.prefab?.sourceAssetId);for(let o of i.prefab?.nodes??[])r(o.sourceAssetId)}for(let i of e.scene.gameObjects){for(let s of i.components)s.type==="ModelRenderer"&&r(s.assetId);r(i.prefab?.sourceAssetId);let o=ir(ir(i)?.instance);r(o?.assetId)}return t}function io(e){let t=[],n=(i,o)=>{let s=or(o);s&&t.push({assetId:s,...i})};for(let i=0;i<e.scene.gameObjects.length;i+=1){let o=e.scene.gameObjects[i];for(let s=0;s<o.components.length;s+=1){let a=o.components[s];a.type!=="ModelRenderer"&&a.type!=="ImageRenderer"||n({scope:"scene-object",kind:`${a.type}.assetId`,path:`scene.gameObjects[${i}].components[${s}].assetId`,objectId:o.id,...o.name?{objectName:o.name}:{}},a.assetId)}n({scope:"scene-object",kind:"prefab.prefabId",path:`scene.gameObjects[${i}].prefab.prefabId`,objectId:o.id,...o.name?{objectName:o.name}:{}},o.prefab?.prefabId),n({scope:"scene-object",kind:"prefab.sourceAssetId",path:`scene.gameObjects[${i}].prefab.sourceAssetId`,objectId:o.id,...o.name?{objectName:o.name}:{}},o.prefab?.sourceAssetId),rt(o.overrides,`scene.gameObjects[${i}].overrides`,(s,a)=>n({scope:"scene-object",kind:"material.textureAssetId",path:s,objectId:o.id,...o.name?{objectName:o.name}:{}},a))}for(let i=0;i<e.assets.length;i+=1){let o=e.assets[i];if(!o.prefab)continue;let s=`assets[${i}].prefab`;n({scope:"prefab-asset",kind:"prefab.sourceAssetId",path:`${s}.sourceAssetId`,prefabAssetId:o.id},o.prefab.sourceAssetId),rt(o.prefab.overrides,`${s}.overrides`,(c,d)=>n({scope:"prefab-asset",kind:"material.textureAssetId",path:c,prefabAssetId:o.id},d));let a=Et(o);for(let c=0;c<a.length;c+=1){let d=a[c],u=`${s}.nodes[${c}]`;n({scope:"prefab-node",kind:"node.sourceAssetId",path:`${u}.sourceAssetId`,prefabAssetId:o.id,nodeId:d.id},d.sourceAssetId),n({scope:"prefab-node",kind:"node.childPrefabId",path:`${u}.childPrefabId`,prefabAssetId:o.id,nodeId:d.id},d.childPrefabId),rt(d.overrides,`${u}.overrides`,(l,f)=>n({scope:"prefab-node",kind:"material.textureAssetId",path:l,prefabAssetId:o.id,nodeId:d.id},f))}}let r=Array.isArray(e.scene.materialAssets)?e.scene.materialAssets:[];for(let i=0;i<r.length;i+=1){let o=r[i],s=or(o.id)??"";n({scope:"material-asset",kind:"origin.sourceAssetId",path:`scene.materialAssets[${i}].origin.sourceAssetId`,materialAssetId:s},ir(o.origin)?.sourceAssetId),rt(o.properties,`scene.materialAssets[${i}].properties`,(a,c)=>n({scope:"material-asset",kind:"material.textureAssetId",path:a,materialAssetId:s},c))}return t.sort((i,o)=>i.path.localeCompare(o.path))}function no(e,t){return{...e,guid:t.guid??e.guid,displayName:t.displayName||e.displayName,category:t.category??e.category,warmupCount:t.warmupCount??e.warmupCount,singleton:t.singleton??e.singleton,materialMode:t.materialMode??e.materialMode,defaults:yn(t.defaults??e.defaults),prefab:yn(t.prefab??e.prefab),external:yn(t.external??e.external),metadata:yn(t.metadata??e.metadata)}}function yn(e){return e==null?void 0:structuredClone(e)}function rt(e,t,n){if(!(!e||typeof e!="object")){if(Array.isArray(e)){e.forEach((r,i)=>rt(r,`${t}[${i}]`,n));return}for(let[r,i]of Object.entries(e)){let o=`${t}.${r}`;r==="textureAssetId"?n(o,i):rt(i,o,n)}}}function ir(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function or(e){return(typeof e=="string"?e.trim():"")||void 0}function oo(e){let t=dn(e);if(t.ok)return;let n=new Error(`editor_scene_material_assets_missing: ${t.missingMaterialAssetIds.join(", ")}`);throw n.details={missingMaterialAssetIds:t.missingMaterialAssetIds,missingReferences:t.missingReferences.map(r=>({materialAssetId:r.materialAssetId,gameObjectId:r.gameObjectId,bindingPath:r.bindingPath,label:r.label,kind:r.kind,...r.slotId?{slotId:r.slotId}:{},...r.ownerNodePath?{ownerNodePath:r.ownerNodePath}:{}}))},n}var fo="@fps-games/editor.playable-sdk.scene-compiler",mo="3",Wc=new Set(["shadowMode","childMaterialBindings","childMaterials"]),qc=new Set(["coordinateSpace","center","size","rotation"]),so=new Set(["root","group","model","primitive","light","prefabInstance","marker","collision"]);function Jc(e){Xc(e,!0)}function go(e){let t=Fi(e);return Jc(t.document),t}function Xc(e,t){let n=I(e);if(!n)throw new Error("editor_scene_must_be_object");if(n.schemaVersion!==1)throw y("schema.unsupportedVersion","$.schemaVersion");if(!Array.isArray(n.assets))throw new Error("editor_scene_assets_must_be_array");let r=I(n.scene);if(!Array.isArray(r?.gameObjects))throw new Error("editor_scene_game_objects_must_be_array");if(r.materialAssets!=null&&!Array.isArray(r.materialAssets))throw new Error("editor_scene_material_assets_must_be_array");if(Object.prototype.hasOwnProperty.call(r,"shadowMapExperiment"))throw y("schema.forbiddenField","$.scene.shadowMapExperiment");el(n.assets,r.gameObjects),dr(n,"$"),tl(n.assets),Qc(n.assets,r.gameObjects),nl(r.gameObjects,n.assets),rl(r.gameObjects),Yc(r.materialAssets??[]),t&&il(n.assets,r.gameObjects),oo(n),Zc(n.assets,r.gameObjects)}function Zc(e,t){for(let n=0;n<t.length;n+=1){let r=I(t[n]),i=`$.scene.gameObjects[${n}]`,o=Object.prototype.hasOwnProperty.call(r,"shadow");if(I(r.prefab)){if(o)throw y("schema.forbiddenField",`${i}.shadow`)}else if(Jn(r))ao(r.shadow,`${i}.shadow`);else if(o)throw y("schema.forbiddenField",`${i}.shadow`);if(Object.prototype.hasOwnProperty.call(r,"shadowMapExperiment"))throw y("schema.forbiddenField",`${i}.shadowMapExperiment`)}for(let n=0;n<e.length;n+=1){let r=I(e[n]),i=`$.assets[${n}]`,o=I(r.defaults);if(o?.shadow!==void 0)throw y("schema.forbiddenField",`${i}.defaults.shadow`);if(o?.shadowMapExperiment!==void 0)throw y("schema.forbiddenField",`${i}.defaults.shadowMapExperiment`);let s=I(r.prefab);if(!s)continue;let a=I(s.defaults);if(ao(a?.shadow,`${i}.prefab.defaults.shadow`),a?.shadowMapExperiment!==void 0)throw y("schema.forbiddenField",`${i}.prefab.defaults.shadowMapExperiment`);Array.isArray(s.nodes)&&s.nodes.forEach((c,d)=>{let u=I(c),l=`${i}.prefab.nodes[${d}]`,f=I(u?.defaults);if(u?.shadow!==void 0)throw y("schema.forbiddenField",`${l}.shadow`);if(f?.shadow!==void 0)throw y("schema.forbiddenField",`${l}.defaults.shadow`);if(u?.shadowMapExperiment!==void 0)throw y("schema.forbiddenField",`${l}.shadowMapExperiment`);if(f?.shadowMapExperiment!==void 0)throw y("schema.forbiddenField",`${l}.defaults.shadowMapExperiment`)})}}function ao(e,t){let n=I(e);if(!n||n.cast===void 0||n.receive===void 0)throw y("schema.invalidType",t);if(n.cast!=="enabled"&&n.cast!=="none"||n.receive!=="enabled"&&n.receive!=="none")throw y("schema.invalidValue",t);for(let r of Object.keys(n))if(r!=="cast"&&r!=="receive")throw y("schema.forbiddenField",`${t}.${r}`)}function Yc(e){let t=new Set,n=new Set;for(let r=0;r<e.length;r+=1){let i=I(e[r]),o=`$.scene.materialAssets[${r}]`;if(!i)throw y("schema.invalidType",o);if(Object.prototype.hasOwnProperty.call(i,"materialKind"))throw y("schema.deprecatedField",`${o}.materialKind`);if(Object.prototype.hasOwnProperty.call(i,"profile"))throw y("schema.deprecatedField",`${o}.profile`);let s=A(i.id);if(!s)throw y("schema.invalidType",`${o}.id`);if(t.has(s))throw y("schema.invalidValue",`${o}.id`);t.add(s);let a=A(i.guid);if(a){if(n.has(a))throw y("schema.invalidValue",`${o}.guid`);n.add(a)}if(!A(i.name))throw y("schema.invalidType",`${o}.name`);let c=A(i.shaderId);if(!c)throw y("schema.invalidValue",`${o}.shaderId`);let d=on(c),u=i.definitionVersion;if(u!=null&&(typeof u!="number"||!Number.isSafeInteger(u)||u<1))throw y("schema.invalidValue",`${o}.definitionVersion`);if(!d&&u==null)throw y("schema.invalidValue",`${o}.definitionVersion`);if(d){let l=sn(c,i.properties,`${o}.properties`);if(l[0])throw y("schema.invalidValue",l[0].path)}else if(!I(i.properties))throw y("schema.invalidType",`${o}.properties`);for(let l of Object.keys(i))if(!["id","guid","name","shaderId","definitionVersion","properties","system","origin"].includes(l))throw y("schema.unknownField",`${o}.${l}`)}}function Qc(e,t){let n=new Set(e.map(I).filter(o=>o?.type==="glb").map(o=>A(o?.id)).filter(o=>!!o)),r=new Set(e.map(I).filter(o=>o?.type==="texture").map(o=>A(o?.id)).filter(o=>!!o)),i=new Map;for(let o of e.map(I)){if(o?.type!=="prefab")continue;let s=A(o.id),a=A(I(o.prefab)?.sourceAssetId);s&&a&&i.set(s,a)}for(let o=0;o<e.length;o+=1){let s=I(e[o]);if(s?.type!=="prefab")continue;let a=I(s.prefab),c=A(a?.sourceAssetId),d=A(a?.rootNodeId);if(!c||!n.has(c))throw y("schema.invalidReference",`$.assets[${o}].prefab.sourceAssetId`);let u=Array.isArray(a?.nodes)?a.nodes:[];for(let l=0;l<u.length;l+=1){let f=I(u[l]),g=A(f?.sourceAssetId);if(f?.kind==="model"&&(!g||!n.has(g)))throw y("schema.invalidReference",`$.assets[${o}].prefab.nodes[${l}].sourceAssetId`);if(f?.kind==="prefabInstance"){let p=A(f.childPrefabId),h=p?i.get(p):null;if(A(f.id)===d&&c!==h)throw y("schema.invalidReference",`$.assets[${o}].prefab.sourceAssetId`);if(g&&g!==h)throw y("schema.invalidReference",`$.assets[${o}].prefab.nodes[${l}].sourceAssetId`)}}}for(let o=0;o<t.length;o+=1){let s=I(t[o]),a=A(I(s?.instance)?.assetId);if(a&&!n.has(a))throw y("schema.invalidReference",`$.scene.gameObjects[${o}].instance.assetId`);let c=Array.isArray(s?.components)?s.components:[];for(let d=0;d<c.length;d+=1){let u=I(c[d]);if(u?.type!=="ModelRenderer")continue;let l=A(u.assetId);if(!l||!n.has(l))throw y("schema.invalidReference",`$.scene.gameObjects[${o}].components[${d}].assetId`)}for(let d=0;d<c.length;d+=1){let u=I(c[d]);if(u?.type!=="ImageRenderer")continue;let l=A(u.assetId);if(!l||!r.has(l))throw y("schema.invalidReference",`$.scene.gameObjects[${o}].components[${d}].assetId`);let f=I(u.size);if(!f||!uo(f.width)||!uo(f.height))throw y("schema.invalidValue",`$.scene.gameObjects[${o}].components[${d}].size`)}}}function el(e,t){let n=new Set;e.forEach((o,s)=>{let a=I(o);if(!a)throw y("schema.invalidType",`$.assets[${s}]`);let c=A(a.id);if(!c||!A(a.type))throw y("schema.invalidValue",`$.assets[${s}]`);if(n.has(c))throw y("schema.invalidValue",`$.assets[${s}].id`);n.add(c)});let r=new Set,i=new Map;t.forEach((o,s)=>{let a=I(o);if(!a)throw y("schema.invalidType",`$.scene.gameObjects[${s}]`);let c=A(a.id);if(!c)throw y("schema.invalidValue",`$.scene.gameObjects[${s}].id`);if(r.has(c))throw y("schema.invalidValue",`$.scene.gameObjects[${s}].id`);if(r.add(c),i.set(c,{value:a,index:s}),!Array.isArray(a.components))throw y("schema.invalidType",`$.scene.gameObjects[${s}].components`);a.components.forEach((d,u)=>{let l=I(d);if(!l)throw y("schema.invalidType",`$.scene.gameObjects[${s}].components[${u}]`);if(!A(l.type))throw y("schema.invalidValue",`$.scene.gameObjects[${s}].components[${u}].type`)})});for(let[o,s]of i){if(!("parentId"in s.value))continue;let a=A(s.value.parentId);if(!a||!i.has(a))throw y("schema.invalidReference",`$.scene.gameObjects[${s.index}].parentId`);let c=new Set([o]),d=a;for(;d;){if(c.has(d))throw y("schema.invalidReference",`$.scene.gameObjects[${s.index}].parentId`);c.add(d);let u=i.get(d)?.value;d=u&&u.parentId!=null?A(u.parentId):null}}}function dr(e,t){if(Array.isArray(e)){e.forEach((r,i)=>dr(r,`${t}[${i}]`));return}let n=I(e);if(n)for(let[r,i]of Object.entries(n)){let o=`${t}.${r}`;if(Wc.has(r))throw y("schema.deprecatedField",o);r==="shadow"&&pt(i,o),!(r==="metadata"||r==="shadowMapExperiment")&&dr(i,o)}}function tl(e){let t=new Set(e.map(I).filter(s=>s?.type==="prefab").map(s=>A(s?.id)).filter(s=>!!s)),n=new Map;for(let s=0;s<e.length;s+=1){let a=I(e[s]);if(a?.type!=="prefab")continue;let c=I(a.prefab);if(!Array.isArray(c?.nodes))throw y("schema.unsupportedVersion",`$.assets[${s}].prefab.nodes`);co(c.defaults,`$.assets[${s}].prefab.defaults`);let d=[],u=new Set;for(let p=0;p<c.nodes.length;p+=1){let h=`$.assets[${s}].prefab.nodes[${p}]`,S=I(c.nodes[p]);if(!S)throw y("schema.invalidType",h);co(S.defaults,`${h}.defaults`);let P=A(S.id);if(!P||!so.has(String(S.kind)))throw y("schema.invalidValue",h);if(u.has(P))throw y("schema.invalidValue",`${h}.id`);u.add(P),d.push(S)}let l=A(c?.rootNodeId),f=l?d.find(p=>A(p?.id)===l):null,g=!!f&&so.has(String(f.kind))&&!Object.prototype.hasOwnProperty.call(f,"parentId");if(c?.compositionVersion!==ln||d.length===0||!g)throw y("schema.unsupportedVersion",`$.assets[${s}].prefab`);n.set(A(a.id),d.flatMap((p,h)=>{let S=A(p.childPrefabId);return S?[{prefabId:S,path:`$.assets[${s}].prefab.nodes[${h}].childPrefabId`}]:[]}));for(let p=0;p<d.length;p+=1){let h=d[p];Ki(h,new Map(d.map($=>[A($.id),$])),`$.assets[${s}].prefab.nodes[${p}]`);let S=A(h.id),P=A(h.parentId);if(S!==l&&(!P||!u.has(P)))throw y("schema.invalidReference",`$.assets[${s}].prefab.nodes[${p}].parentId`);if(h.kind==="prefabInstance"){let $=A(h.childPrefabId);if(!$||!t.has($))throw y("schema.invalidReference",`$.assets[${s}].prefab.nodes[${p}].childPrefabId`)}let D=new Set([S]),T=P;for(;T;){if(D.has(T))throw y("schema.invalidReference",`$.assets[${s}].prefab.nodes[${p}].parentId`);D.add(T);let $=d.find(_=>A(_.id)===T);T=$?A($.parentId):null}}}let r=new Set,i=new Set,o=s=>{if(!i.has(s)){r.add(s);for(let a of n.get(s)??[]){if(r.has(a.prefabId))throw y("schema.invalidReference",a.path);o(a.prefabId)}r.delete(s),i.add(s)}};for(let s of n.keys())o(s)}function co(e,t){if(e==null)return;let n=I(e);if(!n)throw y("schema.invalidType",t);if(Object.prototype.hasOwnProperty.call(n,"active")&&typeof n.active!="boolean")throw y("schema.invalidType",`${t}.active`)}function nl(e,t){let n=new Map;for(let r of t.map(I)){if(r?.type!=="prefab")continue;let i=A(r.id),o=A(I(r.prefab)?.sourceAssetId);i&&o&&n.set(i,o)}for(let r=0;r<e.length;r+=1){let i=I(e[r]);if(!i||i.prefab==null)continue;let o=I(i.prefab),s=A(o?.prefabId),a=s?n.get(s):null;if(!s||!a)throw y("schema.unsupportedVersion",`$.scene.gameObjects[${r}].prefab`);if(A(o?.sourceAssetId)!==a)throw y("schema.invalidReference",`$.scene.gameObjects[${r}].prefab.sourceAssetId`);let c=A(I(i.instance)?.assetId);if(c&&c!==a)throw y("schema.invalidReference",`$.scene.gameObjects[${r}].instance.assetId`);let d=Array.isArray(i.components)?i.components:[];for(let u=0;u<d.length;u+=1){let l=I(d[u]);if(l?.type==="ModelRenderer"&&A(l.assetId)!==a)throw y("schema.invalidReference",`$.scene.gameObjects[${r}].components[${u}].assetId`)}}}function rl(e){for(let t=0;t<e.length;t+=1){let n=I(I(I(e[t])?.marker)?.geometry);if(n?.kind!=="box"&&n?.kind!=="cylinder")continue;for(let i of qc)if(Object.prototype.hasOwnProperty.call(n,i))throw y("schema.deprecatedField",`$.scene.gameObjects[${t}].marker.geometry.${i}`);if(!(Array.isArray(I(e[t])?.components)?I(e[t]).components:[]).some(i=>I(i)?.type==="Transform"))throw y("schema.invalidValue",`$.scene.gameObjects[${t}].components`)}}function il(e,t){let n=new Map,r=new Map;for(let i=0;i<e.length;i+=1){let o=I(e[i]),s=A(o?.id);if(!o||!s)continue;if(o.type==="prefab"){let l=A(I(o.prefab)?.sourceAssetId);l&&r.set(s,l)}let a=I(o.metadata),c=a?.materialSlots;if(c==null){n.set(s,new Set);continue}if(!Array.isArray(c))throw y("schema.invalidType",`$.assets[${i}].metadata.materialSlots`);let d=ol(a?.assetAnalysis),u=new Set;for(let l=0;l<c.length;l+=1){let f=I(c[l]),g=A(f?.slotId);if(!f||!g)throw y("schema.invalidValue",`$.assets[${i}].metadata.materialSlots[${l}]`);let p=`$.assets[${i}].metadata.materialSlots[${l}]`;for(let h of["ownerNodePath","nodeIndex","nodeIndexPath","meshIndex","primitiveIndex","sourceMaterialIndex","sourceMaterialIndices","sourceMeshName","triangleCount","boundingBox"])if(Object.prototype.hasOwnProperty.call(f,h))throw y("schema.deprecatedField",`${p}.${h}`);if(!Array.isArray(f.sourceSurfaces))throw y("schema.invalidType",`${p}.sourceSurfaces`);if(f.sourceSurfaces.length===0)throw y("schema.invalidValue",`${p}.sourceSurfaces`);for(let h=0;h<f.sourceSurfaces.length;h+=1){let S=`${p}.sourceSurfaces[${h}]`,P=I(f.sourceSurfaces[h]);if(!P||!A(P.ownerNodePath))throw y("schema.invalidValue",S);lo(P,"nodeIndex",S),lo(P,"sourceMaterialIndex",S);for(let T of["meshIndex","primitiveIndex"])if(!Number.isInteger(P[T])||P[T]<0)throw y("schema.invalidValue",`${S}.${T}`);if(P.nodeIndexPath!=null&&(!Array.isArray(P.nodeIndexPath)||P.nodeIndexPath.some(T=>!Number.isInteger(T)||T<0)))throw y("schema.invalidValue",`${S}.nodeIndexPath`);let D=P.meshIndex;if(!A(P.sourceMeshName)&&!d.has(D))throw y("schema.invalidValue",`${S}.sourceMeshName`)}if(u.has(g))throw y("schema.invalidValue",`$.assets[${i}].metadata.materialSlots[${l}].slotId`);u.add(g)}n.set(s,u)}for(let i=0;i<e.length;i+=1){let o=I(e[i]);if(o?.type!=="prefab")continue;let s=I(o.prefab),a=A(s?.sourceAssetId);sr(s?.overrides,a?n.get(a):void 0,`$.assets[${i}].prefab.overrides`);let c=Array.isArray(s?.nodes)?s.nodes:[];for(let d=0;d<c.length;d+=1){let u=I(c[d]),l=A(u?.childPrefabId),f=A(u?.sourceAssetId)??(l?r.get(l)??null:null);sr(u?.overrides,f?n.get(f):void 0,`$.assets[${i}].prefab.nodes[${d}].overrides`)}}for(let i=0;i<t.length;i+=1){let o=I(t[i]),a=(Array.isArray(o?.components)?o.components:[]).map(I).find(d=>d?.type==="ModelRenderer"),c=A(a?.assetId);sr(o?.overrides,c?n.get(c):void 0,`$.scene.gameObjects[${i}].overrides`)}}function sr(e,t,n){let r=I(e);if(!r||r.materialSlotBindings==null)return;let i=I(r.materialSlotBindings);if(!i)throw y("schema.invalidType",`${n}.materialSlotBindings`);for(let[o,s]of Object.entries(i)){if(!t?.has(o))throw y("schema.invalidReference",`${n}.materialSlotBindings.${o}`);let a=`${n}.materialSlotBindings.${o}`,c=I(s);if(!c)throw y("schema.invalidType",a);for(let d of Object.keys(c))if(d!=="materialAssetId"&&d!=="override")throw y("schema.deprecatedField",`${a}.${d}`);if("materialAssetId"in c&&c.materialAssetId!=null&&!A(c.materialAssetId))throw y("schema.invalidValue",`${a}.materialAssetId`);if("override"in c&&!I(c.override))throw y("schema.invalidType",`${a}.override`);"override"in c&&sl(c.override,`${a}.override`)}}function lo(e,t,n){let r=e[t];if(r!=null&&(!Number.isInteger(r)||r<0))throw y("schema.invalidValue",`${n}.${t}`)}function ol(e){let t=I(e),n=Array.isArray(t?.meshes)?t.meshes:[];return new Set(n.flatMap(r=>{let i=I(r),o=i?.meshIndex,s=Number.isInteger(o)?o:null;return s!=null&&A(i?.name)?[s]:[]}))}function sl(e,t){let n=I(e);if(!n)throw y("schema.invalidType",t);if(it(n,["lightingModel","baseColor","normal","metallic","roughness","metallicRoughness","occlusion","emission","alpha"],t),"lightingModel"in n&&!["lit","unlit"].includes(String(n.lightingModel)))throw y("schema.invalidValue",`${t}.lightingModel`);for(let r of["metallic","roughness"])Dt(n,r,t);al(n.baseColor,`${t}.baseColor`),ar(n.normal,`${t}.normal`,["texture","strength"]),ar(n.metallicRoughness,`${t}.metallicRoughness`,["texture"]),ar(n.occlusion,`${t}.occlusion`,["texture","strength"]),dl(n.emission,`${t}.emission`),cl(n.alpha,`${t}.alpha`)}function al(e,t){if(e==null)return;let n=ot(e,t);it(n,["color","texture","brightness","saturation","contrast","hue"],t),po(n.color,`${t}.color`),Tt(n.texture,`${t}.texture`);for(let r of["brightness","saturation","contrast","hue"])Dt(n,r,t)}function ar(e,t,n){if(e==null)return;let r=ot(e,t);it(r,n,t),Tt(r.texture,`${t}.texture`),n.includes("strength")&&Dt(r,"strength",t)}function dl(e,t){if(e==null)return;let n=ot(e,t);it(n,["color","intensity","texture","maskTexture"],t),po(n.color,`${t}.color`),Dt(n,"intensity",t),Tt(n.texture,`${t}.texture`),Tt(n.maskTexture,`${t}.maskTexture`)}function cl(e,t){if(e==null)return;let n=ot(e,t);if(it(n,["mode","opacity","cutoff","texture"],t),"mode"in n&&!["opaque","mask","blend"].includes(String(n.mode)))throw y("schema.invalidValue",`${t}.mode`);for(let r of["opacity","cutoff"])Dt(n,r,t);Tt(n.texture,`${t}.texture`)}function Tt(e,t){if(e==null)return;let n=ot(e,t);it(n,["url","textureAssetId"],t);for(let r of["url","textureAssetId"])if(r in n&&n[r]!=null&&!A(n[r]))throw y("schema.invalidValue",`${t}.${r}`)}function po(e,t){if(e==null)return;let n=ot(e,t);for(let r of["r","g","b"])ll(n,r,t)}function it(e,t,n){let r=new Set(t);for(let i of Object.keys(e))if(!r.has(i))throw y("schema.deprecatedField",`${n}.${i}`)}function Dt(e,t,n){if(t in e&&e[t]!=null&&(typeof e[t]!="number"||!Number.isFinite(e[t])))throw y("schema.invalidType",`${n}.${t}`)}function ll(e,t,n){if(!(t in e)||typeof e[t]!="number"||!Number.isFinite(e[t]))throw y("schema.invalidValue",`${n}.${t}`)}function ot(e,t){let n=I(e);if(!n)throw y("schema.invalidType",t);return n}function y(e,t){let n=new Error(`${e}: ${t}`);return Object.assign(n,{code:e,path:t}),n}function I(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function A(e){return typeof e=="string"&&e.length>0&&e===e.trim()?e:null}function uo(e){return typeof e=="number"&&Number.isFinite(e)&&e>0}function yo(e,t,n={}){let r=go(e).document,i=t;Object.prototype.hasOwnProperty.call(i,"staticShadows")&&i.staticShadows!=null&&nn(i.staticShadows,"$.staticShadows");let{scene:o,...s}=t,a=structuredClone(s),c=re(o)?o:void 0,d=Xi(r),u={...d,compilerId:fo,compilerVersion:mo,compiledAt:new Date().toISOString()};a.schemaVersion=3,a.meta={...a.meta??{},generatedFrom:u};let l=c?.rootId||"root",f=r.scene.gameObjects.filter(D=>D.id!==l),g=pl(r,n.materialShaderDefinitions,!0),p={...r,scene:{...r.scene,materialAssets:g}},h=f.flatMap(D=>Tl(D,d,p,n)),S=h.map(ho);fl(l,S),ml(l,S);let P={rootId:l,assets:p.assets.filter(hl).map(Sl),nodes:S,materialAssets:g,materials:structuredClone(c?.materials??[]),textures:structuredClone(c?.textures??[])};return a.scene=P,a.plugins=kl(a.plugins,n.shadowMapExperimentConfig,h,l,d.revision),yi(a),{sceneConfig:a,summary:{assetCount:P.assets.length,gameObjectCount:r.scene.gameObjects.length,nodeCount:P.nodes.length}}}function ho(e){if(!Object.prototype.hasOwnProperty.call(e,"shadowMapExperimentInferredUpdateClass"))return e;let{shadowMapExperimentInferredUpdateClass:t,...n}=e;return n}function fl(e,t){let n=new Set([e]);for(let r=0;r<t.length;r+=1){let i=t[r].id;if(n.has(i)){let o=new Error(`schema.invalidReference: $.scene.nodes[${r}].id`);throw Object.assign(o,{code:"schema.invalidReference",path:`$.scene.nodes[${r}].id`,nodeId:i}),o}n.add(i)}}function ml(e,t){let n=new Map(t.map(r=>[r.id,r]));for(let r=0;r<t.length;r+=1){let i=t[r];if(!(i.source?.component!=="PrefabMarker"||!("marker"in i)||!i.marker))for(let o of gl(i.marker)){let s=n.get(o.target.id);if(o.target.id!==e&&(!s||s.source?.objectId===i.source.objectId))continue;let a=`$.scene.nodes[${r}].marker.${o.path}.id`,c=new Error(`schema.invalidReference: ${a}`);throw Object.assign(c,{code:"schema.invalidReference",path:a,nodeId:i.id,targetId:o.target.id}),c}}}function gl(e){let t=[];return e.target&&t.push({path:"target",target:e.target}),e.geometry.kind==="point"&&e.geometry.target&&t.push({path:"geometry.target",target:e.geometry.target}),e.geometry.kind==="object-bounds"&&t.push({path:"geometry.target",target:e.geometry.target}),t}function pl(e,t,n=!1){let r=structuredClone(e.scene.materialAssets??[]);for(let o=0;o<r.length;o+=1){let s=r[o];if(on(s.shaderId))continue;let a=t?.get(s.shaderId);if(!a){if(!n)continue;throw cr("material.shaderDefinitionNotFound",`$.scene.materialAssets[${o}].shaderId`,`Shader Definition was not found: ${s.shaderId}`)}if(s.definitionVersion!==a.version)throw cr("material.shaderDefinitionVersionMismatch",`$.scene.materialAssets[${o}].definitionVersion`,`Material ${s.id} uses Definition v${String(s.definitionVersion)} but ${s.shaderId} is v${a.version}.`);let c=sn(s.shaderId,s.properties,`$.scene.materialAssets[${o}].properties`,t);if(c[0])throw cr("material.propertiesInvalid",c[0].path,c[0].message)}let i=dn(bl(e,r));if(!i.ok)throw new Error(`editor_scene_material_assets_missing: ${i.missingMaterialAssetIds.join(", ")}`);return r}function cr(e,t,n){return Object.assign(new Error(`${e}: ${n}`),{code:e,path:t})}function bl(e,t){let n={...e,scene:{...e.scene,materialAssets:t}};return{...n,scene:{...n.scene,gameObjects:[...n.scene.gameObjects.map(r=>{let i=To(r,n);if(i)return{...r,overrides:i};if(!("overrides"in r))return r;let o={...r};return delete o.overrides,o}),...yl(n)]}}}function yl(e){let t=[];for(let n of e.scene.gameObjects){let r=un(e,n);!r.definition||!hn(r.definition)||t.push(...So({editorDocument:e,prefabAsset:r.definition,hostGameObject:n,instanceOverrides:n.overrides,visitedPrefabIds:new Set}))}return t}function So(e){if(e.visitedPrefabIds.has(e.prefabAsset.id))return[];e.visitedPrefabIds.add(e.prefabAsset.id);let t=Ao(Et(e.prefabAsset),It(e.prefabAsset)??""),n=t.find(o=>o.id===It(e.prefabAsset));if(!n)return e.visitedPrefabIds.delete(e.prefabAsset.id),[];let r=wo(t,e.prefabAsset),i=[];for(let o of t){if(o.kind==="prefabInstance"&&o.childPrefabId){let d=e.editorDocument.assets.find(u=>u.id===o.childPrefabId);if(d&&hn(d)){i.push(...So({editorDocument:e.editorDocument,prefabAsset:d,hostGameObject:e.hostGameObject,instanceOverrides:o.overrides,visitedPrefabIds:new Set(e.visitedPrefabIds)}));continue}continue}let s=Fl(e.hostGameObject,o);if(!s)continue;let a=o.kind==="model"&&o.sourceAssetId?e.editorDocument.assets.find(d=>d.id===o.sourceAssetId):void 0,c=gr({hostGameObject:s,prefabAsset:e.prefabAsset,rootNode:n,node:o,asset:a,editorDocument:e.editorDocument,instanceOverrides:o.id===r?e.instanceOverrides:void 0});c&&i.push({...s,overrides:c})}return e.visitedPrefabIds.delete(e.prefabAsset.id),i}function hl(e){return e.type==="glb"||e.type==="texture"}function Sl(e){let t=Il(e),n=e.type==="glb"?El(e):[],r=Pl(e.external),i=xl(e.defaults);return{id:e.id,type:e.type,...e.guid?{guid:e.guid}:{},...t?{url:t}:{},...typeof e.warmupCount=="number"&&Number.isInteger(e.warmupCount)&&e.warmupCount>=0?{warmupCount:e.warmupCount}:{},...typeof e.singleton=="boolean"?{singleton:e.singleton}:{},...typeof e.materialMode=="string"?{materialMode:e.materialMode}:{},...i!==void 0?{defaults:i}:{},...r?{external:r}:{},...n.length>0?{materialSlots:n}:{}}}function xl(e){if(!e)return;let t=structuredClone(e);return re(t)?(delete t.shadowMapExperiment,Object.keys(t).length>0?t:void 0):t}function Pl(e){let t=re(e)?e:void 0,n=we(t?.platformAssetId),r=we(t?.assetUrl);if(!(!n&&!r))return{...n?{platformAssetId:n}:{},...r?{assetUrl:r}:{}}}function Il(e){let t=re(e.metadata)?e.metadata:void 0,n=re(e.external)?e.external:void 0;return we(t?.url)??we(n?.assetUrl)??void 0}function El(e){let t=re(e.metadata)?e.metadata:void 0,n=Array.isArray(t?.materialSlots)?t.materialSlots:[],r=Al(t?.assetAnalysis);return n.flatMap(i=>{if(!re(i))return[];let o=we(i.slotId);if(!o)return[];let s=we(i.label),a=(Array.isArray(i.sourceSurfaces)?i.sourceSurfaces:[]).flatMap(c=>{if(!re(c))return[];let d=we(c.ownerNodePath),u=kt(c.meshIndex),l=kt(c.primitiveIndex);if(!d||u==null||l==null)return[];let f=kt(c.nodeIndex),g=wl(Array.isArray(c.nodeIndexPath)?c.nodeIndexPath:[]),p=kt(c.sourceMaterialIndex),h=we(c.sourceMeshName)??r.get(u);return[{ownerNodePath:d,...f==null?{}:{nodeIndex:f},...g.length>0?{nodeIndexPath:g}:{},meshIndex:u,primitiveIndex:l,...p==null?{}:{sourceMaterialIndex:p},...h?{sourceMeshName:h}:{}}]});return a.length===0?[]:[{slotId:o,...s?{label:s}:{},sourceSurfaces:a}]})}function Al(e){let t=re(e)?e:void 0,n=Array.isArray(t?.meshes)?t.meshes:[];return new Map(n.flatMap(r=>{if(!re(r))return[];let i=kt(r.meshIndex),o=we(r.name);return i==null||!o?[]:[[i,o]]}))}function wl(e){return[...new Set(e.filter(t=>typeof t=="number"&&Number.isInteger(t)&&t>=0))]}function kt(e){return typeof e=="number"&&Number.isInteger(e)&&e>=0?e:void 0}function Tl(e,t,n,r){let i=un(n,e);return(i.definition&&hn(i.definition)?Cl(e,i.definition,t,n,new Set,r):[Dl(e,t,n,r)]).map(s=>{let a=s.kind==="instance"?n.assets.find(d=>d.id===s.instance.assetId):void 0,c=r.inferShadowMapExperimentUpdateClass?.({gameObject:e,runtimeNode:ho(s),...a?{asset:a}:{}})??Ml(a);return{...s,shadowMapExperimentInferredUpdateClass:c}})}function Dl(e,t,n,r={}){let i=Xn(e),o=tt(e),s=Zn(e),a=Ll(e),c=nt(e),d=To(e,n),u=Vi(e),l={sourceId:t.sourceId,sourceType:t.sourceType,revision:t.revision,...e.guid?{objectGuid:e.guid}:{},objectId:e.id,component:o?"ModelRenderer":s?"ImageRenderer":a||c==="primitive"?"PrimitiveRenderer":c==="transform"?"Transform":"GameObject"},f={id:e.id,...e.name?{name:e.name}:{},...e.parentId?{parentId:e.parentId}:{},...e.active===!1?{enabled:!1}:{},...e.shadow?{shadow:structuredClone(e.shadow)}:{},...Nl(n,e,r),...u?{rendering:u}:{},source:l,...i&&"position"in i?{transform:{position:i.position,rotation:i.rotation,...i.scale?{scale:i.scale}:{}}}:{}};if(c==="primitive")return{...f,kind:"primitive",primitive:{shape:a?.shape??"cube"},...d?{overrides:d}:{}};if(s)return{...f,kind:"image",image:{assetId:s.assetId,size:{width:s.size.width,height:s.size.height}},...d?{overrides:d}:{}};if(!o){if(c==="transform"){let g=$l(e,r),p=g.transformType;delete g.transformType;let h=bo(p)??bo(e.transformType);return{...f,kind:"transform",...h?{transformType:h}:{},...e.camera?{camera:Bl(e.camera)}:{},...e.light?{light:Do(e.light)}:{},...e.marker?{marker:{label:e.name||e.id,...structuredClone(e.marker)}}:{},...g,...d?{overrides:d}:{}}}return{...f,kind:"group"}}return{...f,kind:"instance",instance:{assetId:o.assetId},...d?{overrides:d}:{}}}function kl(e,t,n,r,i){let o=(e??[]).filter(u=>u.pluginId!==jn);if(!t)return o;let s=n.find(u=>u.id===t.lightRef),a=s?.kind==="transform"&&s.light?.type==="directional"?s:void 0;if(!s&&t.enabled)throw new Error(`shadowMapExperiment.lightMissing:${t.lightRef}`);if(s&&!a&&t.enabled)throw new Error(`shadowMapExperiment.lightUnsupported:${t.lightRef}`);let c=a?.kind==="transform"&&a.light?.type==="directional"?[a.light.direction.x,a.light.direction.y,a.light.direction.z]:[0,-1,0],d=Kr({revision:typeof i=="number"&&Number.isInteger(i)&&i>=0?i:0,scopeId:r,config:t,lightDirection:c,objects:n.filter(u=>u.kind==="instance"||u.kind==="primitive").map(u=>({entityId:u.id,renderableIds:[u.id],cast:u.shadow?.cast==="enabled",receive:u.shadow?.receive==="enabled",inferredUpdateClass:u.shadowMapExperimentInferredUpdateClass??"static"}))});return[...o,{pluginId:jn,schemaVersion:3,data:d}]}function Ml(e){let t=re(e?.metadata?.assetAnalysis)?e.metadata.assetAnalysis:void 0;if(!t)return"static";let n=lr(t.skinCount),r=lr(t.morphTargetCount);return n>0||r>0?"skinned":lr(t.animationCount)>0?"dynamic":"static"}function lr(e){return typeof e=="number"&&Number.isFinite(e)&&e>=0?e:0}function Cl(e,t,n,r,i,o){return xo({prefabAsset:t,sourceRef:n,editorDocument:r,hostGameObject:e,rootRuntimeId:e.id,rootParentId:e.parentId,rootName:e.name??t.displayName??t.id,rootTransform:Xn(e)??void 0,rootActive:e.active,instanceOverrides:e.overrides,propertyPathPrefix:`assets.${t.id}.prefab.nodes`,visitedPrefabIds:i,compilerOptions:o})}function xo(e){if(e.visitedPrefabIds.has(e.prefabAsset.id))return[ur({id:e.rootRuntimeId,name:e.rootName??e.prefabAsset.displayName??e.prefabAsset.id,parentId:e.rootParentId,transform:e.rootTransform,editorDocument:e.editorDocument,sourceRef:e.sourceRef,hostGameObject:e.hostGameObject,component:"PrefabCycle",propertyPath:e.propertyPathPrefix})];e.visitedPrefabIds.add(e.prefabAsset.id);let t=Et(e.prefabAsset),n=It(e.prefabAsset),r=n?t.find(d=>d.id===n):null;if(!r||t.length===0)return e.visitedPrefabIds.delete(e.prefabAsset.id),[ur({id:e.rootRuntimeId,name:e.rootName??e.prefabAsset.displayName??e.prefabAsset.id,parentId:e.rootParentId,transform:e.rootTransform,editorDocument:e.editorDocument,sourceRef:e.sourceRef,hostGameObject:e.hostGameObject,component:"Prefab",propertyPath:e.propertyPathPrefix})];let i={instanceId:e.rootRuntimeId,rootNodeId:r.id},o=d=>tr(i,d.id),s=Ao(t,r.id),a=wo(s,e.prefabAsset),c=[];for(let d of s){let u=o(d),l=d.id===r.id?e.rootParentId:o(t.find(f=>f.id===d.parentId)??r);if(d.kind==="prefabInstance"&&d.childPrefabId){let f=e.editorDocument.assets.find(g=>g.id===d.childPrefabId);if(f&&hn(f)){let g=d.id===r.id;c.push(...xo({prefabAsset:f,sourceRef:e.sourceRef,editorDocument:e.editorDocument,hostGameObject:e.hostGameObject,rootRuntimeId:u,rootParentId:l,rootName:g?e.rootName??d.name??f.displayName??f.id:d.name??f.displayName??f.id,rootTransform:g?e.rootTransform??d.transform:d.transform,rootActive:g?e.rootActive??d.defaults?.active??e.prefabAsset.prefab?.defaults?.active:d.defaults?.active,instanceOverrides:g?Mt(Mt(xe(e.prefabAsset.prefab?.overrides),xe(d.overrides)),xe(e.instanceOverrides)):d.overrides,propertyPathPrefix:`${e.propertyPathPrefix}.${d.id}.childPrefab.nodes`,visitedPrefabIds:new Set(e.visitedPrefabIds),compilerOptions:e.compilerOptions}));continue}c.push(ur({id:u,name:d.name??d.childPrefabId??"Prefab Instance",parentId:l,transform:d.transform,sourceRef:e.sourceRef,editorDocument:e.editorDocument,hostGameObject:e.hostGameObject,component:"UnsupportedPrefabInstance",propertyPath:`${e.propertyPathPrefix}.${d.id}`}));continue}c.push(Rl({node:d,rootNode:r,identityScope:i,prefabAsset:e.prefabAsset,runtimeId:u,parentId:l,sourceRef:e.sourceRef,editorDocument:e.editorDocument,hostGameObject:e.hostGameObject,rootRuntimeName:e.rootName,rootRuntimeTransform:e.rootTransform,rootRuntimeActive:e.rootActive,instanceOverrides:d.id===a?e.instanceOverrides:void 0,propertyPath:`${e.propertyPathPrefix}.${d.id}`,shadowFallbackMode:mr(e.compilerOptions)}))}return e.visitedPrefabIds.delete(e.prefabAsset.id),vl({compiledNodes:c,editorDocument:e.editorDocument,hostGameObject:e.hostGameObject,shadowFallbackMode:mr(e.compilerOptions)})}function Rl(e){let t=e.node.id===e.rootNode.id,n=t?e.rootRuntimeTransform??e.node.transform:e.node.transform,r=e.node.kind==="model"&&e.node.sourceAssetId?e.editorDocument.assets.find(s=>s.id===e.node.sourceAssetId):void 0,i=e.node.kind==="model"||e.node.kind==="primitive",o=Po({id:e.runtimeId,name:t?e.rootRuntimeName??e.node.name??e.prefabAsset.displayName??e.prefabAsset.id:e.node.name,parentId:e.parentId,transform:n,active:t?e.rootRuntimeActive??e.node.defaults?.active??e.prefabAsset.prefab?.defaults?.active:e.node.defaults?.active,...i?{shadow:e.prefabAsset.prefab?.defaults?.shadow}:{},editorDocument:e.editorDocument,shadowFallbackMode:e.shadowFallbackMode,sourceRef:e.sourceRef,hostGameObject:e.hostGameObject,component:e.node.kind==="model"?"PrefabModel":e.node.kind==="primitive"?"PrefabPrimitive":e.node.kind==="light"?"PrefabLight":e.node.kind==="marker"?"PrefabMarker":"PrefabNode",propertyPath:e.propertyPath});if(e.node.kind==="model"&&e.node.sourceAssetId){let s=gr({hostGameObject:e.hostGameObject,prefabAsset:e.prefabAsset,rootNode:e.rootNode,node:e.node,asset:r,editorDocument:e.editorDocument,instanceOverrides:e.instanceOverrides});return{...o,kind:"instance",instance:{assetId:e.node.sourceAssetId},...s?{overrides:s}:{}}}if(e.node.kind==="primitive"){let s=gr({hostGameObject:e.hostGameObject,prefabAsset:e.prefabAsset,rootNode:e.rootNode,node:e.node,asset:void 0,editorDocument:e.editorDocument,instanceOverrides:e.instanceOverrides});return{...o,kind:"primitive",primitive:{shape:e.node.primitive?.shape??"cube"},...s?{overrides:s}:{}}}return e.node.kind==="light"?{...o,kind:"transform",transformType:"light",...e.node.light?{light:Do(e.node.light)}:{}}:e.node.kind==="marker"&&e.node.marker?{...o,kind:"transform",marker:{label:e.node.name??e.node.id,...Hi(e.node.marker,e.identityScope)}}:{...o,kind:"group"}}function ur(e){return{...Po({id:e.id,name:e.name,parentId:e.parentId,transform:e.transform,editorDocument:e.editorDocument,shadowFallbackMode:e.shadowFallbackMode,sourceRef:e.sourceRef,hostGameObject:e.hostGameObject,component:e.component,propertyPath:e.propertyPath}),kind:"group"}}function $l(e,t){let n=t.readCustomTransformRuntimeData?.(e);return n&&typeof n=="object"&&!Array.isArray(n)?structuredClone(n):{}}function Po(e){return{id:e.id,...e.name?{name:e.name}:{},...e.parentId?{parentId:e.parentId}:{},...e.active===!1?{enabled:!1}:{},...e.shadow?{shadow:structuredClone(e.shadow)}:{},...Ol(e),source:{sourceId:e.sourceRef.sourceId,sourceType:e.sourceRef.sourceType,revision:e.sourceRef.revision,...e.hostGameObject.guid?{objectGuid:e.hostGameObject.guid}:{},objectId:e.hostGameObject.id,component:e.component,propertyPath:e.propertyPath},...e.transform&&"position"in e.transform?{transform:{position:e.transform.position,rotation:e.transform.rotation,...e.transform.scale?{scale:e.transform.scale}:{}}}:{}}}function Nl(e,t,n){let r=mn({document:e,casterId:t.id,caster:t,fallbackMode:mr(n)});return pr(r,!!t.shadow)?{shadowPlan:r}:{}}function Ol(e){if(!e.editorDocument)return{};let t=De(e.shadow),n=!!e.shadow||!!t.shadow;if(!n&&t.diagnostics.length===0)return{};let r=mn({document:e.editorDocument,casterId:e.hostGameObject.id,caster:e.hostGameObject,resolvedSettings:t.shadow,fallbackMode:e.shadowFallbackMode}),i={...r,casterId:e.id,diagnostics:[...t.diagnostics,...r.diagnostics].map(o=>({...o,casterId:o.casterId===e.hostGameObject.id||!o.casterId?e.id:o.casterId}))};return pr(i,n)?{shadowPlan:i}:{}}function pr(e,t){return t||e.backend!=="none"||e.diagnostics.length>0}function vl(e){if(e.compiledNodes.length===0)return e.compiledNodes;let t=new Set(e.compiledNodes.map(s=>s.id)),n=e.compiledNodes.map(s=>Gl(s)),r={...e.editorDocument,scene:{...e.editorDocument.scene,gameObjects:[...e.editorDocument.scene.gameObjects.filter(s=>!t.has(s.id)),...n]}},i=e.compiledNodes.filter(s=>s.shadow?.receive==="enabled").map(s=>s.id),o=n.find(s=>s.light?.type==="directional"&&s.active!==!1)?.id;return e.compiledNodes.map((s,a)=>{let c=n[a],d=mn({document:r,casterId:s.id,caster:c,explicitReceiverIds:i,...o?{defaultLightId:o}:{},fallbackMode:e.shadowFallbackMode}),u=!!s.shadow;if(!pr(d,u)){if(!s.shadowPlan)return s;let l={...s};return delete l.shadowPlan,l}return{...s,shadowPlan:d}})}function mr(e){let t=Xt(e.renderingProfile).shadows,n=t.planar.enabled?"planar":t.blob.enabled?"blob":t.staticProjected.enabled?"static":t.enabled?"dynamic":"none";return n==="planar"?"projected":n}function Gl(e){let t=[];return e.transform&&t.push({type:"Transform",position:e.transform.position,rotation:e.transform.rotation,...e.transform.scale?{scale:e.transform.scale}:{}}),e.kind==="instance"&&t.push({type:"ModelRenderer",assetId:e.instance.assetId}),e.kind==="image"&&t.push({type:"ImageRenderer",assetId:e.image.assetId,size:structuredClone(e.image.size)}),{id:e.id,...e.name?{name:e.name}:{},kind:e.kind==="image"?"transform":e.kind,...e.parentId?{parentId:e.parentId}:{},...e.enabled===!1?{active:!1}:{},...e.shadow?{shadow:{cast:e.shadow.cast==="enabled"?"enabled":"none",receive:e.shadow.receive==="enabled"?"enabled":"none"}}:{},...e.kind==="primitive"?{primitive:{shape:e.primitive.shape}}:{},...e.kind==="transform"&&e.transformType?{transformType:e.transformType}:{},...e.kind==="transform"&&e.light?{light:e.light}:{},...e.kind==="transform"&&e.camera?{camera:e.camera}:{},...e.kind==="transform"&&e.marker?{marker:structuredClone(e.marker)}:{},components:t}}function gr(e){let t=e.node.kind==="model"&&e.node.sourceAssetId?Eo(e.hostGameObject,e.node,e.node.sourceAssetId):e.hostGameObject,n=e.asset?.id,r=_l([fr(xe(e.prefabAsset.prefab?.overrides),e.prefabAsset.prefab?.sourceAssetId,e.asset),fr(xe(e.rootNode.overrides),e.rootNode.kind==="model"?e.rootNode.sourceAssetId:e.prefabAsset.prefab?.sourceAssetId,e.asset),e.node.id===e.rootNode.id?void 0:fr(xe(e.node.overrides),e.node.kind==="model"?e.node.sourceAssetId:n,e.asset)]),i=xe(e.instanceOverrides);return Io(Mt(r,i),e.asset)}function fr(e,t,n){return Io(e,t&&t===n?.id?n:void 0)}function Io(e,t){if(!e?.materialSlotBindings)return e;let n=re(t?.metadata)&&Array.isArray(t.metadata.materialSlots)?t.metadata.materialSlots:[],r=new Set(n.flatMap(s=>{let a=re(s)&&typeof s.slotId=="string"?s.slotId.trim():"";return a?[a]:[]})),i=Object.fromEntries(Object.entries(e.materialSlotBindings).filter(([s])=>r.has(s))),o=structuredClone(e);return Object.keys(i).length>0?o.materialSlotBindings=i:delete o.materialSlotBindings,Object.keys(o).length>0?o:void 0}function Eo(e,t,n){return{id:`${e.id}:${t.id}`,...t.name?{name:t.name}:{},kind:"instance",components:[...t.transform?[t.transform]:[],{type:"ModelRenderer",assetId:n}]}}function jl(e,t){return{id:`${e.id}:${t.id}`,...t.name?{name:t.name}:{},kind:"primitive",primitive:{shape:t.primitive?.shape??"cube"},components:[...t.transform?[t.transform]:[]]}}function Fl(e,t){return t.kind==="model"&&t.sourceAssetId?Eo(e,t,t.sourceAssetId):t.kind==="primitive"?jl(e,t):null}function _l(e){let t;for(let n of e){let r=xe(n);r&&(t=Mt(t,r))}return t}function Ao(e,t){let n=new Map;for(let a of e){if(!a.parentId)continue;let c=n.get(a.parentId)??[];c.push(a),n.set(a.parentId,c)}let r=[],i=new Set,o=a=>{if(!i.has(a.id)){i.add(a.id),r.push(a);for(let c of n.get(a.id)??[])o(c)}},s=e.find(a=>a.id===t);s&&o(s);for(let a of e)o(a);return r}function wo(e,t){let n=t.prefab?.sourceAssetId;return e.find(r=>r.kind==="model"&&r.sourceAssetId===n)?.id??e.find(r=>r.kind==="model")?.id}function hn(e){return cn(e)&&e.prefab.compositionVersion===ln&&Array.isArray(e.prefab.nodes)&&e.prefab.nodes.length>0&&!!It(e)}function Ll(e){return e.primitive??null}function To(e,t){let n=nt(e);if(n!=="instance"&&n!=="transform"&&n!=="primitive")return;let r=tt(e),i=r?t.assets.find(o=>o.id===r.assetId):void 0;return zl(e,t,i)}function zl(e,t,n){let r=xe(e.overrides),i=un(t,e),o=xe(i.definition?.prefab?.overrides);return Mt(o,r)}function Mt(e,t){let n=Bi(e,t);for(let r of[e,t])if(r)for(let[i,o]of Object.entries(r))Ul(i)||o===void 0||(n??={},n[i]=structuredClone(o));return n&&Object.keys(n).length>0?n:void 0}function xe(e){if(!re(e))return;let t=structuredClone(e);return Object.keys(t).length>0?t:void 0}function Ul(e){return e==="materialBinding"||e==="materialSlotBindings"}function re(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function we(e){return(typeof e=="string"?e.trim():"")||void 0}function bo(e){return typeof e=="string"?e:void 0}function Bl(e){let t=structuredClone(e);return delete t.inspectorLanguage,t}function Do(e){return e.type==="directional"?qe({schemaVersion:1,type:"directional",intensity:e.intensity,direction:ft(e.direction),diffuseColor:e.diffuseColor??Qi.diffuseColor}):qe({schemaVersion:1,type:"hemispheric",intensity:e.intensity,diffuseColor:e.diffuseColor??rr.diffuseColor,groundColor:e.groundColor??rr.groundColor})}function Vl(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function ko(e){let t=Vl(e);if(t==null)return null;let n=t%360;n>180&&(n-=360),n<=-180&&(n+=360);let r=Kl(n);return Object.is(r,-0)?0:r}function Kl(e){return Math.round(e*1e3)/1e3}var Hl=new Set(["leftToRight","rightToLeft","bottomToTop","topToBottom"]);function Ro(e){let t=Ii(e),n={uiKind:e.uiKind,size:{width:e.size.width,depth:e.size.depth},layers:e.layers.map((r,i)=>Wl(r,i)),rendering:{textureWidth:t.width,textureHeight:t.height}};return e.aspectSourceLayerId&&(n.aspectSourceLayerId=e.aspectSourceLayerId),typeof e.lockAspectToBorder=="boolean"&&(n.lockAspectToBorder=e.lockAspectToBorder),e.mask&&(n.mask={...typeof e.mask.enabled=="boolean"?{enabled:e.mask.enabled}:{},...e.mask.source==="roundedRect"||e.mask.source==="borderAlpha"||e.mask.source==="texture"?{source:e.mask.source}:{},...e.mask.textureId?{textureId:e.mask.textureId}:{},...typeof e.mask.cornerRadius=="number"&&Number.isFinite(e.mask.cornerRadius)?{cornerRadius:e.mask.cornerRadius}:{},...typeof e.mask.padding=="number"&&Number.isFinite(e.mask.padding)?{padding:e.mask.padding}:{}}),e.rendering&&(n.rendering={...n.rendering,...typeof e.rendering.alphaIndex=="number"&&Number.isFinite(e.rendering.alphaIndex)?{alphaIndex:e.rendering.alphaIndex}:{},...typeof e.rendering.diffuseTextureLevel=="number"&&Number.isFinite(e.rendering.diffuseTextureLevel)?{diffuseTextureLevel:e.rendering.diffuseTextureLevel}:{},...typeof e.rendering.emissiveTextureLevel=="number"&&Number.isFinite(e.rendering.emissiveTextureLevel)?{emissiveTextureLevel:e.rendering.emissiveTextureLevel}:{}}),n}function Wl(e,t){let n=ko(e.rotationDeg??0)??0,r={id:e.id,role:e.role,zOrder:typeof e.zOrder=="number"&&Number.isFinite(e.zOrder)?e.zOrder:t,rect:ql(e.rect),...n!==0?{rotationDeg:n}:{},...typeof e.enabled=="boolean"?{enabled:e.enabled}:{},...typeof e.opacity=="number"&&Number.isFinite(e.opacity)?{opacity:e.opacity}:{}};return e.kind==="texture"?{...r,kind:"texture",...e.textureId?{textureId:e.textureId}:{},...e.tint?{tint:st(e.tint)}:{},...e.imageFit?{imageFit:e.imageFit}:{}}:e.kind==="textureProgress"?{...r,kind:"textureProgress",...e.textureId?{textureId:e.textureId}:{},value:Co(e.value),...e.tint?{tint:st(e.tint)}:{},...e.imageFit?{imageFit:e.imageFit}:{},...Mo(e.direction)?{direction:e.direction}:{}}:e.kind==="color"?{...r,kind:"color",color:st(e.color)}:e.kind==="progress"?{...r,kind:"progress",value:Co(e.value??0),color:st(e.color),...Mo(e.direction)?{direction:e.direction}:{}}:{...r,kind:"text",text:{value:e.text.value,color:st(e.text.color),...e.text.fontFamily?{fontFamily:e.text.fontFamily}:{},...typeof e.text.fontSize=="number"&&Number.isFinite(e.text.fontSize)?{fontSize:e.text.fontSize}:{},...e.text.fontWeight!=null?{fontWeight:String(e.text.fontWeight)}:{},...e.text.strokeColor?{strokeColor:st(e.text.strokeColor)}:{},...typeof e.text.strokeWidth=="number"&&Number.isFinite(e.text.strokeWidth)?{strokeWidth:e.text.strokeWidth}:{},...e.text.align==="left"||e.text.align==="center"||e.text.align==="right"?{align:e.text.align}:{},...e.text.baseline==="top"||e.text.baseline==="middle"||e.text.baseline==="bottom"?{baseline:e.text.baseline}:{}}}}function ql(e){return{x:e.x,z:e.z,width:e.width,depth:e.depth}}function st(e){return{r:e.r,g:e.g,b:e.b,...typeof e.a=="number"?{a:e.a}:{}}}function Mo(e){return typeof e=="string"&&Hl.has(e)}function Co(e){return Number.isFinite(e)?Math.max(0,Math.min(1,e)):0}var $o=["model","texture","image","sound"],br=[".glb",".gltf"],No=[".png",".jpg",".jpeg",".webp"],Jl=[".env",".hdr",".dds",".ktx",".ktx2"],yr=[...No,...Jl],hr=[".mp3",".wav",".ogg",".flac",".aac",".m4a"],Ct=[...br,...yr,...hr];function Xl(e){return String(e??"").trim().toLowerCase().replace(/-/g,"")}function Sr(e,t){let n=Xl(t);return`${e==="model"?"asset":e==="texture"?"texture":e==="sound"?"sound":"image"}_${n}`}function xr(e){let i=String(e??"").trim().split(/[^a-zA-Z0-9_$]+/).filter(Boolean).map((o,s)=>s===0?o:`${o.charAt(0).toUpperCase()}${o.slice(1)}`).join("").replace(/[^a-zA-Z0-9_$]/g,"")||"assetUrl";return/^[a-zA-Z_$]/.test(i)?i:`asset${i}`}function Pr(e,t=""){let n=String(e??"").trim().toLowerCase();if(n==="glb"||n==="gltf"||n==="model")return"model";if(n==="groundtexture"||n==="ground-texture"||n==="texture")return"texture";if(n==="ui"||n==="image"||n==="img")return"image";if(n==="audio"||n==="sound")return"sound";let r=Zl(t);return br.includes(r)?"model":hr.includes(r)?"sound":yr.includes(r)?"texture":null}function Zl(e){let t=e.split(/[?#]/,1)[0]??"",n=Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\")),r=t.slice(n+1),i=r.lastIndexOf(".");return i>=0?r.slice(i).toLowerCase():""}function Oo(e){let t=String(e??"").trim(),n=t.toLowerCase();for(let r of[...Ct].sort((i,o)=>o.length-i.length))if(n.endsWith(r)){t=t.slice(0,-r.length);break}return t}function vo(e,t){return String(e??"").trim()||Oo(t)||"Asset"}function Go(e,t){return Oo(e||t).trim().toLowerCase().normalize("NFKD").replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"").replace(/_{2,}/g,"_")||null}function jo(e){return e==="model"?br:e==="sound"?hr:e==="texture"?yr:e==="image"?No:[]}function Sn(e,t={}){let n=t.generatedBy??"scripts/register-asset.mjs",r=t.codeKeyPolicy??"legacy",i=e.filter(d=>d.codeKey);if(r==="disabled"&&i.length>0){let d=i[0];throw Object.assign(new Error("manifest_code_key_disabled"),{name:"PlayableEditorAssetCatalogGenerationError",details:{codeKeyPolicy:r,assetId:d.assetId,codeKey:d.codeKey}})}let o=e.map(d=>`import ${xr(d.assetId)} from ${JSON.stringify(`${d.relativePath}?url`)};`).join(`
|
|
4
4
|
`),s=e.map(d=>{let u=si(d.relativePath);if(!u)throw new Error(`Generated asset catalog entry has no file extension: ${d.assetId}`);if(!ai(u))throw new Error(`Generated asset catalog entry has unsupported format: ${d.assetId} (${u})`);let l=[`guid: ${JSON.stringify(d.guid)}`,`assetId: ${JSON.stringify(d.assetId)}`,`kind: ${JSON.stringify(d.kind)}`,`displayName: ${JSON.stringify(d.displayName)}`,`url: ${xr(d.assetId)}`,`format: ${JSON.stringify(u)}`,`relativePath: ${JSON.stringify(d.relativePath)}`,d.originalFileName?`originalFileName: ${JSON.stringify(d.originalFileName)}`:"",d.codeKey?`codeKey: ${JSON.stringify(d.codeKey)}`:"",d.category?`category: ${JSON.stringify(d.category)}`:"",typeof d.placeable=="boolean"?`placeable: ${JSON.stringify(d.placeable)}`:"",typeof d.warmupCount=="number"?`warmupCount: ${JSON.stringify(d.warmupCount)}`:"",typeof d.singleton=="boolean"?`singleton: ${JSON.stringify(d.singleton)}`:"",d.materialMode?`materialMode: ${JSON.stringify(d.materialMode)}`:"",d.defaults?`defaults: ${JSON.stringify(d.defaults)}`:"",d.contentHash?`contentHash: ${JSON.stringify(d.contentHash)}`:"",typeof d.byteSize=="number"?`byteSize: ${JSON.stringify(d.byteSize)}`:"",d.external?`external: ${JSON.stringify(d.external)}`:"",d.metadata?`metadata: ${JSON.stringify(d.metadata)}`:"",d.createdAt?`createdAt: ${JSON.stringify(d.createdAt)}`:"",d.updatedAt?`updatedAt: ${JSON.stringify(d.updatedAt)}`:""].filter(Boolean).join(", ");return` ${JSON.stringify(d.assetId)}: { ${l} },`}).join(`
|
|
5
5
|
`),a=new Map;for(let d of i)a.set(d.codeKey,d.assetId);let c=[...a].map(([d,u])=>` ${JSON.stringify(d)}: ${JSON.stringify(u)},`).join(`
|
|
6
6
|
`);return[`// This file is generated by ${n}.`,"// Do not edit by hand.","",o,"",'export type GeneratedAssetCatalogKind = "model" | "texture" | "image" | "sound";',"","export interface GeneratedAssetCatalogEntry {"," guid: string;"," assetId: string;"," kind: GeneratedAssetCatalogKind;"," displayName: string;"," url: string;"," format: `.${string}`;"," relativePath: string;"," originalFileName?: string;",...r==="legacy"?[" /** @deprecated Use the canonical assetId for persisted and runtime identity. */"," codeKey?: string;"]:[]," category?: string;"," placeable?: boolean;"," warmupCount?: number;"," singleton?: boolean;"," materialMode?: string;"," defaults?: Record<string, unknown>;"," contentHash?: string;"," byteSize?: number;"," external?: { platformAssetId?: string; assetPath?: string; assetUrl?: string };"," metadata?: Record<string, unknown>;"," createdAt?: string;"," updatedAt?: string;","}","","export const GENERATED_ASSET_CATALOG: Record<string, GeneratedAssetCatalogEntry> = {",s,"};","","export const GENERATED_ASSET_URL_MAP = Object.fromEntries("," Object.entries(GENERATED_ASSET_CATALOG).map(([assetId, entry]) => [assetId, entry.url]),",") as Record<string, string>;","","export const GENERATED_MODEL_ASSET_URL_MAP = Object.fromEntries(",' Object.entries(GENERATED_ASSET_CATALOG).filter(([, entry]) => entry.kind === "model").map(([assetId, entry]) => [assetId, entry.url]),',") as Record<string, string>;","","export const GENERATED_TEXTURE_ASSET_URL_MAP = Object.fromEntries(",' Object.entries(GENERATED_ASSET_CATALOG).filter(([, entry]) => entry.kind === "texture").map(([assetId, entry]) => [assetId, entry.url]),',") as Record<string, string>;","","export const GENERATED_IMAGE_ASSET_URL_MAP = Object.fromEntries(",' Object.entries(GENERATED_ASSET_CATALOG).filter(([, entry]) => entry.kind === "image").map(([assetId, entry]) => [assetId, entry.url]),',") as Record<string, string>;","","export const GENERATED_SOUND_ASSET_URL_MAP = Object.fromEntries(",' Object.entries(GENERATED_ASSET_CATALOG).filter(([, entry]) => entry.kind === "sound").map(([assetId, entry]) => [assetId, entry.url]),',") as Record<string, string>;","","/** @deprecated Resolve assets by canonical assetId through GENERATED_ASSET_CATALOG. */","export const ASSET_IDS = {",c,"} as const satisfies Record<string, string>;"].join(`
|
|
7
7
|
`)+`
|
|
8
|
-
`}import In from"node:crypto";import{constants as Ru}from"node:fs";import R from"node:fs/promises";import w from"node:path";import Ir from"node:fs/promises";import ae from"node:path";var Er=5;async function xn(e){let t={...e.existingMetadata??{},...e.payloadMetadata??{}},n=await Yl(e);if(n?(t.assetAnalysis=n,t.assetAnalysisStatus="complete"):(delete t.assetAnalysis,t.assetAnalysisStatus="unavailable"),e.kind==="texture"||e.kind==="image"){let i=Iu(e.sourcePath,t);return i&&(t.textureUsage=i.usage,t.capabilities={...V(t.capabilities)?t.capabilities:{},materialTexture:i.materialTexture,environmentTexture:i.environmentTexture}),Object.keys(t).length>0?t:null}if(e.kind!=="model")return Object.keys(t).length>0?t:null;t.assetMetadataVersion=Er;let r=await Ql(e.sourcePath,{assetGuid:e.guid,assetId:e.assetId,cwd:e.cwd,assetsDir:e.assetsDir,existingMaterialSlots:t.materialSlots});return r.length===0?delete t.materialSlots:t.materialSlots=r,Object.keys(t).length>0?t:null}async function Yl(e){return e.kind==="model"?eu(e.sourcePath):e.kind==="texture"||e.kind==="image"?tu(e.sourcePath):null}async function Ql(e,t={}){try{let n=await zo(e);return fu(n,{...t,sourcePath:e})}catch{return[]}}async function zo(e){let t=ae.extname(e).toLowerCase();if(t===".gltf")return JSON.parse(await Ir.readFile(e,"utf8"));if(t!==".glb")return null;let n=await Ir.readFile(e);if(n.length<20||n.toString("utf8",0,4)!=="glTF"||n.readUInt32LE(4)!==2||n.readUInt32LE(8)>n.length)return null;let o=12;for(;o+8<=n.length;){let s=n.readUInt32LE(o),a=n.readUInt32LE(o+4);if(o+=8,o+s>n.length)return null;if(a===1313821514){let c=n.toString("utf8",o,o+s).replace(/\0+$/g,"");return JSON.parse(c)}o+=s}return null}async function eu(e){try{let t=await zo(e);if(!t||typeof t!="object")return null;let n=Array.isArray(t.scenes)?t.scenes:[],r=Array.isArray(t.nodes)?t.nodes:[],i=Array.isArray(t.meshes)?t.meshes:[],o=Array.isArray(t.materials)?t.materials:[],s=Array.isArray(t.textures)?t.textures:[],a=Array.isArray(t.images)?t.images:[],c=Array.isArray(t.animations)?t.animations:[],d=Array.isArray(t.skins)?t.skins:[],u=Array.isArray(t.accessors)?t.accessors:[],l=Ho(t),f=Wo(r),g=new Set(l),p=i.reduce((T,$)=>T+(Array.isArray($?.primitives)?$.primitives.length:0),0),h=i.reduce((T,$)=>T+(Array.isArray($?.primitives)?$.primitives.reduce((_,q)=>_+(Array.isArray(q?.targets)?q.targets.length:0),0):0),0),S=su({nodeCount:r.length,meshCount:i.length,primitiveCount:p,materialCount:o.length,textureCount:s.length,imageCount:a.length}),P=au({nodeCount:r.length,meshCount:i.length,primitiveCount:p,materialCount:o.length,textureCount:s.length,imageCount:a.length,animationCount:c.length,skinCount:d.length,morphTargetCount:h,complexity:S});return{kind:"gltf",format:ae.extname(e).toLowerCase()===".gltf"?"gltf":"glb",summary:`${r.length} nodes, ${i.length} meshes, ${p} primitives, ${o.length} materials`,complexity:S,sceneCount:n.length,nodeCount:r.length,meshCount:i.length,primitiveCount:p,materialCount:o.length,textureCount:s.length,imageCount:a.length,animationCount:c.length,skinCount:d.length,morphTargetCount:h,nodes:nu(r,i,o,u,f,g),meshes:ru(i,o,u),materials:iu(t),diagnostics:P}}catch{return null}}async function tu(e){try{let t=await Ir.readFile(e),n=ae.extname(e).toLowerCase(),r=n===".png"?du(t):n===".jpg"||n===".jpeg"?cu(t):n===".webp"?lu(t):null;if(!r)return null;let i=uu(r);return{kind:"image",format:r.format,summary:`${r.width}x${r.height} ${r.mime}`,complexity:r.estimatedPixels>=4096*4096?"high":r.estimatedPixels>=2048*2048?"medium":"low",width:r.width,height:r.height,mime:r.mime,bitDepth:r.bitDepth,hasAlpha:r.hasAlpha,estimatedPixels:r.estimatedPixels,diagnostics:i}}catch{return null}}function nu(e,t,n,r,i,o){return e.slice(0,100).map((s,a)=>{let c=Number.isInteger(s?.mesh)?s.mesh:-1,d=c>=0&&c<t.length?t[c]:null,u=Array.isArray(s?.children)?s.children.filter(g=>Number.isInteger(g)):[],l=qo(e,i,o,a),f={nodeIndex:a,nodeIndexPath:Xo(i,a),...typeof s?.name=="string"&&s.name.trim()?{name:s.name.trim()}:{},...l?{ownerNodePath:l}:{},...u.length>0?{children:u}:{}};if(d){let g=Uo(d,n,r);Object.assign(f,{meshIndex:c,...typeof d?.name=="string"&&d.name.trim()?{meshName:d.name.trim()}:{},primitiveCount:g.length,...g.length>0?{primitives:g}:{}})}return f})}function ru(e,t,n){return e.slice(0,50).map((r,i)=>{let o=Array.isArray(r?.primitives)?r.primitives:[],s=[...new Set(o.map(c=>Number.isInteger(c?.material)?c.material:-1).filter(c=>c>=0))],a=Uo(r,t,n);return{meshIndex:i,...typeof r?.name=="string"&&r.name.trim()?{name:r.name.trim()}:{},primitiveCount:o.length,...a.length>0?{primitives:a}:{},...s.length>0?{materialIndices:s}:{},...s.length>0?{materialNames:s.map(c=>{let d=t[c];return typeof d?.name=="string"?d.name.trim():""}).filter(Boolean)}:{}}})}function Uo(e,t,n){let r=V(e)?e:{};return(Array.isArray(r.primitives)?r.primitives:[]).map((o,s)=>{let a=Number.isInteger(o?.material)?o.material:-1,c=a>=0?t[a]:null,d=typeof c?.name=="string"&&c.name.trim()?c.name.trim():"",u=Zo(o,n),l=Yo(o,n);return{primitiveIndex:s,...Number.isInteger(o?.mode)?{mode:o.mode}:{},...a>=0?{sourceMaterialIndex:a}:{},...d?{materialName:d}:{},...Number.isFinite(u)?{triangleCount:u}:{},...l?{boundingBox:l}:{}}})}function iu(e){return(Array.isArray(e?.materials)?e.materials:[]).slice(0,50).map((n,r)=>{let i=n?.pbrMetallicRoughness&&typeof n.pbrMetallicRoughness=="object"?n.pbrMetallicRoughness:{},o=ou(n,i);return{sourceMaterialIndex:r,...typeof n?.name=="string"&&n.name.trim()?{materialName:n.name.trim()}:{},...Array.isArray(i.baseColorFactor)?{baseColorFactor:i.baseColorFactor.slice(0,4)}:{},metallicFactor:Number.isFinite(i.metallicFactor)?i.metallicFactor:1,roughnessFactor:Number.isFinite(i.roughnessFactor)?i.roughnessFactor:1,alphaMode:Vo(n?.alphaMode)??"opaque",...Number.isFinite(n?.alphaCutoff)?{alphaCutoff:n.alphaCutoff}:{},...o.length>0?{textureSlots:o}:{}}})}function ou(e,t){let n=[];return Rt(n,"baseColor",t?.baseColorTexture),Rt(n,"metallicRoughness",t?.metallicRoughnessTexture),Rt(n,"normal",e?.normalTexture),Rt(n,"occlusion",e?.occlusionTexture),Rt(n,"emissive",e?.emissiveTexture),n}function Rt(e,t,n){!V(n)||!Number.isInteger(n.index)||e.push({slot:t,textureIndex:n.index,...Number.isFinite(n.texCoord)?{texCoord:n.texCoord}:{}})}function su(e){return e.nodeCount>=300||e.meshCount>=250||e.primitiveCount>=300||e.materialCount>=200||e.textureCount>=80||e.imageCount>=80?"high":e.nodeCount>=100||e.meshCount>=80||e.primitiveCount>=100||e.materialCount>=50||e.textureCount>=24||e.imageCount>=24?"medium":"low"}function au(e){let t=[];return e.complexity==="high"&&t.push({severity:"warning",source:"asset",code:"asset.analysis.highComplexity",message:"GLTF asset is structurally complex; agent should place and inspect it before duplicating or using dense shadows.",details:{nodeCount:e.nodeCount,meshCount:e.meshCount,primitiveCount:e.primitiveCount,materialCount:e.materialCount,textureCount:e.textureCount,imageCount:e.imageCount}}),(e.animationCount>0||e.skinCount>0||e.morphTargetCount>0)&&t.push({severity:"info",source:"asset",code:"asset.analysis.riggedOrAnimated",message:"GLTF asset contains animation, skin, or morph target data.",details:{animationCount:e.animationCount,skinCount:e.skinCount,morphTargetCount:e.morphTargetCount}}),t}function du(e){if(e.length<33||e[0]!==137||e.toString("ascii",1,4)!=="PNG"||e[4]!==13||e[5]!==10||e[6]!==26||e[7]!==10||e.toString("ascii",12,16)!=="IHDR")return null;let n=e.readUInt32BE(16),r=e.readUInt32BE(20),i=e[24],o=e[25],s=!1,a=33;for(;a+12<=e.length;){let c=e.readUInt32BE(a),d=a+12+c;if(d>e.length)break;let u=e.toString("ascii",a+4,a+8);if(u==="tRNS"){s=!0;break}if(u==="IDAT"||u==="IEND")break;a=d}return{format:"png",mime:"image/png",width:n,height:r,bitDepth:i,hasAlpha:o===4||o===6||s,estimatedPixels:n*r}}function cu(e){if(e.length<4||e[0]!==255||e[1]!==216)return null;let t=2;for(;t+9<e.length;){if(e[t]!==255){t+=1;continue}let n=e[t+1],r=e.readUInt16BE(t+2);if(r<2)return null;if(n>=192&&n<=207&&![196,200,204].includes(n)&&t+8<e.length){let o=e[t+4],s=e.readUInt16BE(t+5),a=e.readUInt16BE(t+7);return{format:"jpeg",mime:"image/jpeg",width:a,height:s,bitDepth:o,hasAlpha:!1,estimatedPixels:a*s}}t+=2+r}return null}function lu(e){if(e.length<30||e.toString("ascii",0,4)!=="RIFF"||e.toString("ascii",8,12)!=="WEBP")return null;let t=e.toString("ascii",12,16);if(t==="VP8X"&&e.length>=30){let n=e[20],r=Fo(e,24)+1,i=Fo(e,27)+1;return{format:"webp",mime:"image/webp",width:r,height:i,hasAlpha:(n&16)!==0,estimatedPixels:r*i}}if(t==="VP8 "&&e.length>=30){let n=e.readUInt16LE(26)&16383,r=e.readUInt16LE(28)&16383;return{format:"webp",mime:"image/webp",width:n,height:r,hasAlpha:!1,estimatedPixels:n*r}}if(t==="VP8L"&&e.length>=25&&e[20]===47){let n=e.readUInt32LE(21),r=(n&16383)+1,i=(n>>14&16383)+1;return{format:"webp",mime:"image/webp",width:r,height:i,hasAlpha:!0,estimatedPixels:r*i}}return null}function Fo(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16}function uu(e){let t=[];return e.estimatedPixels>=4096*4096&&t.push({severity:"warning",source:"asset",code:"asset.analysis.largeImage",message:"Image asset is large; agent should inspect texture usage before assigning it broadly.",details:{width:e.width,height:e.height,estimatedPixels:e.estimatedPixels}}),t}function fu(e,t={}){if(!e||typeof e!="object")return[];let n=Array.isArray(e.nodes)?e.nodes:[],r=Array.isArray(e.meshes)?e.meshes:[],i=Array.isArray(e.materials)?e.materials:[],o=gu(e,t),s=Ho(e),a=Wo(n),c=new Set(s),d=Array.isArray(e.accessors)?e.accessors:[],u=Su(t.existingMaterialSlots),l=[],f=new Map;for(let g=0;g<n.length;g+=1){let p=n[g],h=Number.isInteger(p?.mesh)?p.mesh:-1;if(h<0||h>=r.length)continue;let S=qo(n,a,c,g);if(!S)continue;let P=r[h],D=Array.isArray(P?.primitives)?P.primitives:[],T=Au(p,P,S),$=Jo(P),_=Xo(a,g);for(let q=0;q<D.length;q+=1){let ve=D[q],m=wu(ve,i),L=Ko({ownerNodePath:S,nodeIndex:g,meshIndex:h,primitiveIndex:q}),b=Zo(ve,d),j=Yo(ve,d),W=D.length>1?`${T} / Primitive ${q}`:T,J={ownerNodePath:S,nodeIndex:g,nodeIndexPath:_,meshIndex:h,primitiveIndex:q,...$?{sourceMeshName:$}:{},...m.index>=0?{sourceMaterialIndex:m.index}:{},...Number.isFinite(b)?{triangleCount:b}:{},...j?{boundingBox:j}:{}};if(m.index>=0){let z=f.get(m.index)??{label:W,materialName:m.name,sourceSurfaces:[]};z.sourceSurfaces.push(J),f.set(m.index,z);continue}l.push({slotId:u.byExactSource.get(L)??xu({assetGuid:t.assetGuid,assetId:t.assetId,nodeIndex:g,meshIndex:h,primitiveIndex:D.length>1?q:void 0}),label:W,sourceSurfaces:[J]})}}for(let[g,p]of f){let h=p.sourceSurfaces.sort(Bo);l.push({slotId:u.bySourceMaterialIndex.get(g)??Pu({assetGuid:t.assetGuid,assetId:t.assetId,sourceMaterialIndex:g}),label:p.label,sourceSurfaces:h,...p.materialName?{materialName:p.materialName,materialNames:[p.materialName]}:{},...pu(o,[g])})}return l.sort(mu)}function mu(e,t){let n=Array.isArray(e.sourceSurfaces)?e.sourceSurfaces[0]:void 0,r=Array.isArray(t.sourceSurfaces)?t.sourceSurfaces[0]:void 0;return Bo(n,r)}function Bo(e,t){let n=String(e?.ownerNodePath??"").localeCompare(String(t?.ownerNodePath??""));if(n!==0)return n;let r=Number.isInteger(e?.nodeIndex)?e.nodeIndex:-1,i=Number.isInteger(t?.nodeIndex)?t.nodeIndex:-1;if(r!==i)return r-i;let o=Number.isInteger(e?.meshIndex)?e.meshIndex:-1,s=Number.isInteger(t?.meshIndex)?t.meshIndex:-1;if(o!==s)return o-s;let a=Number.isInteger(e?.primitiveIndex)?e.primitiveIndex:-1,c=Number.isInteger(t?.primitiveIndex)?t.primitiveIndex:-1;return a-c}function gu(e,t={}){let n=Array.isArray(e?.materials)?e.materials:[],r=[];for(let i=0;i<n.length;i+=1){let o=bu(e,i,t);o&&r.push(o)}return r}function pu(e,t){if(!t.length||!e.length)return{};let n=new Map(e.map(i=>[i.sourceMaterialIndex,i])),r=t.map(i=>n.get(i)).filter(Boolean);return r.length>0?{sourceMaterialProfiles:r}:{}}function bu(e,t,n={}){let r=Array.isArray(e?.materials)?e.materials[t]:null;if(!r||typeof r!="object")return null;let i={},o=[],s=r.pbrMetallicRoughness&&typeof r.pbrMetallicRoughness=="object"?r.pbrMetallicRoughness:{},a={},c=Array.isArray(s.baseColorFactor)?s.baseColorFactor:null,d=_o(c);d&&(a.color=d);let u=$t(e,s.baseColorTexture,n,"baseColor.texture",a,"texture",o);Object.keys(a).length>0&&(i.baseColor={...a,brightness:1,saturation:1,contrast:1,hue:0});let l={};$t(e,r.normalTexture,n,"normal.texture",l,"texture",o),Number.isFinite(r.normalTexture?.scale)?l.strength=r.normalTexture.scale:l.texture&&(l.strength=1),Object.keys(l).length>0&&(i.normal=l),i.metallic=Number.isFinite(s.metallicFactor)?s.metallicFactor:1,i.roughness=Number.isFinite(s.roughnessFactor)?s.roughnessFactor:1;let f={};$t(e,s.metallicRoughnessTexture,n,"metallicRoughness.texture",f,"texture",o),Object.keys(f).length>0&&(i.metallicRoughness=f);let g={};$t(e,r.occlusionTexture,n,"occlusion.texture",g,"texture",o),Number.isFinite(r.occlusionTexture?.strength)?g.strength=r.occlusionTexture.strength:g.texture&&(g.strength=1),Object.keys(g).length>0&&(i.occlusion=g);let p={},h=_o(Array.isArray(r.emissiveFactor)?r.emissiveFactor:null),S=h&&(h.r!==0||h.g!==0||h.b!==0);S&&(p.color=h),$t(e,r.emissiveTexture,n,"emission.texture",p,"texture",o),S&&(p.intensity=1),Object.keys(p).length>0&&(i.emission=p);let P={},D=Vo(r.alphaMode);if(D&&(P.mode=D),(D==="mask"||D==="blend")&&(c&&Number.isFinite(c[3])&&c[3]!==1&&(P.opacity=c[3]),Number.isFinite(r.alphaCutoff)?P.cutoff=r.alphaCutoff:D==="mask"&&(P.cutoff=.5),u.texture&&(P.texture=structuredClone(u.texture)),u.hint&&o.push({...u.hint,profilePath:"alpha.texture"})),Object.keys(P).length>0&&(i.alpha=P),Object.keys(i).length===0&&o.length===0)return null;let T=typeof r.name=="string"&&r.name.trim()?r.name.trim():"";return{sourceMaterialIndex:t,...T?{materialName:T}:{},...Object.keys(i).length>0?{profile:i}:{},...o.length>0?{textureHints:o}:{}}}function _o(e){if(!Array.isArray(e)||e.length<3)return null;let[t,n,r]=e;return Number.isFinite(t)&&Number.isFinite(n)&&Number.isFinite(r)?{r:t,g:n,b:r}:null}function Vo(e){return e==="MASK"?"mask":e==="BLEND"?"blend":e==="OPAQUE"?"opaque":null}function $t(e,t,n,r,i,o,s){let a=yu(e,t,n,r);return a.texture&&(i[o]=a.texture),a.hint&&s.push(a.hint),a}function yu(e,t,n,r){let i=V(t)?t:{},o=Number.isInteger(i.index)?i.index:-1;if(o<0)return{};let s=Array.isArray(e?.textures)?e.textures:[],a=Array.isArray(e?.images)?e.images:[],c=s[o],d=hu(c),u=d.imageIndex,l=u>=0?a[u]:null,f=typeof l?.uri=="string"?l.uri.trim():"",g=/^data:/i.test(f),p={profilePath:r,textureIndex:o,...u>=0?{imageIndex:u}:{},...d.previewImageIndex>=0?{previewImageIndex:d.previewImageIndex}:{},...f&&!g?{uri:f}:{},...Number.isInteger(l?.bufferView)?{bufferView:l.bufferView}:{},...typeof l?.mimeType=="string"&&l.mimeType.trim()?{mimeType:l.mimeType.trim()}:{}};if(l?.bufferView!=null)return{hint:{...p,reason:"embedded-texture"}};if(!f)return{hint:{...p,reason:"missing-image-uri"}};if(g)return{hint:{...p,reason:"embedded-texture"}};if(/^https?:\/\//i.test(f)||f.startsWith("/"))return{texture:{url:f}};let h=f;try{h=decodeURIComponent(f)}catch{return{hint:{...p,reason:"unresolved-external-texture"}}}let S=ae.dirname(String(n.sourcePath??"")),P=ae.resolve(S,h),D=n.assetsDir?ae.resolve(n.assetsDir):"",T=n.cwd?ae.resolve(n.cwd):"",$=D?ae.relative(D,P):"../";return D&&T&&$&&!$.startsWith("..")&&!ae.isAbsolute($)?{texture:{url:`/${ae.relative(T,P).split(ae.sep).join("/")}`},hint:{...p,reason:"external-texture"}}:{hint:{...p,reason:"external-texture"}}}function hu(e){let t=V(e)?e:{},n=V(t.extensions)?t.extensions:{},r=Number.isInteger(t.source)?t.source:-1,i=V(n.KHR_texture_basisu)?n.KHR_texture_basisu:{};if(Number.isInteger(i.source))return{imageIndex:i.source,previewImageIndex:r>=0&&r!==i.source?r:-1};let o=V(n.EXT_texture_webp)?n.EXT_texture_webp:{};return Number.isInteger(o.source)?{imageIndex:o.source,previewImageIndex:-1}:{imageIndex:r,previewImageIndex:-1}}function Su(e){let t=new Map,n=new Map;if(!Array.isArray(e))return{byExactSource:t,bySourceMaterialIndex:new Map};for(let i of e){if(!V(i))continue;let o=Array.isArray(i.sourceSurfaces)?i.sourceSurfaces:[],s=typeof i.slotId=="string"?i.slotId.trim():"";if(!s)continue;let a=new Set;for(let c of o){if(!V(c))continue;let d=typeof c.ownerNodePath=="string"?c.ownerNodePath.trim().replace(/^\/+|\/+$/g,""):"",u=Number.isInteger(c.nodeIndex)?c.nodeIndex:-1,l=Number.isInteger(c.meshIndex)?c.meshIndex:-1,f=Number.isInteger(c.primitiveIndex)?c.primitiveIndex:-1;o.length===1&&d&&u>=0&&l>=0&&f>=0&&t.set(Ko({ownerNodePath:d,nodeIndex:u,meshIndex:l,primitiveIndex:f}),s),Number.isInteger(c.sourceMaterialIndex)&&c.sourceMaterialIndex>=0&&a.add(c.sourceMaterialIndex)}if(a.size===1){let[c]=a,d=n.get(c)??[];d.push(s),n.set(c,d)}}let r=new Map;for(let[i,o]of n)o.length===1&&r.set(i,o[0]);return{byExactSource:t,bySourceMaterialIndex:r}}function Ko(e){return[e.ownerNodePath,e.nodeIndex,e.meshIndex,e.primitiveIndex].join("\0")}function xu(e){let t=Number.isInteger(e.primitiveIndex)?`:${e.primitiveIndex}`:"",n=`${e.assetGuid||e.assetId||"asset"}:${e.nodeIndex}:${e.meshIndex}${t}`;return`slot_${es(n)}`}function Pu(e){let t=`${e.assetGuid||e.assetId||"asset"}:material:${e.sourceMaterialIndex}`;return`slot_${es(t)}`}function Iu(e,t){if(t.textureUsage==="material"||t.usage==="material")return{usage:"material",materialTexture:!0,environmentTexture:!1};if(V(t.capabilities)&&t.capabilities.materialTexture===!0)return{usage:"material",materialTexture:!0,environmentTexture:!1};if(t.textureUsage==="environment"||t.usage==="environment")return{usage:"environment",materialTexture:!1,environmentTexture:!0};if(V(t.capabilities)&&t.capabilities.environmentTexture===!0)return{usage:"environment",materialTexture:!1,environmentTexture:!0};let n=ae.extname(e).toLowerCase();return[".env",".hdr",".dds",".ktx",".ktx2"].includes(n)?{usage:"environment",materialTexture:!1,environmentTexture:!0}:[".png",".jpg",".jpeg",".webp"].includes(n)?{usage:"material",materialTexture:!0,environmentTexture:!1}:null}function Ho(e){let t=Array.isArray(e.scenes)?e.scenes:[],n=Number.isInteger(e.scene)?e.scene:0,r=t[n]??t[0];return Array.isArray(r?.nodes)?r.nodes.filter(Number.isInteger):[]}function Wo(e){let t=new Map;for(let n=0;n<e.length;n+=1){let r=Array.isArray(e[n]?.children)?e[n].children:[];for(let i of r)Number.isInteger(i)&&!t.has(i)&&t.set(i,n)}return t}function qo(e,t,n,r){let i=[],o=r,s=new Set;for(;Number.isInteger(o)&&o>=0&&o<e.length;){if(s.has(o))return"";s.add(o),i.push(Eu(e[o],o));let a=t.get(o);if(typeof a!="number"||!Number.isInteger(a))break;o=a}return i.reverse(),i.length>1&&n.has(o)&&i.shift(),i.filter(Boolean).join("/")}function Eu(e,t){return(V(e)&&typeof e.name=="string"?e.name.trim():"")||`node_${t}`}function Au(e,t,n){let r=V(e)&&typeof e.name=="string"?e.name.trim():"",i=Jo(t);return r||i||n.split("/").filter(Boolean).pop()||n}function Jo(e){return V(e)&&typeof e.name=="string"?e.name.trim():""}function Xo(e,t){let n=[],r=t,i=new Set;for(;Number.isInteger(r)&&r>=0;){if(i.has(r))return[];i.add(r),n.push(r);let o=e.get(r);if(!Number.isInteger(o))break;r=o}return n.reverse(),n}function wu(e,t){let n=V(e)?e:{},r=Number.isInteger(n.material)?n.material:-1,i=r>=0?t[r]:null,o=typeof i?.name=="string"&&i.name.trim()?i.name.trim():"";return{index:r,name:o}}function Zo(e,t){let n=V(e)?e:{},r=Number.isInteger(n.indices)?n.indices:-1,i=Qo(n),o=r>=0?t[r]:null,s=i>=0?t[i]:null,a=Number.isFinite(o?.count)?Number(o.count):Number.isFinite(s?.count)?Number(s.count):null;if(a==null)return null;let c=Number.isInteger(n.mode)?n.mode:4;return c===4?Math.floor(a/3):c===5||c===6?Math.max(0,a-2):0}function Yo(e,t){let n=V(e)?e:{},r=Qo(n),i=r>=0?t[r]:null,o=Lo(i?.min),s=Lo(i?.max);return o&&s?{min:o,max:s}:null}function Qo(e){let t=V(e.attributes)?e.attributes:{};return Number.isInteger(t.POSITION)?t.POSITION:-1}function Lo(e){if(!Array.isArray(e)||e.length<3)return null;let t=Number(e[0]),n=Number(e[1]),r=Number(e[2]);return Number.isFinite(t)&&Number.isFinite(n)&&Number.isFinite(r)?[t,n,r]:null}function V(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function es(e){let t=String(e??""),n=2166136261;for(let r=0;r<t.length;r+=1)n^=t.charCodeAt(r),n=Math.imul(n,16777619);return(n>>>0).toString(16).padStart(8,"0")}import Nt from"node:fs/promises";import pe from"node:path";async function ns(e,t={}){try{let n=await Tu(e);if(!n)return[];let r=Array.isArray(n.gltf.images)?n.gltf.images:[],i=t.imageIndexes?new Set(t.imageIndexes.filter(s=>Number.isInteger(s)&&s>=0)):null,o=[];for(let s=0;s<r.length;s+=1){if(i&&!i.has(s))continue;let a=de(r[s]);if(!a)continue;let c=await Du(e,n,a);if(!c)continue;let d=Ot(a.name)??(c.originalFileName?pe.parse(c.originalFileName).name:null)??void 0;o.push({imageIndex:s,bytes:c.bytes,extension:c.extension,mimeType:c.mimeType,...d?{displayName:d}:{},...c.originalFileName?{originalFileName:c.originalFileName}:{}})}return o}catch{return[]}}function rs(e){let t=new Set;for(let n of os(e)){let r=Te(n.imageIndex),i=Te(n.previewImageIndex);r!=null&&t.add(r),i!=null&&t.add(i)}return[...t].sort((n,r)=>n-r)}function is(e){let t=new Map;for(let n of os(e)){let r=Te(n.imageIndex),i=Te(n.previewImageIndex);r==null||i==null||r===i||t.set(`${r}:${i}`,{imageIndex:r,previewImageIndex:i})}return[...t.values()].sort((n,r)=>n.imageIndex-r.imageIndex||n.previewImageIndex-r.previewImageIndex)}function os(e){if(!e)return[];let t=[],n=Array.isArray(e.materialSlots)?e.materialSlots:[];for(let r of n){let i=de(r),o=Array.isArray(i?.sourceMaterialProfiles)?i.sourceMaterialProfiles:[];for(let s of o){let a=de(s),c=Array.isArray(a?.textureHints)?a.textureHints:[];for(let d of c){let u=de(d);u&&t.push(u)}}}return t}function ss(e,t){if(!e||t.length===0)return e;let n=new Map(t.map(s=>[s.imageIndex,s.textureAssetId])),r=structuredClone(e),i=Array.isArray(r.materialSlots)?r.materialSlots:[],o=!1;for(let s of i){let a=de(s),c=Array.isArray(a?.sourceMaterialProfiles)?a.sourceMaterialProfiles:[];for(let d of c){let u=de(d);if(!u)continue;let l=Array.isArray(u.textureHints)?u.textureHints:[];if(l.length===0)continue;let f=[];for(let g of l){let p=de(g),h=Te(p?.imageIndex),S=Ot(p?.profilePath),P=h==null?null:n.get(h)??null;if(!P||!S||!Mu(S)){f.push(g);continue}let D=de(u.profile)??{};Cu(D,S,{textureAssetId:P}),u.profile=D,o=!0}f.length>0?u.textureHints=f:delete u.textureHints}}return o?r:e}async function Tu(e){let t=pe.extname(e).toLowerCase();if(t===".gltf"){let c=JSON.parse(await Nt.readFile(e,"utf8")),d=await Promise.all((Array.isArray(c.buffers)?c.buffers:[]).map(u=>ts(e,de(u))));return{gltf:c,buffers:d}}if(t!==".glb")return null;let n=await Nt.readFile(e);if(n.length<20||n.toString("utf8",0,4)!=="glTF"||n.readUInt32LE(4)!==2||n.readUInt32LE(8)>n.length)return null;let r=null,i=[],o=12;for(;o+8<=n.length;){let c=n.readUInt32LE(o),d=n.readUInt32LE(o+4);if(o+=8,o+c>n.length)return null;let u=n.subarray(o,o+c);d===1313821514?r=JSON.parse(u.toString("utf8").replace(/\0+$/g,"")):d===5130562&&i.push(Buffer.from(u)),o+=c}if(!r)return null;let s=Array.isArray(r.buffers)?r.buffers:[],a=await Promise.all(s.map(async(c,d)=>{let u=de(c);return Ot(u?.uri)?ts(e,u):i[d]??(d===0?i[0]??null:null)}));return a.length===0&&i.length>0&&a.push(i[0]),{gltf:r,buffers:a}}async function ts(e,t){let n=Ot(t?.uri);if(!n)return null;let r=cs(n);if(r)return r.bytes;if(wr(n))return null;let i=ds(n);return i?as(e,i):null}async function Du(e,t,n){let r=Ot(n.uri);if(r){let g=cs(r);if(g){let D=Ar(g.bytes);return D?{bytes:g.bytes,...D}:null}if(wr(r))return null;let p=ds(r);if(!p)return null;let h=await as(e,p);if(!h)return null;let S=pe.basename(p),P=Ar(h);return P?{bytes:h,...P,originalFileName:S}:null}let i=Te(n.bufferView);if(i==null)return null;let o=Array.isArray(t.gltf.bufferViews)?t.gltf.bufferViews:[],s=de(o[i]),a=Te(s?.buffer)??0,c=t.buffers[a],d=Te(s?.byteOffset)??0,u=Te(s?.byteLength);if(!c||u==null||d+u>c.length)return null;let l=Buffer.from(c.subarray(d,d+u)),f=Ar(l);return f?{bytes:l,...f}:null}async function as(e,t){if(pe.isAbsolute(t)||pe.win32.isAbsolute(t)||t.includes("\0"))return null;try{let n=await Nt.realpath(pe.dirname(e)),r=pe.resolve(n,t),i=await Nt.realpath(r);return ku(n,i)?await Nt.readFile(i):null}catch{return null}}function ds(e){if(wr(e))return null;try{return decodeURIComponent(e)}catch{return null}}function ku(e,t){let n=pe.relative(e,t);return n===""||!n.startsWith(`..${pe.sep}`)&&n!==".."&&!pe.isAbsolute(n)}function cs(e){let t=/^data:([^;,]+)?(?:;[^,]*)?,(.*)$/is.exec(e);if(!t)return null;let n=e.slice(0,e.indexOf(","));try{return{bytes:n.toLowerCase().includes(";base64")?Buffer.from(t[2]??"","base64"):Buffer.from(decodeURIComponent(t[2]??""),"utf8")}}catch{return null}}function Ar(e){return e.length>=8&&e.subarray(0,8).equals(Buffer.from([137,80,78,71,13,10,26,10]))?{extension:".png",mimeType:"image/png"}:e.length>=3&&e[0]===255&&e[1]===216&&e[2]===255?{extension:".jpg",mimeType:"image/jpeg"}:e.length>=12&&e.toString("ascii",0,4)==="RIFF"&&e.toString("ascii",8,12)==="WEBP"?{extension:".webp",mimeType:"image/webp"}:e.length>=12&&e.subarray(0,12).equals(Buffer.from([171,75,84,88,32,50,48,187,13,10,26,10]))?{extension:".ktx2",mimeType:"image/ktx2"}:null}function Mu(e){return["baseColor.texture","normal.texture","metallicRoughness.texture","occlusion.texture","emission.texture","emission.maskTexture","alpha.texture"].includes(e)}function Cu(e,t,n){let r=t.split("."),i=e;for(let o=0;o<r.length-1;o+=1){let s=r[o],a=de(i[s])??{};i[s]=a,i=a}i[r[r.length-1]]=n}function wr(e){return/^[a-z][a-z0-9+.-]*:/i.test(e)||e.startsWith("/")||pe.win32.isAbsolute(e)}function de(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function Ot(e){return typeof e=="string"&&e.trim()?e.trim():null}function Te(e){return Number.isInteger(e)&&e>=0?e:null}function ls(e){let t=typeof e=="string"&&e.trim()?e.trim():void 0;if(!t)return;if(t.includes("\0"))throw new Error("external_asset_path_must_be_portable");let n=t.replace(/\\/g,"/");if(n.startsWith("/")||/^[a-z]:\//i.test(n)||/^[a-z][a-z0-9+.-]*:/i.test(n))throw new Error("external_asset_path_must_be_portable");let r=[];for(let i of n.split("/"))if(!(!i||i===".")){if(i==="..")throw new Error("external_asset_path_must_be_portable");r.push(i)}if(r.length===0)throw new Error("external_asset_path_must_be_portable");return r.join("/")}function Dr(e){if(typeof e=="number"&&Number.isFinite(e)&&e>0)return e;if(!e||typeof e!="object")return;let t=e,n=Tr(t.x),r=Tr(t.y),i=Tr(t.z);if(!(n==null||r==null||i==null||n<=0||r<=0||i<=0))return{x:n,y:r,z:i}}function Tr(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function kr(e){return e==="shared"||e==="instance"?e:void 0}function Mr(e){return Number.isInteger(e)&&e>=0?e:void 0}var C=class extends Error{constructor(t,n={}){super(t),this.name="PlayableEditorAssetRegistryError",this.details=n}};function $u(e){let t={};for(let n=0;n<e.length;n+=1){let r=e[n];if(r==="--unregister"){t.unregister=!0;continue}if(r==="--payload"){t.payload=e[n+1],n+=1;continue}if(r==="--asset-id"){t.assetId=e[n+1],n+=1;continue}if(r==="--guid"){t.guid=e[n+1],n+=1;continue}if(r==="--delete-file"){t.deleteFile=!0;continue}if(r==="--keep-file"){t.deleteFile=!1;continue}(r==="--help"||r==="-h")&&(t.help=!0)}return t}async function bs(e,t=process.argv.slice(2)){let n=$u(t),r=await Fu(e),i=Y(r.errorCodes),o=(s,a={})=>{let c={ok:!1,error:s,...a};process.stderr.write(`${JSON.stringify(c,null,2)}
|
|
8
|
+
`}import In from"node:crypto";import{constants as Ru}from"node:fs";import R from"node:fs/promises";import w from"node:path";import Ir from"node:fs/promises";import de from"node:path";var Er=5;async function xn(e){let t={...e.existingMetadata??{},...e.payloadMetadata??{}},n=await Yl(e);if(n?(t.assetAnalysis=n,t.assetAnalysisStatus="complete"):(delete t.assetAnalysis,t.assetAnalysisStatus="unavailable"),e.kind==="texture"||e.kind==="image"){let i=Iu(e.sourcePath,t);return i&&(t.textureUsage=i.usage,t.capabilities={...V(t.capabilities)?t.capabilities:{},materialTexture:i.materialTexture,environmentTexture:i.environmentTexture}),Object.keys(t).length>0?t:null}if(e.kind!=="model")return Object.keys(t).length>0?t:null;t.assetMetadataVersion=Er;let r=await Ql(e.sourcePath,{assetGuid:e.guid,assetId:e.assetId,cwd:e.cwd,assetsDir:e.assetsDir,existingMaterialSlots:t.materialSlots});return r.length===0?delete t.materialSlots:t.materialSlots=r,Object.keys(t).length>0?t:null}async function Yl(e){return e.kind==="model"?eu(e.sourcePath):e.kind==="texture"||e.kind==="image"?tu(e.sourcePath):null}async function Ql(e,t={}){try{let n=await zo(e);return fu(n,{...t,sourcePath:e})}catch{return[]}}async function zo(e){let t=de.extname(e).toLowerCase();if(t===".gltf")return JSON.parse(await Ir.readFile(e,"utf8"));if(t!==".glb")return null;let n=await Ir.readFile(e);if(n.length<20||n.toString("utf8",0,4)!=="glTF"||n.readUInt32LE(4)!==2||n.readUInt32LE(8)>n.length)return null;let o=12;for(;o+8<=n.length;){let s=n.readUInt32LE(o),a=n.readUInt32LE(o+4);if(o+=8,o+s>n.length)return null;if(a===1313821514){let c=n.toString("utf8",o,o+s).replace(/\0+$/g,"");return JSON.parse(c)}o+=s}return null}async function eu(e){try{let t=await zo(e);if(!t||typeof t!="object")return null;let n=Array.isArray(t.scenes)?t.scenes:[],r=Array.isArray(t.nodes)?t.nodes:[],i=Array.isArray(t.meshes)?t.meshes:[],o=Array.isArray(t.materials)?t.materials:[],s=Array.isArray(t.textures)?t.textures:[],a=Array.isArray(t.images)?t.images:[],c=Array.isArray(t.animations)?t.animations:[],d=Array.isArray(t.skins)?t.skins:[],u=Array.isArray(t.accessors)?t.accessors:[],l=Ho(t),f=Wo(r),g=new Set(l),p=i.reduce((T,$)=>T+(Array.isArray($?.primitives)?$.primitives.length:0),0),h=i.reduce((T,$)=>T+(Array.isArray($?.primitives)?$.primitives.reduce((_,q)=>_+(Array.isArray(q?.targets)?q.targets.length:0),0):0),0),S=su({nodeCount:r.length,meshCount:i.length,primitiveCount:p,materialCount:o.length,textureCount:s.length,imageCount:a.length}),P=au({nodeCount:r.length,meshCount:i.length,primitiveCount:p,materialCount:o.length,textureCount:s.length,imageCount:a.length,animationCount:c.length,skinCount:d.length,morphTargetCount:h,complexity:S});return{kind:"gltf",format:de.extname(e).toLowerCase()===".gltf"?"gltf":"glb",summary:`${r.length} nodes, ${i.length} meshes, ${p} primitives, ${o.length} materials`,complexity:S,sceneCount:n.length,nodeCount:r.length,meshCount:i.length,primitiveCount:p,materialCount:o.length,textureCount:s.length,imageCount:a.length,animationCount:c.length,skinCount:d.length,morphTargetCount:h,nodes:nu(r,i,o,u,f,g),meshes:ru(i,o,u),materials:iu(t),diagnostics:P}}catch{return null}}async function tu(e){try{let t=await Ir.readFile(e),n=de.extname(e).toLowerCase(),r=n===".png"?du(t):n===".jpg"||n===".jpeg"?cu(t):n===".webp"?lu(t):null;if(!r)return null;let i=uu(r);return{kind:"image",format:r.format,summary:`${r.width}x${r.height} ${r.mime}`,complexity:r.estimatedPixels>=4096*4096?"high":r.estimatedPixels>=2048*2048?"medium":"low",width:r.width,height:r.height,mime:r.mime,bitDepth:r.bitDepth,hasAlpha:r.hasAlpha,estimatedPixels:r.estimatedPixels,diagnostics:i}}catch{return null}}function nu(e,t,n,r,i,o){return e.slice(0,100).map((s,a)=>{let c=Number.isInteger(s?.mesh)?s.mesh:-1,d=c>=0&&c<t.length?t[c]:null,u=Array.isArray(s?.children)?s.children.filter(g=>Number.isInteger(g)):[],l=qo(e,i,o,a),f={nodeIndex:a,nodeIndexPath:Xo(i,a),...typeof s?.name=="string"&&s.name.trim()?{name:s.name.trim()}:{},...l?{ownerNodePath:l}:{},...u.length>0?{children:u}:{}};if(d){let g=Uo(d,n,r);Object.assign(f,{meshIndex:c,...typeof d?.name=="string"&&d.name.trim()?{meshName:d.name.trim()}:{},primitiveCount:g.length,...g.length>0?{primitives:g}:{}})}return f})}function ru(e,t,n){return e.slice(0,50).map((r,i)=>{let o=Array.isArray(r?.primitives)?r.primitives:[],s=[...new Set(o.map(c=>Number.isInteger(c?.material)?c.material:-1).filter(c=>c>=0))],a=Uo(r,t,n);return{meshIndex:i,...typeof r?.name=="string"&&r.name.trim()?{name:r.name.trim()}:{},primitiveCount:o.length,...a.length>0?{primitives:a}:{},...s.length>0?{materialIndices:s}:{},...s.length>0?{materialNames:s.map(c=>{let d=t[c];return typeof d?.name=="string"?d.name.trim():""}).filter(Boolean)}:{}}})}function Uo(e,t,n){let r=V(e)?e:{};return(Array.isArray(r.primitives)?r.primitives:[]).map((o,s)=>{let a=Number.isInteger(o?.material)?o.material:-1,c=a>=0?t[a]:null,d=typeof c?.name=="string"&&c.name.trim()?c.name.trim():"",u=Zo(o,n),l=Yo(o,n);return{primitiveIndex:s,...Number.isInteger(o?.mode)?{mode:o.mode}:{},...a>=0?{sourceMaterialIndex:a}:{},...d?{materialName:d}:{},...Number.isFinite(u)?{triangleCount:u}:{},...l?{boundingBox:l}:{}}})}function iu(e){return(Array.isArray(e?.materials)?e.materials:[]).slice(0,50).map((n,r)=>{let i=n?.pbrMetallicRoughness&&typeof n.pbrMetallicRoughness=="object"?n.pbrMetallicRoughness:{},o=ou(n,i);return{sourceMaterialIndex:r,...typeof n?.name=="string"&&n.name.trim()?{materialName:n.name.trim()}:{},...Array.isArray(i.baseColorFactor)?{baseColorFactor:i.baseColorFactor.slice(0,4)}:{},metallicFactor:Number.isFinite(i.metallicFactor)?i.metallicFactor:1,roughnessFactor:Number.isFinite(i.roughnessFactor)?i.roughnessFactor:1,alphaMode:Vo(n?.alphaMode)??"opaque",...Number.isFinite(n?.alphaCutoff)?{alphaCutoff:n.alphaCutoff}:{},...o.length>0?{textureSlots:o}:{}}})}function ou(e,t){let n=[];return Rt(n,"baseColor",t?.baseColorTexture),Rt(n,"metallicRoughness",t?.metallicRoughnessTexture),Rt(n,"normal",e?.normalTexture),Rt(n,"occlusion",e?.occlusionTexture),Rt(n,"emissive",e?.emissiveTexture),n}function Rt(e,t,n){!V(n)||!Number.isInteger(n.index)||e.push({slot:t,textureIndex:n.index,...Number.isFinite(n.texCoord)?{texCoord:n.texCoord}:{}})}function su(e){return e.nodeCount>=300||e.meshCount>=250||e.primitiveCount>=300||e.materialCount>=200||e.textureCount>=80||e.imageCount>=80?"high":e.nodeCount>=100||e.meshCount>=80||e.primitiveCount>=100||e.materialCount>=50||e.textureCount>=24||e.imageCount>=24?"medium":"low"}function au(e){let t=[];return e.complexity==="high"&&t.push({severity:"warning",source:"asset",code:"asset.analysis.highComplexity",message:"GLTF asset is structurally complex; agent should place and inspect it before duplicating or using dense shadows.",details:{nodeCount:e.nodeCount,meshCount:e.meshCount,primitiveCount:e.primitiveCount,materialCount:e.materialCount,textureCount:e.textureCount,imageCount:e.imageCount}}),(e.animationCount>0||e.skinCount>0||e.morphTargetCount>0)&&t.push({severity:"info",source:"asset",code:"asset.analysis.riggedOrAnimated",message:"GLTF asset contains animation, skin, or morph target data.",details:{animationCount:e.animationCount,skinCount:e.skinCount,morphTargetCount:e.morphTargetCount}}),t}function du(e){if(e.length<33||e[0]!==137||e.toString("ascii",1,4)!=="PNG"||e[4]!==13||e[5]!==10||e[6]!==26||e[7]!==10||e.toString("ascii",12,16)!=="IHDR")return null;let n=e.readUInt32BE(16),r=e.readUInt32BE(20),i=e[24],o=e[25],s=!1,a=33;for(;a+12<=e.length;){let c=e.readUInt32BE(a),d=a+12+c;if(d>e.length)break;let u=e.toString("ascii",a+4,a+8);if(u==="tRNS"){s=!0;break}if(u==="IDAT"||u==="IEND")break;a=d}return{format:"png",mime:"image/png",width:n,height:r,bitDepth:i,hasAlpha:o===4||o===6||s,estimatedPixels:n*r}}function cu(e){if(e.length<4||e[0]!==255||e[1]!==216)return null;let t=2;for(;t+9<e.length;){if(e[t]!==255){t+=1;continue}let n=e[t+1],r=e.readUInt16BE(t+2);if(r<2)return null;if(n>=192&&n<=207&&![196,200,204].includes(n)&&t+8<e.length){let o=e[t+4],s=e.readUInt16BE(t+5),a=e.readUInt16BE(t+7);return{format:"jpeg",mime:"image/jpeg",width:a,height:s,bitDepth:o,hasAlpha:!1,estimatedPixels:a*s}}t+=2+r}return null}function lu(e){if(e.length<30||e.toString("ascii",0,4)!=="RIFF"||e.toString("ascii",8,12)!=="WEBP")return null;let t=e.toString("ascii",12,16);if(t==="VP8X"&&e.length>=30){let n=e[20],r=Fo(e,24)+1,i=Fo(e,27)+1;return{format:"webp",mime:"image/webp",width:r,height:i,hasAlpha:(n&16)!==0,estimatedPixels:r*i}}if(t==="VP8 "&&e.length>=30){let n=e.readUInt16LE(26)&16383,r=e.readUInt16LE(28)&16383;return{format:"webp",mime:"image/webp",width:n,height:r,hasAlpha:!1,estimatedPixels:n*r}}if(t==="VP8L"&&e.length>=25&&e[20]===47){let n=e.readUInt32LE(21),r=(n&16383)+1,i=(n>>14&16383)+1;return{format:"webp",mime:"image/webp",width:r,height:i,hasAlpha:!0,estimatedPixels:r*i}}return null}function Fo(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16}function uu(e){let t=[];return e.estimatedPixels>=4096*4096&&t.push({severity:"warning",source:"asset",code:"asset.analysis.largeImage",message:"Image asset is large; agent should inspect texture usage before assigning it broadly.",details:{width:e.width,height:e.height,estimatedPixels:e.estimatedPixels}}),t}function fu(e,t={}){if(!e||typeof e!="object")return[];let n=Array.isArray(e.nodes)?e.nodes:[],r=Array.isArray(e.meshes)?e.meshes:[],i=Array.isArray(e.materials)?e.materials:[],o=gu(e,t),s=Ho(e),a=Wo(n),c=new Set(s),d=Array.isArray(e.accessors)?e.accessors:[],u=Su(t.existingMaterialSlots),l=[],f=new Map;for(let g=0;g<n.length;g+=1){let p=n[g],h=Number.isInteger(p?.mesh)?p.mesh:-1;if(h<0||h>=r.length)continue;let S=qo(n,a,c,g);if(!S)continue;let P=r[h],D=Array.isArray(P?.primitives)?P.primitives:[],T=Au(p,P,S),$=Jo(P),_=Xo(a,g);for(let q=0;q<D.length;q+=1){let ve=D[q],m=wu(ve,i),L=Ko({ownerNodePath:S,nodeIndex:g,meshIndex:h,primitiveIndex:q}),b=Zo(ve,d),j=Yo(ve,d),W=D.length>1?`${T} / Primitive ${q}`:T,J={ownerNodePath:S,nodeIndex:g,nodeIndexPath:_,meshIndex:h,primitiveIndex:q,...$?{sourceMeshName:$}:{},...m.index>=0?{sourceMaterialIndex:m.index}:{},...Number.isFinite(b)?{triangleCount:b}:{},...j?{boundingBox:j}:{}};if(m.index>=0){let z=f.get(m.index)??{label:W,materialName:m.name,sourceSurfaces:[]};z.sourceSurfaces.push(J),f.set(m.index,z);continue}l.push({slotId:u.byExactSource.get(L)??xu({assetGuid:t.assetGuid,assetId:t.assetId,nodeIndex:g,meshIndex:h,primitiveIndex:D.length>1?q:void 0}),label:W,sourceSurfaces:[J]})}}for(let[g,p]of f){let h=p.sourceSurfaces.sort(Bo);l.push({slotId:u.bySourceMaterialIndex.get(g)??Pu({assetGuid:t.assetGuid,assetId:t.assetId,sourceMaterialIndex:g}),label:p.label,sourceSurfaces:h,...p.materialName?{materialName:p.materialName,materialNames:[p.materialName]}:{},...pu(o,[g])})}return l.sort(mu)}function mu(e,t){let n=Array.isArray(e.sourceSurfaces)?e.sourceSurfaces[0]:void 0,r=Array.isArray(t.sourceSurfaces)?t.sourceSurfaces[0]:void 0;return Bo(n,r)}function Bo(e,t){let n=String(e?.ownerNodePath??"").localeCompare(String(t?.ownerNodePath??""));if(n!==0)return n;let r=Number.isInteger(e?.nodeIndex)?e.nodeIndex:-1,i=Number.isInteger(t?.nodeIndex)?t.nodeIndex:-1;if(r!==i)return r-i;let o=Number.isInteger(e?.meshIndex)?e.meshIndex:-1,s=Number.isInteger(t?.meshIndex)?t.meshIndex:-1;if(o!==s)return o-s;let a=Number.isInteger(e?.primitiveIndex)?e.primitiveIndex:-1,c=Number.isInteger(t?.primitiveIndex)?t.primitiveIndex:-1;return a-c}function gu(e,t={}){let n=Array.isArray(e?.materials)?e.materials:[],r=[];for(let i=0;i<n.length;i+=1){let o=bu(e,i,t);o&&r.push(o)}return r}function pu(e,t){if(!t.length||!e.length)return{};let n=new Map(e.map(i=>[i.sourceMaterialIndex,i])),r=t.map(i=>n.get(i)).filter(Boolean);return r.length>0?{sourceMaterialProfiles:r}:{}}function bu(e,t,n={}){let r=Array.isArray(e?.materials)?e.materials[t]:null;if(!r||typeof r!="object")return null;let i={},o=[],s=r.pbrMetallicRoughness&&typeof r.pbrMetallicRoughness=="object"?r.pbrMetallicRoughness:{},a={},c=Array.isArray(s.baseColorFactor)?s.baseColorFactor:null,d=_o(c);d&&(a.color=d);let u=$t(e,s.baseColorTexture,n,"baseColor.texture",a,"texture",o);Object.keys(a).length>0&&(i.baseColor={...a,brightness:1,saturation:1,contrast:1,hue:0});let l={};$t(e,r.normalTexture,n,"normal.texture",l,"texture",o),Number.isFinite(r.normalTexture?.scale)?l.strength=r.normalTexture.scale:l.texture&&(l.strength=1),Object.keys(l).length>0&&(i.normal=l),i.metallic=Number.isFinite(s.metallicFactor)?s.metallicFactor:1,i.roughness=Number.isFinite(s.roughnessFactor)?s.roughnessFactor:1;let f={};$t(e,s.metallicRoughnessTexture,n,"metallicRoughness.texture",f,"texture",o),Object.keys(f).length>0&&(i.metallicRoughness=f);let g={};$t(e,r.occlusionTexture,n,"occlusion.texture",g,"texture",o),Number.isFinite(r.occlusionTexture?.strength)?g.strength=r.occlusionTexture.strength:g.texture&&(g.strength=1),Object.keys(g).length>0&&(i.occlusion=g);let p={},h=_o(Array.isArray(r.emissiveFactor)?r.emissiveFactor:null),S=h&&(h.r!==0||h.g!==0||h.b!==0);S&&(p.color=h),$t(e,r.emissiveTexture,n,"emission.texture",p,"texture",o),S&&(p.intensity=1),Object.keys(p).length>0&&(i.emission=p);let P={},D=Vo(r.alphaMode);if(D&&(P.mode=D),(D==="mask"||D==="blend")&&(c&&Number.isFinite(c[3])&&c[3]!==1&&(P.opacity=c[3]),Number.isFinite(r.alphaCutoff)?P.cutoff=r.alphaCutoff:D==="mask"&&(P.cutoff=.5),u.texture&&(P.texture=structuredClone(u.texture)),u.hint&&o.push({...u.hint,profilePath:"alpha.texture"})),Object.keys(P).length>0&&(i.alpha=P),Object.keys(i).length===0&&o.length===0)return null;let T=typeof r.name=="string"&&r.name.trim()?r.name.trim():"";return{sourceMaterialIndex:t,...T?{materialName:T}:{},...Object.keys(i).length>0?{profile:i}:{},...o.length>0?{textureHints:o}:{}}}function _o(e){if(!Array.isArray(e)||e.length<3)return null;let[t,n,r]=e;return Number.isFinite(t)&&Number.isFinite(n)&&Number.isFinite(r)?{r:t,g:n,b:r}:null}function Vo(e){return e==="MASK"?"mask":e==="BLEND"?"blend":e==="OPAQUE"?"opaque":null}function $t(e,t,n,r,i,o,s){let a=yu(e,t,n,r);return a.texture&&(i[o]=a.texture),a.hint&&s.push(a.hint),a}function yu(e,t,n,r){let i=V(t)?t:{},o=Number.isInteger(i.index)?i.index:-1;if(o<0)return{};let s=Array.isArray(e?.textures)?e.textures:[],a=Array.isArray(e?.images)?e.images:[],c=s[o],d=hu(c),u=d.imageIndex,l=u>=0?a[u]:null,f=typeof l?.uri=="string"?l.uri.trim():"",g=/^data:/i.test(f),p={profilePath:r,textureIndex:o,...u>=0?{imageIndex:u}:{},...d.previewImageIndex>=0?{previewImageIndex:d.previewImageIndex}:{},...f&&!g?{uri:f}:{},...Number.isInteger(l?.bufferView)?{bufferView:l.bufferView}:{},...typeof l?.mimeType=="string"&&l.mimeType.trim()?{mimeType:l.mimeType.trim()}:{}};if(l?.bufferView!=null)return{hint:{...p,reason:"embedded-texture"}};if(!f)return{hint:{...p,reason:"missing-image-uri"}};if(g)return{hint:{...p,reason:"embedded-texture"}};if(/^https?:\/\//i.test(f)||f.startsWith("/"))return{texture:{url:f}};let h=f;try{h=decodeURIComponent(f)}catch{return{hint:{...p,reason:"unresolved-external-texture"}}}let S=de.dirname(String(n.sourcePath??"")),P=de.resolve(S,h),D=n.assetsDir?de.resolve(n.assetsDir):"",T=n.cwd?de.resolve(n.cwd):"",$=D?de.relative(D,P):"../";return D&&T&&$&&!$.startsWith("..")&&!de.isAbsolute($)?{texture:{url:`/${de.relative(T,P).split(de.sep).join("/")}`},hint:{...p,reason:"external-texture"}}:{hint:{...p,reason:"external-texture"}}}function hu(e){let t=V(e)?e:{},n=V(t.extensions)?t.extensions:{},r=Number.isInteger(t.source)?t.source:-1,i=V(n.KHR_texture_basisu)?n.KHR_texture_basisu:{};if(Number.isInteger(i.source))return{imageIndex:i.source,previewImageIndex:r>=0&&r!==i.source?r:-1};let o=V(n.EXT_texture_webp)?n.EXT_texture_webp:{};return Number.isInteger(o.source)?{imageIndex:o.source,previewImageIndex:-1}:{imageIndex:r,previewImageIndex:-1}}function Su(e){let t=new Map,n=new Map;if(!Array.isArray(e))return{byExactSource:t,bySourceMaterialIndex:new Map};for(let i of e){if(!V(i))continue;let o=Array.isArray(i.sourceSurfaces)?i.sourceSurfaces:[],s=typeof i.slotId=="string"?i.slotId.trim():"";if(!s)continue;let a=new Set;for(let c of o){if(!V(c))continue;let d=typeof c.ownerNodePath=="string"?c.ownerNodePath.trim().replace(/^\/+|\/+$/g,""):"",u=Number.isInteger(c.nodeIndex)?c.nodeIndex:-1,l=Number.isInteger(c.meshIndex)?c.meshIndex:-1,f=Number.isInteger(c.primitiveIndex)?c.primitiveIndex:-1;o.length===1&&d&&u>=0&&l>=0&&f>=0&&t.set(Ko({ownerNodePath:d,nodeIndex:u,meshIndex:l,primitiveIndex:f}),s),Number.isInteger(c.sourceMaterialIndex)&&c.sourceMaterialIndex>=0&&a.add(c.sourceMaterialIndex)}if(a.size===1){let[c]=a,d=n.get(c)??[];d.push(s),n.set(c,d)}}let r=new Map;for(let[i,o]of n)o.length===1&&r.set(i,o[0]);return{byExactSource:t,bySourceMaterialIndex:r}}function Ko(e){return[e.ownerNodePath,e.nodeIndex,e.meshIndex,e.primitiveIndex].join("\0")}function xu(e){let t=Number.isInteger(e.primitiveIndex)?`:${e.primitiveIndex}`:"",n=`${e.assetGuid||e.assetId||"asset"}:${e.nodeIndex}:${e.meshIndex}${t}`;return`slot_${es(n)}`}function Pu(e){let t=`${e.assetGuid||e.assetId||"asset"}:material:${e.sourceMaterialIndex}`;return`slot_${es(t)}`}function Iu(e,t){if(t.textureUsage==="material"||t.usage==="material")return{usage:"material",materialTexture:!0,environmentTexture:!1};if(V(t.capabilities)&&t.capabilities.materialTexture===!0)return{usage:"material",materialTexture:!0,environmentTexture:!1};if(t.textureUsage==="environment"||t.usage==="environment")return{usage:"environment",materialTexture:!1,environmentTexture:!0};if(V(t.capabilities)&&t.capabilities.environmentTexture===!0)return{usage:"environment",materialTexture:!1,environmentTexture:!0};let n=de.extname(e).toLowerCase();return[".env",".hdr",".dds",".ktx",".ktx2"].includes(n)?{usage:"environment",materialTexture:!1,environmentTexture:!0}:[".png",".jpg",".jpeg",".webp"].includes(n)?{usage:"material",materialTexture:!0,environmentTexture:!1}:null}function Ho(e){let t=Array.isArray(e.scenes)?e.scenes:[],n=Number.isInteger(e.scene)?e.scene:0,r=t[n]??t[0];return Array.isArray(r?.nodes)?r.nodes.filter(Number.isInteger):[]}function Wo(e){let t=new Map;for(let n=0;n<e.length;n+=1){let r=Array.isArray(e[n]?.children)?e[n].children:[];for(let i of r)Number.isInteger(i)&&!t.has(i)&&t.set(i,n)}return t}function qo(e,t,n,r){let i=[],o=r,s=new Set;for(;Number.isInteger(o)&&o>=0&&o<e.length;){if(s.has(o))return"";s.add(o),i.push(Eu(e[o],o));let a=t.get(o);if(typeof a!="number"||!Number.isInteger(a))break;o=a}return i.reverse(),i.length>1&&n.has(o)&&i.shift(),i.filter(Boolean).join("/")}function Eu(e,t){return(V(e)&&typeof e.name=="string"?e.name.trim():"")||`node_${t}`}function Au(e,t,n){let r=V(e)&&typeof e.name=="string"?e.name.trim():"",i=Jo(t);return r||i||n.split("/").filter(Boolean).pop()||n}function Jo(e){return V(e)&&typeof e.name=="string"?e.name.trim():""}function Xo(e,t){let n=[],r=t,i=new Set;for(;Number.isInteger(r)&&r>=0;){if(i.has(r))return[];i.add(r),n.push(r);let o=e.get(r);if(!Number.isInteger(o))break;r=o}return n.reverse(),n}function wu(e,t){let n=V(e)?e:{},r=Number.isInteger(n.material)?n.material:-1,i=r>=0?t[r]:null,o=typeof i?.name=="string"&&i.name.trim()?i.name.trim():"";return{index:r,name:o}}function Zo(e,t){let n=V(e)?e:{},r=Number.isInteger(n.indices)?n.indices:-1,i=Qo(n),o=r>=0?t[r]:null,s=i>=0?t[i]:null,a=Number.isFinite(o?.count)?Number(o.count):Number.isFinite(s?.count)?Number(s.count):null;if(a==null)return null;let c=Number.isInteger(n.mode)?n.mode:4;return c===4?Math.floor(a/3):c===5||c===6?Math.max(0,a-2):0}function Yo(e,t){let n=V(e)?e:{},r=Qo(n),i=r>=0?t[r]:null,o=Lo(i?.min),s=Lo(i?.max);return o&&s?{min:o,max:s}:null}function Qo(e){let t=V(e.attributes)?e.attributes:{};return Number.isInteger(t.POSITION)?t.POSITION:-1}function Lo(e){if(!Array.isArray(e)||e.length<3)return null;let t=Number(e[0]),n=Number(e[1]),r=Number(e[2]);return Number.isFinite(t)&&Number.isFinite(n)&&Number.isFinite(r)?[t,n,r]:null}function V(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function es(e){let t=String(e??""),n=2166136261;for(let r=0;r<t.length;r+=1)n^=t.charCodeAt(r),n=Math.imul(n,16777619);return(n>>>0).toString(16).padStart(8,"0")}import Nt from"node:fs/promises";import pe from"node:path";async function ns(e,t={}){try{let n=await Tu(e);if(!n)return[];let r=Array.isArray(n.gltf.images)?n.gltf.images:[],i=t.imageIndexes?new Set(t.imageIndexes.filter(s=>Number.isInteger(s)&&s>=0)):null,o=[];for(let s=0;s<r.length;s+=1){if(i&&!i.has(s))continue;let a=ce(r[s]);if(!a)continue;let c=await Du(e,n,a);if(!c)continue;let d=Ot(a.name)??(c.originalFileName?pe.parse(c.originalFileName).name:null)??void 0;o.push({imageIndex:s,bytes:c.bytes,extension:c.extension,mimeType:c.mimeType,...d?{displayName:d}:{},...c.originalFileName?{originalFileName:c.originalFileName}:{}})}return o}catch{return[]}}function rs(e){let t=new Set;for(let n of os(e)){let r=Te(n.imageIndex),i=Te(n.previewImageIndex);r!=null&&t.add(r),i!=null&&t.add(i)}return[...t].sort((n,r)=>n-r)}function is(e){let t=new Map;for(let n of os(e)){let r=Te(n.imageIndex),i=Te(n.previewImageIndex);r==null||i==null||r===i||t.set(`${r}:${i}`,{imageIndex:r,previewImageIndex:i})}return[...t.values()].sort((n,r)=>n.imageIndex-r.imageIndex||n.previewImageIndex-r.previewImageIndex)}function os(e){if(!e)return[];let t=[],n=Array.isArray(e.materialSlots)?e.materialSlots:[];for(let r of n){let i=ce(r),o=Array.isArray(i?.sourceMaterialProfiles)?i.sourceMaterialProfiles:[];for(let s of o){let a=ce(s),c=Array.isArray(a?.textureHints)?a.textureHints:[];for(let d of c){let u=ce(d);u&&t.push(u)}}}return t}function ss(e,t){if(!e||t.length===0)return e;let n=new Map(t.map(s=>[s.imageIndex,s.textureAssetId])),r=structuredClone(e),i=Array.isArray(r.materialSlots)?r.materialSlots:[],o=!1;for(let s of i){let a=ce(s),c=Array.isArray(a?.sourceMaterialProfiles)?a.sourceMaterialProfiles:[];for(let d of c){let u=ce(d);if(!u)continue;let l=Array.isArray(u.textureHints)?u.textureHints:[];if(l.length===0)continue;let f=[];for(let g of l){let p=ce(g),h=Te(p?.imageIndex),S=Ot(p?.profilePath),P=h==null?null:n.get(h)??null;if(!P||!S||!Mu(S)){f.push(g);continue}let D=ce(u.profile)??{};Cu(D,S,{textureAssetId:P}),u.profile=D,o=!0}f.length>0?u.textureHints=f:delete u.textureHints}}return o?r:e}async function Tu(e){let t=pe.extname(e).toLowerCase();if(t===".gltf"){let c=JSON.parse(await Nt.readFile(e,"utf8")),d=await Promise.all((Array.isArray(c.buffers)?c.buffers:[]).map(u=>ts(e,ce(u))));return{gltf:c,buffers:d}}if(t!==".glb")return null;let n=await Nt.readFile(e);if(n.length<20||n.toString("utf8",0,4)!=="glTF"||n.readUInt32LE(4)!==2||n.readUInt32LE(8)>n.length)return null;let r=null,i=[],o=12;for(;o+8<=n.length;){let c=n.readUInt32LE(o),d=n.readUInt32LE(o+4);if(o+=8,o+c>n.length)return null;let u=n.subarray(o,o+c);d===1313821514?r=JSON.parse(u.toString("utf8").replace(/\0+$/g,"")):d===5130562&&i.push(Buffer.from(u)),o+=c}if(!r)return null;let s=Array.isArray(r.buffers)?r.buffers:[],a=await Promise.all(s.map(async(c,d)=>{let u=ce(c);return Ot(u?.uri)?ts(e,u):i[d]??(d===0?i[0]??null:null)}));return a.length===0&&i.length>0&&a.push(i[0]),{gltf:r,buffers:a}}async function ts(e,t){let n=Ot(t?.uri);if(!n)return null;let r=cs(n);if(r)return r.bytes;if(wr(n))return null;let i=ds(n);return i?as(e,i):null}async function Du(e,t,n){let r=Ot(n.uri);if(r){let g=cs(r);if(g){let D=Ar(g.bytes);return D?{bytes:g.bytes,...D}:null}if(wr(r))return null;let p=ds(r);if(!p)return null;let h=await as(e,p);if(!h)return null;let S=pe.basename(p),P=Ar(h);return P?{bytes:h,...P,originalFileName:S}:null}let i=Te(n.bufferView);if(i==null)return null;let o=Array.isArray(t.gltf.bufferViews)?t.gltf.bufferViews:[],s=ce(o[i]),a=Te(s?.buffer)??0,c=t.buffers[a],d=Te(s?.byteOffset)??0,u=Te(s?.byteLength);if(!c||u==null||d+u>c.length)return null;let l=Buffer.from(c.subarray(d,d+u)),f=Ar(l);return f?{bytes:l,...f}:null}async function as(e,t){if(pe.isAbsolute(t)||pe.win32.isAbsolute(t)||t.includes("\0"))return null;try{let n=await Nt.realpath(pe.dirname(e)),r=pe.resolve(n,t),i=await Nt.realpath(r);return ku(n,i)?await Nt.readFile(i):null}catch{return null}}function ds(e){if(wr(e))return null;try{return decodeURIComponent(e)}catch{return null}}function ku(e,t){let n=pe.relative(e,t);return n===""||!n.startsWith(`..${pe.sep}`)&&n!==".."&&!pe.isAbsolute(n)}function cs(e){let t=/^data:([^;,]+)?(?:;[^,]*)?,(.*)$/is.exec(e);if(!t)return null;let n=e.slice(0,e.indexOf(","));try{return{bytes:n.toLowerCase().includes(";base64")?Buffer.from(t[2]??"","base64"):Buffer.from(decodeURIComponent(t[2]??""),"utf8")}}catch{return null}}function Ar(e){return e.length>=8&&e.subarray(0,8).equals(Buffer.from([137,80,78,71,13,10,26,10]))?{extension:".png",mimeType:"image/png"}:e.length>=3&&e[0]===255&&e[1]===216&&e[2]===255?{extension:".jpg",mimeType:"image/jpeg"}:e.length>=12&&e.toString("ascii",0,4)==="RIFF"&&e.toString("ascii",8,12)==="WEBP"?{extension:".webp",mimeType:"image/webp"}:e.length>=12&&e.subarray(0,12).equals(Buffer.from([171,75,84,88,32,50,48,187,13,10,26,10]))?{extension:".ktx2",mimeType:"image/ktx2"}:null}function Mu(e){return["baseColor.texture","normal.texture","metallicRoughness.texture","occlusion.texture","emission.texture","emission.maskTexture","alpha.texture"].includes(e)}function Cu(e,t,n){let r=t.split("."),i=e;for(let o=0;o<r.length-1;o+=1){let s=r[o],a=ce(i[s])??{};i[s]=a,i=a}i[r[r.length-1]]=n}function wr(e){return/^[a-z][a-z0-9+.-]*:/i.test(e)||e.startsWith("/")||pe.win32.isAbsolute(e)}function ce(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function Ot(e){return typeof e=="string"&&e.trim()?e.trim():null}function Te(e){return Number.isInteger(e)&&e>=0?e:null}function ls(e){let t=typeof e=="string"&&e.trim()?e.trim():void 0;if(!t)return;if(t.includes("\0"))throw new Error("external_asset_path_must_be_portable");let n=t.replace(/\\/g,"/");if(n.startsWith("/")||/^[a-z]:\//i.test(n)||/^[a-z][a-z0-9+.-]*:/i.test(n))throw new Error("external_asset_path_must_be_portable");let r=[];for(let i of n.split("/"))if(!(!i||i===".")){if(i==="..")throw new Error("external_asset_path_must_be_portable");r.push(i)}if(r.length===0)throw new Error("external_asset_path_must_be_portable");return r.join("/")}function Dr(e){if(typeof e=="number"&&Number.isFinite(e)&&e>0)return e;if(!e||typeof e!="object")return;let t=e,n=Tr(t.x),r=Tr(t.y),i=Tr(t.z);if(!(n==null||r==null||i==null||n<=0||r<=0||i<=0))return{x:n,y:r,z:i}}function Tr(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function kr(e){return e==="shared"||e==="instance"?e:void 0}function Mr(e){return Number.isInteger(e)&&e>=0?e:void 0}var C=class extends Error{constructor(t,n={}){super(t),this.name="PlayableEditorAssetRegistryError",this.details=n}};function $u(e){let t={};for(let n=0;n<e.length;n+=1){let r=e[n];if(r==="--unregister"){t.unregister=!0;continue}if(r==="--payload"){t.payload=e[n+1],n+=1;continue}if(r==="--asset-id"){t.assetId=e[n+1],n+=1;continue}if(r==="--guid"){t.guid=e[n+1],n+=1;continue}if(r==="--delete-file"){t.deleteFile=!0;continue}if(r==="--keep-file"){t.deleteFile=!1;continue}(r==="--help"||r==="-h")&&(t.help=!0)}return t}async function bs(e,t=process.argv.slice(2)){let n=$u(t),r=await Fu(e),i=Y(r.errorCodes),o=(s,a={})=>{let c={ok:!1,error:s,...a};process.stderr.write(`${JSON.stringify(c,null,2)}
|
|
9
9
|
`),process.exit(1)};try{if(n.help){process.stdout.write(["Usage:",` ${e.commands?.register??"npm run asset:register"} -- --payload /path/to/payload.json`,` ${e.commands?.unregister??"npm run asset:unregister"} -- --payload /path/to/payload.json`,` ${e.commands?.unregister??"npm run asset:unregister"} -- --asset-id asset_xxx [--keep-file]`,` ${e.commands?.unregister??"npm run asset:unregister"} -- --guid xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx [--keep-file]`,""].join(`
|
|
10
10
|
`));return}if(n.unregister){let a=await ju(e,n,i);process.stdout.write(`${JSON.stringify(a)}
|
|
11
11
|
`);return}let s=await En(e,n,i);process.stdout.write(`${JSON.stringify(s)}
|