@galacean/cli 2.0.0-alpha.29 → 2.0.0-alpha.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.bundle.cjs +192793 -186137
- package/dist/preview-client/_static/{Accordion-6f002a96.js → Accordion-6346d8c5.js} +1 -1
- package/dist/preview-client/_static/{AmbientLightAsset-57a59fc2.js → AmbientLightAsset-ded8af87.js} +1 -1
- package/dist/preview-client/_static/{AnimationClipAsset-0a1f63eb.js → AnimationClipAsset-a767bb7a.js} +1 -1
- package/dist/preview-client/_static/{AnimatorControllerAsset-9192e596.js → AnimatorControllerAsset-c04c5158.js} +1 -1
- package/dist/preview-client/_static/{AnimatorStore-484b10cf.js → AnimatorStore-fd28fd44.js} +1 -1
- package/dist/preview-client/_static/{AssetViewer-9f395efb.js → AssetViewer-f505fb55.js} +1 -1
- package/dist/preview-client/_static/{AudioAsset-0ea4ba7b.js → AudioAsset-8b8ab944.js} +1 -1
- package/dist/preview-client/_static/{AudioComponent-9bf5944c.js → AudioComponent-4f62f1d6.js} +1 -1
- package/dist/preview-client/_static/{Callout-45631a14.js → Callout-7d87c30e.js} +1 -1
- package/dist/preview-client/_static/{CameraComponent-039457d1.js → CameraComponent-04ebed15.js} +1 -1
- package/dist/preview-client/_static/{Component-c3c0c167.js → Component-85241517.js} +1 -1
- package/dist/preview-client/_static/{DirectLight-7b1f4b9f.js → DirectLight-a2b904ed.js} +1 -1
- package/dist/preview-client/_static/{FontAsset-10273d05.js → FontAsset-5cd70e43.js} +1 -1
- package/dist/preview-client/_static/{FormItemArray-9d4196d8.js → FormItemArray-a06224b4.js} +1 -1
- package/dist/preview-client/_static/{GlTFAsset-917bf1ee.js → GlTFAsset-34fdaded.js} +1 -1
- package/dist/preview-client/_static/{IconPlus-2bfc60da.js → IconPlus-7690a910.js} +1 -1
- package/dist/preview-client/_static/{IconPointFilled-192e99c9.js → IconPointFilled-181a0586.js} +1 -1
- package/dist/preview-client/_static/{LightBaseComponent-948d3192.js → LightBaseComponent-6817bd8c.js} +1 -1
- package/dist/preview-client/_static/{LottieAnimationComponent-da226765.js → LottieAnimationComponent-fb9564f9.js} +1 -1
- package/dist/preview-client/_static/{MarkdownAsset-602f93bf.js → MarkdownAsset-ede9d841.js} +1 -1
- package/dist/preview-client/_static/{MaterialAsset-aa93db51.js → MaterialAsset-010030a2.js} +1 -1
- package/dist/preview-client/_static/{MaterialInspector-45e208c7.js → MaterialInspector-ebbe39d5.js} +1 -1
- package/dist/preview-client/_static/{Menu-beacc39d.js → Menu-7006a0c9.js} +1 -1
- package/dist/preview-client/_static/{MeshAsset-585f4b18.js → MeshAsset-3032a2d3.js} +1 -1
- package/dist/preview-client/_static/{MeshRendererBaseComponent-0bc9f5b3.js → MeshRendererBaseComponent-ea33dbe8.js} +1 -1
- package/dist/preview-client/_static/{MeshRendererComponent-84208d23.js → MeshRendererComponent-eaf512af.js} +1 -1
- package/dist/preview-client/_static/{MeshThumbnail-9bbe01dc.js → MeshThumbnail-3bb8bccf.js} +1 -1
- package/dist/preview-client/_static/ParticleRendererComponent-eb636961.js +31 -0
- package/dist/preview-client/_static/{PhysicsMaterialAsset-2dd013f8.js → PhysicsMaterialAsset-a768f5b6.js} +1 -1
- package/dist/preview-client/_static/PhysicsStore-8bca890a.js +1 -0
- package/dist/preview-client/_static/{PointLight-d9ace100.js → PointLight-1da0b361.js} +1 -1
- package/dist/preview-client/_static/{PostProcessComponent-2b5255d9.js → PostProcessComponent-366ce132.js} +1 -1
- package/dist/preview-client/_static/{PrefabAsset-8c923465.js → PrefabAsset-9e17aab2.js} +1 -1
- package/dist/preview-client/_static/{PrimitiveMesh-fde624a6.js → PrimitiveMesh-81a302d9.js} +1 -1
- package/dist/preview-client/_static/{ReferencedMaterial-890492a2.js → ReferencedMaterial-240e1be6.js} +1 -1
- package/dist/preview-client/_static/{RenderTargetAsset-bf38a725.js → RenderTargetAsset-81649762.js} +1 -1
- package/dist/preview-client/_static/{SceneAsset-7a9dbdd8.js → SceneAsset-68286235.js} +1 -1
- package/dist/preview-client/_static/{ShaderAsset-2f2c1e95.js → ShaderAsset-b2ea36b6.js} +25 -25
- package/dist/preview-client/_static/{ShaderChunkAsset-a3ff3959.js → ShaderChunkAsset-e32e6108.js} +1 -1
- package/dist/preview-client/_static/{ShaderUIScriptAsset-d3a2d680.js → ShaderUIScriptAsset-4adc4d41.js} +1 -1
- package/dist/preview-client/_static/{SkinnedMeshRendererComponent-96740600.js → SkinnedMeshRendererComponent-c0f2037a.js} +1 -1
- package/dist/preview-client/_static/{SpineAnimationComponent-3d4eec48.js → SpineAnimationComponent-ec1ed804.js} +1 -1
- package/dist/preview-client/_static/{SpineSkeletonDataAsset-a8598103.js → SpineSkeletonDataAsset-0fdb1ffc.js} +1 -1
- package/dist/preview-client/_static/{SpotLight-680a6e17.js → SpotLight-7da01a5f.js} +1 -1
- package/dist/preview-client/_static/{SpriteBaseComponent-96a500d7.js → SpriteBaseComponent-5027461c.js} +1 -1
- package/dist/preview-client/_static/{SpriteMaskComponent-58c35ea2.js → SpriteMaskComponent-ea250ae6.js} +1 -1
- package/dist/preview-client/_static/{SpriteRendererComponent-5c89f7dd.js → SpriteRendererComponent-fc459130.js} +1 -1
- package/dist/preview-client/_static/{TextBaseComponent-248ea222.js → TextBaseComponent-269e86ed.js} +1 -1
- package/dist/preview-client/_static/{TextRendererComponent-78458825.js → TextRendererComponent-e1a70d05.js} +1 -1
- package/dist/preview-client/_static/{TextureAsset-bf69040b.js → TextureAsset-adf746d9.js} +1 -1
- package/dist/preview-client/_static/{Tooltip-0268ffac.js → Tooltip-c84e8c00.js} +1 -1
- package/dist/preview-client/_static/{TrailRendererComponent-838e0118.js → TrailRendererComponent-7c1adc57.js} +1 -1
- package/dist/preview-client/_static/{TransformBaseComponent-c92aa259.js → TransformBaseComponent-bc3d99f0.js} +1 -1
- package/dist/preview-client/_static/{TransformComponent-d28b4035.js → TransformComponent-828e97ca.js} +1 -1
- package/dist/preview-client/_static/{XRReferenceImageAsset-16071f5c.js → XRReferenceImageAsset-699f6a74.js} +1 -1
- package/dist/preview-client/_static/{audio-1d573775.js → audio-5b6bbad7.js} +1 -1
- package/dist/preview-client/_static/{createOnModelChange-38471bb6.js → createOnModelChange-f0aaf591.js} +1 -1
- package/dist/preview-client/_static/{createReactComponent-3e49f864.js → createReactComponent-0c5ada83.js} +1 -1
- package/dist/preview-client/_static/{index-2f54d4c9.js → index-066cf34f.js} +1 -1
- package/dist/preview-client/_static/{index-4084db44.js → index-07a70c10.js} +1 -1
- package/dist/preview-client/_static/index-21ffc50d.js +1 -0
- package/dist/preview-client/_static/{index-65c6af4a.js → index-4145c87e.js} +3 -3
- package/dist/preview-client/_static/index-492bd067.js +1 -0
- package/dist/preview-client/_static/index-49a5902b.js +1 -0
- package/dist/preview-client/_static/index-6a2d3d63.js +1 -0
- package/dist/preview-client/_static/{index-8a22fe59.js → index-828538e1.js} +1 -1
- package/dist/preview-client/_static/{index-ce381b62.js → index-89133895.js} +2 -2
- package/dist/preview-client/_static/index-895723b4.js +1 -0
- package/dist/preview-client/_static/{index-1fa3ba70.js → index-981e5626.js} +1 -1
- package/dist/preview-client/_static/index-b154ff9d.js +1 -0
- package/dist/preview-client/_static/{index-9e3daa94.js → index-b4b2d2e5.js} +1 -1
- package/dist/preview-client/_static/{index-d497fb6d.js → index-eeedc550.js} +1072 -651
- package/dist/preview-client/_static/index-f145c261.js +1 -0
- package/dist/preview-client/_static/{index-68806c86.js → index-f655a65a.js} +1 -1
- package/dist/preview-client/_static/{ktx2-encoder-772f6c33.js → ktx2-encoder-2883b55c.js} +1 -1
- package/dist/preview-client/_static/{module-1470d524.js → module-11aabe24.js} +1 -1
- package/dist/preview-client/_static/{module-136992e3.js → module-ace60695.js} +1 -1
- package/dist/preview-client/_static/{module-77c2ea8c.js → module-be69621d.js} +1 -1
- package/dist/preview-client/_static/postmen-fe9eecc4.js +2 -0
- package/dist/preview-client/_static/{shader-data-utils-e38a959d.js → shader-data-utils-c00c9d18.js} +1 -1
- package/dist/preview-client/index.html +1 -1
- package/dist/types/tsconfig.exec-base.json +20 -0
- package/dist/types/typed-exec-api.d.ts +487 -0
- package/package.json +4 -2
- package/dist/preview-client/_static/ParticleRendererComponent-f3ac8d1b.js +0 -26
- package/dist/preview-client/_static/PhysicsStore-fcb01282.js +0 -1
- package/dist/preview-client/_static/index-0a57ae09.js +0 -1
- package/dist/preview-client/_static/index-1d0ae2e4.js +0 -1
- package/dist/preview-client/_static/index-2c567b8d.js +0 -1
- package/dist/preview-client/_static/index-5c27dafa.js +0 -1
- package/dist/preview-client/_static/index-bdda02cf.js +0 -1
- package/dist/preview-client/_static/index-c88f78ce.js +0 -1
- package/dist/preview-client/_static/index-e4fb05d8.js +0 -1
- package/dist/preview-client/_static/postmen-0413c689.js +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
var Le=Object.defineProperty;var Ve=(r,e,t)=>e in r?Le(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var C=(r,e,t)=>(Ve(r,typeof e!="symbol"?e+"":e,t),t);import{e0 as qe,e1 as Ie,e2 as Ue,aJ as be,aK as Je,aL as O,bC as Ge,q as he,aO as We,aw as He,e3 as Qe,C as Ye,bH as Xe,e4 as Ee,e5 as Ze,e6 as W,e7 as et,e8 as tt,e9 as nt,b_ as st,e as J,ea as ge,eb as rt,ec as ot,ed as it,ee as ct,ef as at,eg as dt,eh as ut,ei as ft,ej as lt,ek as ht,el as pt,em as mt,en as we,eo as yt,bY as _e,ep as ne,eq as Pe,er as St,es as It,et as bt,eu as Et,ev as gt,K as Ce,m as wt,aU as _t,x as Pt,aC as Fe,n as Ct,dN as Rt,ew as $t}from"./index-d497fb6d.js";import{T as vt}from"./TaskQueue-05c94a4d.js";import{u as Re,I as At}from"./index-8a22fe59.js";import"./postmen-0413c689.js";import{A as Tt}from"./AssetViewer-9f395efb.js";function A(r){return structuredClone(r)}function H(r,e){const t=r.entities.findIndex(n=>n.id===e);if(t<0)throw new Error(`Prefab source entity "${e}" not found`);return t}function ke(r,e){const t=r.components.findIndex(n=>n.id===e);if(t<0)throw new Error(`Prefab source component "${e}" not found`);return t}function oe(r,e,t){if(!t)return;const n=e==="scale"?[1,1,1]:[0,0,0],s=r[e]??n;r[e]=[t.x??s[0],t.y??s[1],t.z??s[2]]}function $e(r,e,t){const n=new Set(e),s=new Set;for(const o of t){if(s.has(o))throw new Error(`Prefab source ${r} id "${o}" is duplicated in the added source tree`);if(n.has(o))throw new Error(`Prefab source ${r} id "${o}" already exists`);s.add(o)}}function xt(r){return r.entities.map(e=>e.id)}function Ne(r){return r.components.map(e=>e.id)}function Ot(r){const e=new Set(r.entityIds),t=new Set(r.componentIds);return r.entities.map((n,s)=>{var c,a;const o=r.entityIds[s],i=structuredClone(n);return i.id=o,(c=i.children)!=null&&c.length&&(i.children=i.children.map(d=>{const u=typeof d=="number"?r.entityIds[d]:d;if(!e.has(u))throw new Error(`Prefab added source entity "${o}" child "${String(d)}" is outside added entity tree`);return u})),(a=i.components)!=null&&a.length&&(i.components=i.components.map(d=>{const u=typeof d=="number"?r.componentIds[d]:d;if(!t.has(u))throw new Error(`Prefab added source entity "${o}" component "${String(d)}" is outside added component list`);return u})),i})}function Mt(r){return r.components.map((e,t)=>({...structuredClone(e),id:r.componentIds[t]}))}function Dt(r,e){const t=new Map(r.entities.map(o=>[o.id,o])),n=new Set,s=o=>{if(n.has(o))return;n.add(o);const i=t.get(o);for(const c of(i==null?void 0:i.children)??[])s(c)};return s(e),n}function Ft(r,e,t){var o,i,c;if(!t)return A(r);const n=A(r),s=n.entities[H(n,e)];return t.name!==void 0&&(s.name=t.name),t.isActive!==void 0&&(t.isActive?delete s.isActive:s.isActive=!1),t.layer!==void 0&&(t.layer===0?delete s.layer:s.layer=t.layer),t.isLocked!==void 0&&(t.isLocked?s.isLocked=!0:delete s.isLocked),oe(s,"position",(o=t.transform)==null?void 0:o.position),oe(s,"rotation",(i=t.transform)==null?void 0:i.rotation),oe(s,"scale",(c=t.transform)==null?void 0:c.scale),n}function kt(r,e,t){if(!t||Object.keys(t).length===0)return A(r);const n=A(r),s=n.components[ke(n,e)];return s.props=qe(s.props??{},t),n}function Nt(r,e){if(e.entities.length===0||e.entities.length!==e.entityIds.length)throw new Error("Prefab added entity tree must include matching entities and entityIds");if(e.components.length!==e.componentIds.length)throw new Error("Prefab added entity tree must include matching components and componentIds");$e("entity",xt(r),e.entityIds),$e("component",Ne(r),e.componentIds);const t=A(r),n=t.entities[H(t,e.parentSourceEntityId)],s=Ot(e),o=Mt(e),i=e.entityIds[0];t.entities.push(...s),t.components.push(...o);const c=[...n.children??[]],a=Math.min(Math.max(e.index,0),c.length);return c.splice(a,0,i),n.children=c,t}function jt(r,e){var l;const t=A(r),n=t.entities[H(t,e.instanceSourceEntityId)];if(!n.instance)throw new Error(`Prefab source entity "${e.instanceSourceEntityId}" is not an instance entity`);const s=(l=n.instance).overrides??(l.overrides={}),o=[...s.addedEntities??[]],i=Math.max(0,e.index);let c=0,a=o.length;for(let m=0;m<o.length;m+=1)if(o[m].parent===e.parentSourceEntityId){if(c===i){a=m;break}c+=1,a=m+1}const d=structuredClone(e.entity),u=d.id??`${e.instanceSourceEntityId}:added:${o.length}`;return d.id=u,o.splice(a,0,{id:u,parent:e.parentSourceEntityId,entity:d}),s.addedEntities=o,t}function zt(r,e){if(r.root===e)throw new Error("Cannot remove prefab root entity from source");H(r,e);const t=Dt(r,e),n=new Set;for(const o of r.entities)if(t.has(o.id))for(const i of o.components??[])n.add(i);const s=A(r);return s.entities=s.entities.filter(o=>!t.has(o.id)).map(o=>{const i=structuredClone(o),c=(i.children??[]).filter(d=>!t.has(d)),a=(i.components??[]).filter(d=>!n.has(d));return c.length?i.children=c:delete i.children,a.length?i.components=a:delete i.components,i}),s.components=s.components.filter(o=>!n.has(o.id)),s}function Bt(r,e,t,n){if(Ne(r).includes(t))throw new Error(`Prefab source component id "${t}" already exists`);const s=A(r),o=s.entities[H(s,e)];return s.components.push({...structuredClone(n),id:t}),o.components=[...o.components??[],t],s}function Kt(r,e){ke(r,e);const t=A(r);return t.components=t.components.filter(n=>n.id!==e),t.entities=t.entities.map(n=>{const s=structuredClone(n),o=(s.components??[]).filter(i=>i!==e);return o.length?s.components=o:delete s.components,s}),t}function Lt(r){switch(r.kind){case"add-source-entity":if(r.sourceEntityIds.length===0)throw new Error("Prefab source edit add-source-entity requires at least one source entity id");return;case"remove-source-entity":if(!r.sourceEntityId)throw new Error("Prefab source edit remove-source-entity requires a source entity id");return;case"add-source-component":if(!r.sourceComponentId)throw new Error("Prefab source edit add-source-component requires a source component id");return;case"remove-source-component":if(!r.sourceComponentId)throw new Error("Prefab source edit remove-source-component requires a source component id");return;case"add-nested-instance-entity":if(!r.instanceSourceEntityId)throw new Error("Prefab source edit add-nested-instance-entity requires an instance source entity id");if(!r.parentSourceEntityId)throw new Error("Prefab source edit add-nested-instance-entity requires a parent source entity id");return}}function ve(r,e){return r.length===e.length&&r.every((t,n)=>t===e[n])}function G(r,e,t){const n=new Set(e);for(const s of t)if(!n.has(s))throw new Error(`Prefab source edit expected ${r} id "${s}" to exist`)}function se(r,e,t){const n=new Set(e);for(const s of t)if(n.has(s))throw new Error(`Prefab source edit expected ${r} id "${s}" to be removed`)}function D(r){return r.entities.map(e=>e.id)}function z(r){return r.components.map(e=>e.id)}function je(r,e){const t=r.entities.findIndex(n=>n.id===e);if(t<0)throw new Error(`Prefab source edit expected entity id "${e}" to exist`);return t}function Vt(r,e){var n;const t=je(r,e);if(!((n=r.entities[t])!=null&&n.instance))throw new Error(`Prefab source edit expected entity id "${e}" to be an instance entity`)}function Ae(r,e,t){var s,o,i;const n=je(r,e);return(((i=(o=(s=r.entities[n])==null?void 0:s.instance)==null?void 0:o.overrides)==null?void 0:i.addedEntities)??[]).filter(c=>c.parent===t).length}function F(r,e,t,n,s){if(r!=null){if(Array.isArray(r)){r.forEach((o,i)=>F(o,e,t,`${n}[${i}]`,s));return}if(Ue(r)){r.$component===e&&s.push({entityId:t,propPath:n});for(const[o,i]of Object.entries(r))F(i,e,t,`${n}.${o}`,s)}}}function ze(r,e,t,n,s){var o;F(r.props,e,t,`${n}.props`,s),(o=r.calls)==null||o.forEach((i,c)=>F(i,e,t,`${n}.calls[${c}]`,s))}function Be(r,e,t,n,s){var o,i,c;(o=r.components)==null||o.forEach((a,d)=>ze(a,e,t,`${n}.components[${d}]`,s)),(i=r.children)==null||i.forEach((a,d)=>Be(a,e,t,`${n}.children[${d}]`,s)),Ke((c=r.instance)==null?void 0:c.overrides,e,t,`${n}.instance.overrides`,s)}function Ke(r,e,t,n,s){var o,i,c;(o=r==null?void 0:r.componentProps)==null||o.forEach((a,d)=>F(a.props,e,t,`${n}.componentProps[${d}].props`,s)),(i=r==null?void 0:r.addedComponents)==null||i.forEach((a,d)=>ze(a.component,e,t,`${n}.addedComponents[${d}].component`,s)),(c=r==null?void 0:r.addedEntities)==null||c.forEach((a,d)=>Be(a.entity,e,t,`${n}.addedEntities[${d}].entity`,s))}function qt(r,e){var s,o;const t=[],n=new Map;for(const i of r.entities)for(const c of i.components??[])n.set(c,i.id);for(const i of r.components){if(i.id===e)continue;const c=n.get(i.id)??"<unowned>";F(i.props,e,c,`components.${i.id}.props`,t),(s=i.calls)==null||s.forEach((a,d)=>F(a,e,c,`components.${i.id}.calls[${d}]`,t))}for(const i of r.entities)Ke((o=i.instance)==null?void 0:o.overrides,e,i.id,`entities.${i.id}.instance.overrides`,t);return t}function Ut(r,e){const t=qt(r,e);if(t.length!==0)throw new Error(`Cannot remove component "${e}": it is referenced by $component bindings in ${t.map(n=>`entity "${n.entityId}" prop "${n.propPath}"`).join(", ")}. Remove the bindings first.`)}function Jt(r,e){switch(e.kind){case"add-source-entity":se("entity",D(r),e.sourceEntityIds);return;case"remove-source-entity":G("entity",D(r),[e.sourceEntityId]);return;case"add-source-component":se("component",z(r),[e.sourceComponentId]);return;case"remove-source-component":G("component",z(r),[e.sourceComponentId]),Ut(r,e.sourceComponentId);return;case"add-nested-instance-entity":G("entity",D(r),[e.instanceSourceEntityId]),Vt(r,e.instanceSourceEntityId);return}}function Gt(r,e,t){switch(t.kind){case"add-source-entity":G("entity",D(e),t.sourceEntityIds);return;case"remove-source-entity":se("entity",D(e),[t.sourceEntityId]);return;case"add-source-component":G("component",z(e),[t.sourceComponentId]);return;case"remove-source-component":se("component",z(e),[t.sourceComponentId]);return;case"add-nested-instance-entity":{if(!ve(D(r),D(e))||!ve(z(r),z(e)))throw new Error("Prefab source edit add-nested-instance-entity must not change source entity or component ids");const n=Ae(r,t.instanceSourceEntityId,t.parentSourceEntityId);if(Ae(e,t.instanceSourceEntityId,t.parentSourceEntityId)!==n+1)throw new Error(`Prefab source edit expected nested added entity count under "${t.parentSourceEntityId}" to increase by 1`);return}}}function Q(r){Lt(r.intent),Ie(r.prefabFile),Jt(r.prefabFile,r.intent);const e=r.mutation(r.prefabFile);return Ie(e),Gt(r.prefabFile,e,r.intent),e}function Wt(r,e){return Q({prefabFile:r,intent:{kind:"add-source-entity",sourceEntityIds:e.entityIds},mutation:t=>Nt(t,e)})}function Ht(r,e){return Q({prefabFile:r,intent:{kind:"add-nested-instance-entity",instanceSourceEntityId:e.instanceSourceEntityId,parentSourceEntityId:e.parentSourceEntityId},mutation:t=>jt(t,e)})}function Qt(r,e){return Q({prefabFile:r,intent:{kind:"remove-source-entity",sourceEntityId:e},mutation:t=>zt(t,e)})}function Yt(r,e){return Q({prefabFile:r,intent:{kind:"add-source-component",sourceComponentId:e.sourceComponentId},mutation:t=>Bt(t,e.sourceEntityId,e.sourceComponentId,e.component)})}function Xt(r,e){return Q({prefabFile:r,intent:{kind:"remove-source-component",sourceComponentId:e},mutation:t=>Kt(t,e)})}class ae{static update(e,t){!this.entity&&(this.entity=e.createChild("prefab"));const n=this.tempCloneEntity=t.instantiateEngineObject();this.entity.addChild(n)}static clear(){var e;(e=this.entity)==null||e.clearChildren(),this.tempCloneEntity&&this.tempCloneEntity.destroy(),this.tempCloneEntity=null}}C(ae,"entity"),C(ae,"tempCloneEntity");const Zt=be(({asset:r})=>{const{dependentAssets:e}=r,{configDataStore:t}=Re(),{t:n}=Je(),s=be(({dependentAssetInfo:o})=>{const{assetStore:i}=Re(),c=Object.values(i.assets).filter(u=>{const l=u.getMetaConfig().type,m=u.id===o.id,h=u.id===r.id,f=!m&&!h&&!u.isSubAsset;return o.type==="glTF"||o.type==="Prefab"?l==="glTF"||l==="Prefab"&&f:u.getMetaConfig().type===o.type&&f}),a=i.assets[o.id],d=a==null?void 0:a.name;return O.jsx(Ge,{dropLayer:he.Asset,placeholder:n("prefab.inspector.missed"),assets:c,onSelect:u=>{r.replaceDependentAsset(o,u)},onLocate:()=>{i.selectAsset(o.id)},value:d,asset:a})});return O.jsxs(O.Fragment,{children:[O.jsx(We,{title:n("prefab.inspector.basic-info"),defaultOpen:!0,children:t.isBuc&&O.jsx(He,{label:n("prefab.inspector.url")})}),O.jsx(Qe,{label:n("prefab.inspector.dependent-assets"),children:e.map((o,i)=>O.jsx(s,{dependentAssetInfo:o},`${o.id}-${i}`))})]})}),en={asset:{version:"2.0"},root:"defaultPrefab",entities:[{id:"defaultPrefab",name:"prefab"}],components:[]};class tn extends Tt{constructor(){super(...arguments);C(this,"_animators",[]);C(this,"_particles",[])}setViewAsset(t,n){const s=t.entityManager.rootEntities[0];this._entity=s.engineObject,n.addChild(this._entity),s.getComponentsIncludeChildren("Animator",this._animators).forEach(c=>{c.applyBoundPathChange("enabled",Ye.Toggle,c.enabled)}),this._entity.getComponentsIncludeChildren(Xe,this._particles).forEach(c=>{c.generator.stop(!1,Ee.StopEmittingAndClear),c.generator.main.simulationSpeed=1,c.generator.play()})}stopViewAsset(){super.stopViewAsset(),this._particles.forEach(t=>{t.generator.stop(!1,Ee.StopEmittingAndClear)})}}const nn=new Set(["$ref","refId"]);function de(r,e,t){if(Array.isArray(r))return r.map(o=>de(o,e,t));if(!r||typeof r!="object")return r;const n=r,s={};for(const[o,i]of Object.entries(n))s[o]=nn.has(o)&&i===e?t:de(i,e,t);return s}function sn(r,e,t){return de(r,e,t)}function rn(r,e,t){const n=Ze(t);if(typeof e.id!="string"||e.id.length===0)throw new Error(`[SceneV2] Unable to replace prefab asset ref "${e.id}": missing old asset id`);return sn(r,e.id,n)}function on(r,e){const t=e.entities.findIndex(n=>n.id===e.root);if(!e.entities[t])throw new Error(`Prefab asset "${r}" source root "${e.root}" was not found.`);return t}function k(r,e,t){const n=e.entities[t];if(!n)throw new Error(`Prefab asset "${r}" source entity at index "${t}" was not found.`);return n}function B(r,e,t){var s;const n=(s=e.entities[t])==null?void 0:s.id;if(!n)throw new Error(`Prefab asset "${r}" source entity at index "${t}" is missing a stable source id.`);return n}function cn(r,e,t){var s;const n=(s=e.components[t])==null?void 0:s.id;if(!n)throw new Error(`Prefab asset "${r}" source component at index "${t}" is missing a stable source id.`);return n}function Te(r,e,t){const n=k(r,e,t);if(W(n))return[];const s=(n.children??[]).map(o=>e.entities.findIndex(i=>i.id===o));for(const o of s)if(!e.entities[o])throw new Error(`Prefab asset "${r}" source child index "${o}" on entity "${t}" was not found.`);return s}function xe(r,e,t){const n=k(r,e,t);return W(n)?[]:(n.components??[]).map(s=>{const o=e.components.findIndex(c=>c.id===s),i=e.components[o];if(!i)throw new Error(`Prefab asset "${r}" source component "${s}" was not found.`);return{key:cn(r,e,o),type:i.type,schema:i}})}function Oe(r,e,t,n,s){var a,d;const o=B(r,e,t),i=n.find(u=>u.id===o&&!s.has(u.id));if(i)return i;const c=k(r,e,t);if(!W(c)&&!((d=(a=c.instance)==null?void 0:a.asset)!=null&&d.$ref))throw new Error(`Prefab source child "${o}" cannot be matched to a loaded source entity.`)}function an(r,e,t,n){const s=o=>!t.type||o.type===t.type;if(n){const o=r.find(i=>i.key===n&&!e.has(i.key)&&s(i));if(o)return o}if(t.id){const o=r.find(i=>i.key===t.id&&!e.has(i.key)&&s(i));if(o)return o}}function dn(r,e,t,n){const s=(e==null?void 0:e.components)??[],o=t==null?void 0:t.get(r.key);if(o){const c=s.find(a=>(a==null?void 0:a.id)===o&&!a.ignoreToJSON);if(c)return c}const i=s.find(c=>{var d;return!(c!=null&&c.id)||n.has(c.id)||c.ignoreToJSON||((d=c.instance)==null?void 0:d.sourceComponentKey)!==r.key?!1:!c.type||c.type===r.type});if(i)return i}function un(r){var a,d,u,l,m,h,f,y;const e=k(r.assetId,r.prefabFile,r.sourceIndex),t=B(r.assetId,r.prefabFile,r.sourceIndex),n=(d=(a=e==null?void 0:e.instance)==null?void 0:a.asset)==null?void 0:d.$ref;if(!n||!W(e))return!1;const s=((m=(l=(u=r.normalized)==null?void 0:u.entities)==null?void 0:l[r.sceneChild.id])==null?void 0:m.instance)??r.sceneChild.instance,o=s==null?void 0:s.bindingId,i=o?(y=(f=(h=r.normalized)==null?void 0:h.prefab)==null?void 0:f.bindings)==null?void 0:y[o]:void 0,c=r.resolveInstanceAsset(n,t);return c?i?i.instanceRootEntityId===r.sceneChild.id&&i.assetId===c.id&&i.assetKind===c.kind:(s==null?void 0:s.assetId)===c.id&&(s==null?void 0:s.assetKind)===c.kind&&(!(s!=null&&s.role)||s.role==="root"):!1}function fn(r){var s,o;const t=(o=(s=k(r.assetId,r.prefabFile,r.sourceIndex).instance)==null?void 0:s.asset)==null?void 0:o.$ref;if(typeof t!="string")return;const n=r.resolveInstanceAsset(t,r.sourceEntityId);if(!n)throw new Error(`Prefab source entity "${r.sourceEntityId}" references missing instance asset "${t}".`);if(n.kind!=="Prefab"&&n.kind!=="glTF")throw new Error(`Prefab source entity "${r.sourceEntityId}" references unsupported instance asset "${t}" of type "${String(n.kind)}".`);return n}function ln(r,e){var o,i,c,a;if(!(r!=null&&r.id))return;const t=((i=(o=e==null?void 0:e.entities)==null?void 0:o[r.id])==null?void 0:i.instance)??r.instance,n=t==null?void 0:t.bindingId,s=n?(a=(c=e==null?void 0:e.prefab)==null?void 0:c.bindings)==null?void 0:a[n]:void 0;return typeof(s==null?void 0:s.sourceRootEntityId)=="string"?s.sourceRootEntityId:void 0}function ie(r,e){return{x:Number((r==null?void 0:r.x)??e.x),y:Number((r==null?void 0:r.y)??e.y),z:Number((r==null?void 0:r.z)??e.z)}}function hn(r,e){const t=r==null?void 0:r.transform;return{position:t!=null&&t.position?ie(t.position,{x:0,y:0,z:0}):e.position,rotation:t!=null&&t.rotation?ie(t.rotation,{x:0,y:0,z:0}):e.rotation,scale:t!=null&&t.scale?ie(t.scale,{x:1,y:1,z:1}):e.scale}}function pn(r,e,t){const n=r==null?void 0:r.layer;return Array.isArray(n)?t?t(n):e:typeof n=="number"?n:e}function mn(r){var c,a,d,u,l,m;const e=(c=r.normalized)==null?void 0:c.components,t=(r.sceneComponentId?e==null?void 0:e[r.sceneComponentId]:void 0)??((a=r.component)!=null&&a.id?e==null?void 0:e[r.component.id]:void 0),n={},s=(t==null?void 0:t.refId)??(typeof((d=r.schema.script)==null?void 0:d.$ref)=="string"?nt(r.schema.script.$ref):void 0);s&&(n.refId=s);const o=(t==null?void 0:t.scriptKey)??((u=r.schema.script)==null?void 0:u.key);o&&(n.scriptKey=o);const i=(l=t==null?void 0:t.calls)!=null&&l.length?structuredClone(t.calls):(m=r.schema.calls)!=null&&m.length?r.convertSourceRefsToDomainRefs(structuredClone(r.schema.calls)):void 0;return i!=null&&i.length&&(n.calls=i),n}function yn(r){var e,t;return r.sceneEntityIdBySource.has(r.sourceEntityId)?((t=(e=r.allowMissingSceneComponentSourceKeys)==null?void 0:e.get(r.sourceEntityId))==null?void 0:t.has(r.sourceComponentKey))===!0:!0}function Sn(r){const{assetId:e,prefabFile:t,sourceRoot:n,sceneRoot:s,normalized:o}=r,i=[],c=[],a=new Map,d=new Map,u=on(e,t),l=y=>{var b,_;const p=((_=(b=o==null?void 0:o.entities)==null?void 0:b[y.id])==null?void 0:_.instance)??y.instance;return(p==null?void 0:p.role)==="added"},m=(y,p,b,_)=>{var q,ee,te,U;if(l(b))return;const P=B(e,t,y),g=k(e,t,y),T=W(g);i.push({sceneEntityId:b.id,sourceEntityId:P,role:_}),a.set(P,b.id);const K=xe(e,t,y),X=b.components??[],R=new Set;for(const I of X){if(!(I!=null&&I.id)||I.ignoreToJSON)continue;const S=((ee=(q=o==null?void 0:o.components)==null?void 0:q[I.id])==null?void 0:ee.instance)??I.instance;if((S==null?void 0:S.role)==="added")continue;const w=((te=r.sceneSourceComponentKeys)==null?void 0:te.get(I.id))??(S==null?void 0:S.sourceComponentKey),E=an(K,R,I,w);if(!E){if(!T)throw new Error(`Prefab asset "${e}" live scene component "${I.id}" on source entity "${P}" cannot be matched to a prefab source component.`);continue}R.add(E.key),c.push({sceneEntityId:b.id,sceneComponentId:I.id,sourceComponentKey:E.key});const $=d.get(P)??new Map;$.set(E.key,I.id),d.set(P,$)}const j=Te(e,t,y),Z=(p==null?void 0:p.children)??[],x=b.children??[],L=new Set,V=new Set;for(let I=0;I<j.length;I++){const S=j[I],w=B(e,t,S),E=Oe(e,t,S,Z,L);E!=null&&E.id&&L.add(E.id);const $=x.find(v=>{var me,ye,Se;if(V.has(v.id)||l(v))return!1;if(v.id===w||E!=null&&E.id&&v.id===E.id||un({assetId:e,prefabFile:t,sourceIndex:S,sceneChild:v,normalized:o,resolveInstanceAsset:r.resolveInstanceAsset}))return!0;const re=((ye=(me=o==null?void 0:o.entities)==null?void 0:me[v.id])==null?void 0:ye.instance)??v.instance,pe=((Se=r.sceneSourceEntityIds)==null?void 0:Se.get(v.id))??(re==null?void 0:re.sourceEntityId)??v.instanceSourceEntityId;return pe===w||(E==null?void 0:E.id)&&pe===E.id});if(!$){if((U=r.allowMissingSceneChildSourceIds)!=null&&U.has(w))continue;throw new Error(`Prefab asset "${e}" source child "${w}" cannot be matched to live scene child under source entity "${P}".`)}V.add($.id),m(S,E,$,"linked")}},h={},f=(y,p,b,_)=>{const P=k(e,t,y),g=B(e,t,y),T={},K=xe(e,t,y),X=new Set;K.forEach(I=>{var $;const S=dn(I,p,d.get(g),X);if(S!=null&&S.ignoreToJSON)return;S!=null&&S.id&&X.add(S.id);const w=typeof(S==null?void 0:S.toJSON)=="function"?S.toJSON():I.schema,E=($=d.get(g))==null?void 0:$.get(I.key);if(!E&&!yn({sourceEntityId:g,sourceComponentKey:I.key,sceneEntityIdBySource:a,allowMissingSceneComponentSourceKeys:r.allowMissingSceneComponentSourceKeys}))throw new Error(`Prefab asset "${e}" source component "${I.key}" on source entity "${g}" cannot be matched to live scene component.`);T[I.key]={sceneComponentId:E,type:w.type??(S==null?void 0:S.type),...mn({component:S,schema:w,sceneComponentId:E,normalized:o,convertSourceRefsToDomainRefs:r.convertSourceRefsToDomainRefs}),props:r.collectComponentProps(S,w)}});const R=fn({assetId:e,prefabFile:t,sourceIndex:y,sourceEntityId:g,resolveInstanceAsset:r.resolveInstanceAsset}),j=R==null?void 0:R.kind,Z=et({sourceEntity:P,fallbackSourceEntityId:g,instanceAssetKind:j,bindingSourceRootEntityId:ln(p,o)??(R==null?void 0:R.sourceRootEntityId)}),x=tt(P,g,{...typeof Z=="string"?{rootOverrideTarget:Z}:{},resolveInstanceAssetDisplayName:r.resolveInstanceAssetDisplayName}),L=pn(p,x.layer,r.combineLayers),V=(p==null?void 0:p.isLocked)??x.isLocked,q=Te(e,t,y),ee=q.map(I=>B(e,t,I));h[g]={sceneEntityId:a.get(g),parentSourceEntityId:b,childSourceEntityIds:ee,childIndex:_,...j?{instanceAssetKind:j}:{},name:(p==null?void 0:p.name)??x.name,isActive:(p==null?void 0:p.isActive)??x.isActive,...L!==void 0?{layer:L}:{},...V!==void 0?{isLocked:V}:{},transform:hn(p,x.transform),components:T};const te=(p==null?void 0:p.children)??[],U=new Set;q.forEach((I,S)=>{const w=Oe(e,t,I,te,U);w!=null&&w.id&&U.add(w.id),f(I,w,g,S)})};return m(u,n,s,"root"),f(u,n,null,0),{entityMappings:i,componentMappings:c,sourceEntitySnapshots:h}}class In{constructor(e){this.host=e}async apply(e,t){const n=this.host.readSourceFile(),s=e(n);try{if(this.host.writeSourceFile(s),this.host.syncDependentAssets(),this.host.updateCreateByAddResumeSnapshot(),(t==null?void 0:t.refresh)===!1)return;await this.host.refreshContent((t==null?void 0:t.structuralDeltaMode)==="domain-source-replace"?{structuralDeltaMode:"domain-source-replace"}:void 0)}catch(o){throw this.host.writeSourceFile(n),this.host.syncDependentAssets(),this.host.updateCreateByAddResumeSnapshot(),o}}}var bn=Object.defineProperty,En=Object.getOwnPropertyDescriptor,Y=(r,e,t,n)=>{for(var s=n>1?void 0:n?En(e,t):e,o=r.length-1,i;o>=0;o--)(i=r[o])&&(s=(n?i(e,t,s):i(s))||s);return n&&s&&bn(e,t,s),s};const M=Rt("PrefabAsset"),Me=new $t("PrefabAsset");function gn(r){if(!Array.isArray(r))return null;const e=new Set(["id","name","type"]),t=[];for(const n of r){if(!n||typeof n!="object")return null;const s=n;if(!Object.keys(s).every(o=>e.has(o))||typeof s.id!="string"||typeof s.name!="string"||typeof s.type!="string")return null;t.push({id:s.id,name:s.name,type:s.type})}return t}const ue=[0,0,0],fe=[0,0,0],le=[1,1,1];function De(r){const e=new Map;for(const[t,n]of r)e.set(n,t);return e}function ce(r,e,t){const n=r??e;return[(t==null?void 0:t.x)??n[0],(t==null?void 0:t.y)??n[1],(t==null?void 0:t.z)??n[2]]}function wn(r,e){e&&Object.assign(r,{...e.position?{position:ce(r.position,ue,e.position)}:{},...e.rotation?{rotation:ce(r.rotation,fe,e.rotation)}:{},...e.scale?{scale:ce(r.scale,le,e.scale)}:{}})}let N=class extends At{constructor(e){super(e);C(this,"acceptDragLayer",he.Entity);C(this,"_entityManager");C(this,"_contentQueue",new vt);C(this,"prefabFile",null);C(this,"dependentAssets",[]);C(this,"_skipInitUpdateContent",!1);this._entityManager=new it(e)}static async createByEntity(e){var t,n,s;if(e.isPrefabSubEntity||e.isGLTFSubEntity){st.error(J("prefab.error.create-from-sub"));return}ge()&&rt();try{Me.info("createByEntity START",{entityName:e.name,entityId:e.id,isGLTFWrap:e.isGLTFWrapEntity,childCount:(t=e.children)==null?void 0:t.length,childNames:(n=e.children)==null?void 0:n.map(i=>i.name),hasGLTFChild:(s=e.children)==null?void 0:s.some(i=>i.isGLTFRefEntity)});const{assetFacade:o}=e.root;await e.root.runInUndoGroup("asset.create",async()=>{const i=await o.createAssetByAdd({assetType:"Prefab",name:e.name});await i.updateByEntity(e,!1,{undoable:!0,replaceInstances:!1}),i.addInstance(e,{undoable:!0}),i._bindInstantiatedEntity(e,{undoable:!0})})}finally{ge()&&ot()}}get entityManager(){return this._entityManager}get entities(){var e;return((e=this.prefabFile)==null?void 0:e.entities)??[]}async initByMain(e,t){const n=gn(this.meta.dependentAssets);if(this.url=t,this.prefabFile=ct(await e.text()),n?this.dependentAssets=n:this._syncDependentAssetsFromPrefabFile(),this._skipInitUpdateContent){this._skipInitUpdateContent=!1;return}await this._updateContent()}async initByCreation(){return this.prefabFile=en,this._skipInitUpdateContent=!0,this.getMainData()}getMainData(){return at(this._requirePrefabSourceFile("serializing prefab main data"))}async updateByEntity(e,t=!1,n){Me.info("updateByEntity START",{entityName:e.name,entityId:e.id,isGLTFWrap:e.isGLTFWrapEntity,updateInstanceFrom:t});const s=this._serializeRootEntityTreeForSource(e),o=s.entities;if(o[0]){delete o[0].position;const i=o[0].instance?this._resolveNestedInstanceRootOverrideTarget(e):void 0;dt(o[0],i)}this.prefabFile={asset:{version:"2.0"},root:s.entityIds[0],entities:o,components:s.components},this._syncDependentAssetsFromPrefabFile(),this._updateCreateByAddResumeSnapshot(),t&&this.addInstance(e),await this._updateContent({...n!=null&&n.undoable?{undoable:!0}:{},...(n==null?void 0:n.replaceInstances)===!1?{replaceInstances:!1}:{}})}async refreshFromData(e){await this._updateContent(e)}async _editPrefabSource(e,t){await new In({readSourceFile:()=>this.prefabFile,writeSourceFile:n=>{this.prefabFile=n},syncDependentAssets:()=>this._syncDependentAssetsFromPrefabFile(),updateCreateByAddResumeSnapshot:()=>this._updateCreateByAddResumeSnapshot(),refreshContent:n=>this._updateContent(n)}).apply(e,t)}async applyEntityPropsOverride(e,t,n){await this._editPrefabSource(s=>Ft(s,e,t),n)}async applyComponentPropsOverride(e,t,n){const s=t?this._componentPropsOverrideToSourcePatch(e,t):void 0;await this._editPrefabSource(o=>kt(o,e,s),n)}async applyAddedEntityOverride(e,t,n,s){const o=this._serializeEntityTreeForSource(n),i=this._resolveSourceChildInsertionIndex(e,t,n);await this._editPrefabSource(c=>Wt(c,{parentSourceEntityId:e,index:i,entities:o.entities,entityIds:o.entityIds,components:o.components,componentIds:o.componentIds}),{...s,structuralDeltaMode:"domain-source-replace"})}async applyNestedInstanceAddedEntityOverride(e,t,n,s,o){const i=this._serializeEntityInlineForSource(s);await this._editPrefabSource(c=>Ht(c,{instanceSourceEntityId:e,parentSourceEntityId:t,index:n,entity:i}),{...o,structuralDeltaMode:"domain-source-replace"})}async applyRemovedEntityOverride(e,t){await this._editPrefabSource(n=>Qt(n,e),{...t,structuralDeltaMode:"domain-source-replace"})}async applyAddedComponentOverride(e,t,n,s){await this._editPrefabSource(o=>Yt(o,{sourceEntityId:e,sourceComponentId:t,component:this._componentSchemaToSourceRefs(n)}),{...s,structuralDeltaMode:"domain-source-replace"})}async applyRemovedComponentOverride(e,t){await this._editPrefabSource(n=>Xt(n,e),{...t,structuralDeltaMode:"domain-source-replace"})}replaceDependentAsset(e,t){this.prefabFile=rn(this.prefabFile,e,t.id),e.id=t.id,e.name=t.name,e.type=t.getMetaConfig().type,this._updateContent()}_createSourceSerializeContext(e=[]){var n,s;const t=(s=(n=this.root.domainStore)==null?void 0:n.getNormalizedState)==null?void 0:s.call(n);return new ut(e,o=>{var c;const i=(c=t==null?void 0:t.components)==null?void 0:c[o];if(i)return{refId:i.refId,scriptKey:i.scriptKey,calls:i.calls}})}_createSourceRefCodec(){const e=this.root.assetStore;return ft({resolveAssetKind:t=>{var s,o,i,c;const n=(c=(i=(o=(s=e.assets)==null?void 0:s[t])==null?void 0:o.getMetaConfig)==null?void 0:i.call(o))==null?void 0:c.type;return n==="Prefab"||n==="glTF"?n:void 0}})}_convertDomainRefsToSourceRefs(e){return this._createSourceSerializeContext().convertRefs(e)}_convertSourceRefsToDomainRefs(e){return lt(e)}_componentSchemaToSourceRefs(e){var s,o;const t=this._createSourceSerializeContext(),n=structuredClone(e);return(s=n.script)!=null&&s.$ref&&(n.script={$ref:this._componentScriptRefToSourceRef(n.script.$ref),...n.script.key?{key:n.script.key}:{}}),n.props&&(n.props=t.convertRefs(n.props)),(o=n.calls)!=null&&o.length&&(n.calls=t.convertRefs(n.calls)),n}_componentScriptRefToSourceRef(e){return this._createSourceRefCodec().domainToSource(e,"prefab script")}_findSourceComponentModel(e){var n,s;const t=[...((n=this._entityManager)==null?void 0:n.rootEntities)??[]];for(;t.length>0;){const o=t.pop(),i=(s=o==null?void 0:o.components)==null?void 0:s.find(c=>(c==null?void 0:c.id)===e);if(i)return i;t.push(...(o==null?void 0:o.children)??[])}}_componentPropsOverrideToSourcePatch(e,t){const n=this._findSourceComponentModel(e);if(!n||typeof n.toJSON!="function")return this._convertDomainRefsToSourceRefs(t);const s=c=>this._componentSchemaToSourceRefs(c.toJSON()),o=ht(n,s),i=pt(n,t,s);return mt(o,i)}_serializeEntityTreeForSource(e,t={}){const n=t.materializeRootPrefabInstance?null:this._serializeNestedInstanceRootEntityForSource(e);if(n)return{entities:[n],entityIds:[e.id],components:[],componentIds:[]};const s=this._collectEntitySubtree(e,{materializeRootPrefabInstance:t.materializeRootPrefabInstance}),o=s.map(c=>c.id),i=this._createSourceSerializeContext(o);return{entities:s.map((c,a)=>a===0&&t.materializeRootPrefabInstance?c.toV2(i,!0):this._serializeNestedInstanceRootEntityForSource(c)??c.toV2(i,!0)),entityIds:i.entityIds,components:i.components,componentIds:i.componentIds}}_serializeRootEntityTreeForSource(e){const t=this._serializeNestedInstanceRootInlineForSource(e);return t?{entities:[t],entityIds:[e.id],components:[],componentIds:[]}:this._serializeEntityTreeForSource(e)}_sourceEntityTreeToInlineEntity(e,t=0){const n=e.entities[t];if(!n)throw new Error(`Prefab source added entity tree is missing entity index ${t}`);const{children:s,components:o,...i}=n,c=structuredClone(i),a=new Map(e.components.map(u=>[u.id,u]));o!=null&&o.length&&(c.components=o.map(u=>{const l=a.get(u);if(!l)throw new Error(`Prefab source added entity tree is missing component "${String(u)}"`);return structuredClone(l)}));const d=new Map(e.entities.map((u,l)=>[u.id,l]));return s!=null&&s.length&&(c.children=s.map(u=>{const l=d.get(u);if(l===void 0)throw new Error(`Prefab source added entity tree is missing child "${String(u)}"`);return this._sourceEntityTreeToInlineEntity(e,l)})),c}_serializeEntityInlineForSource(e){const t=this._serializeNestedInstanceRootInlineForSource(e);return t||this._sourceEntityTreeToInlineEntity(this._serializeEntityTreeForSource(e))}_serializeNestedInstanceRootEntityForSource(e){const t=this._resolveNestedInstanceAssetRef(e);if(!t)return null;const n=this._serializeNestedInstanceRootFromEntityModel(e,t);if(n)return n;const s={id:e.id,instance:{asset:t}};return this._mergeEntitySourcePropsIntoInstanceOverrides(s,e),s}_serializeNestedInstanceRootInlineForSource(e){const t=this._serializeNestedInstanceRootEntityForSource(e);if(!t)return null;const{children:n,components:s,...o}=t;return o}_serializeNestedInstanceRootFromEntityModel(e,t){if(typeof e.toV2!="function")return null;const n=this._createSourceSerializeContext([e.id]),s=e.toV2(n,!1);if(!s.instance)return null;const{children:o,components:i,...c}=structuredClone(s);return c.instance={...c.instance,asset:{...c.instance.asset??{},$ref:t.$ref}},this._mergeEntitySourcePropsIntoInstanceOverrides(c,e),c}_mergeEntitySourcePropsIntoInstanceOverrides(e,t){if(!e.instance)return;const n={};if(this._writeEntitySourceProps(n,t),Object.keys(n).length===0)return;const s=e.instance.overrides??{},o=[...s.entityProps??[]],i=this._resolveNestedInstanceRootOverrideTarget(t),c=o.findIndex(a=>a.target===i);if(c>=0){const a=o[c];o[c]={...n,...a,target:i}}else o.unshift({target:i,...n});e.instance.overrides={...s,entityProps:o}}_resolveNestedInstanceRootOverrideTarget(e){var s,o;const t=this._findInstanceRootBinding(e.id);if(t!=null&&t.sourceRootEntityId)return t.sourceRootEntityId;if(((t==null?void 0:t.assetKind)??((o=(s=this._resolveNestedInstanceAsset(e))==null?void 0:s.getMetaConfig)==null?void 0:o.call(s).type))==="glTF")return"root";throw new Error(`Cannot serialize nested instance "${e.id}": missing source root entity id for instance overrides.`)}_resolveNestedInstanceAssetRef(e){var o;if(!this._isNestedInstanceRootForSource(e))return null;const t=this._resolveNestedInstanceAsset(e);if(!t)throw new Error(`Cannot serialize nested instance "${e.id}": source asset is not registered.`);const n=(o=t.getMetaConfig)==null?void 0:o.call(t).type;if(n!=="Prefab"&&n!=="glTF")throw new Error(`Cannot serialize nested instance "${e.id}": asset "${t.id}" is type "${n}".`);return{$ref:this._createSourceRefCodec().domainToSource(t.id,`nested instance "${e.id}"`)}}_isNestedInstanceRootForSource(e){var n;const t=this._findInstanceRootBinding(e.id);return(t==null?void 0:t.assetKind)==="Prefab"||(t==null?void 0:t.assetKind)==="glTF"?!0:!!(e.isGLTFRefEntity&&!((n=e.parentEntity)!=null&&n.isGLTFRefEntity))}_findInstanceRootBinding(e){var t,n,s;return Object.values(((s=(n=(t=this.root.domainStore)==null?void 0:t.state)==null?void 0:n.prefab)==null?void 0:s.bindings)??{}).find(o=>o.instanceRootEntityId===e)}_resolveNestedInstanceAsset(e){var s,o;const t=this._findInstanceRootBinding(e.id);if((t==null?void 0:t.assetKind)==="Prefab"||(t==null?void 0:t.assetKind)==="glTF")return(s=this.root.assetStore.assets)==null?void 0:s[t.assetId];const n=(o=e.engineObject)==null?void 0:o._templateResource;if(n)return this.root.assetStore.engineObjectToAssetMap.get(n)}_writeEntitySourceProps(e,t){t.name&&(e.name=t.name),t.isActive===!1&&(e.isActive=!1),t.isLocked&&(e.isLocked=!0);const n=t.layer,s=Array.isArray(n)?we(n):typeof n=="number"?n:0;s!==0&&(e.layer=s),this._writeEntityTransformTuples(e,t)}_writeEntityTransformTuples(e,t){const n=t.transform;if(!n)return;const s=(d,u)=>[Number((d==null?void 0:d.x)??u[0]),Number((d==null?void 0:d.y)??u[1]),Number((d==null?void 0:d.z)??u[2])],o=(d,u)=>d[0]===u[0]&&d[1]===u[1]&&d[2]===u[2],i=s(n.position,ue);o(i,ue)||(e.position=i);const c=s(n.rotation,fe);o(c,fe)||(e.rotation=c);const a=s(n.scale,le);o(a,le)||(e.scale=a)}destroy(){super.destroy(),this.engineObject&&(this.engineObject._root.destroy(),this.engineObject.destroy())}unpackAllInstances(){var n;const e=this.root.sceneStore,t=this._queryInstanceEntityIdsFromDomain();for(const s of t){const o=(n=e.getEntityModel)==null?void 0:n.call(e,s);o==null||o.unpackPrefab()}super.unpackAllInstances()}async instantiate(e,t,n){var m;const s=structuredClone(this.prefabFile),o=yt(s);if(typeof s.root!="string")throw new Error(`Prefab asset "${this.id}" source root must be a stable source entity id.`);const i=o.entityIndexById.get(s.root);if(i===void 0)throw new Error(`Prefab asset "${this.id}" source root "${s.root}" was not indexed.`);const c=s.entities[i];c&&wn(c,t);const a=this._assignSceneInstanceIds(s,i,n==null?void 0:n.expectedRootId),d=await e.hydrateSourceV2LocalEntities(s,{resolveAssetKind:h=>{var y,p,b,_;const f=(_=(b=(p=(y=this.root.assetStore.assets)==null?void 0:y[h])==null?void 0:p.getMetaConfig)==null?void 0:b.call(p))==null?void 0:_.type;return f==="Prefab"||f==="glTF"?f:void 0},resolveInstanceAssetDisplayName:h=>{var f,y;return(y=(f=this.root.assetStore.assets)==null?void 0:f[h])==null?void 0:y.name},resolvePrefabSourceFile:h=>{var y,p,b,_;const f=(p=(y=this.root.assetStore).getAsset)==null?void 0:p.call(y,h);return((_=(b=f==null?void 0:f.getMetaConfig)==null?void 0:b.call(f))==null?void 0:_.type)==="Prefab"?f.prefabFile:void 0},clearExisting:!1,registerDomain:(n==null?void 0:n.deferDomainBinding)!==!0,deferredInstanceBindings:(n==null?void 0:n.deferredInstanceBindings)??[]}),u=(m=s.entities[i])==null?void 0:m.id,l=(u?e.entities.get(u):void 0)??d[0];if(await this._ensureSourceEntityManagerReady(),l.convertToPrefabRefEntity(),(n==null?void 0:n.deferDomainBinding)!==!0&&e.isDomainScoped&&!this.root.domainStore.state.entities[l.id]&&e.registerEntityTreeInDomain(l,null),this.addInstance(l,n),n!=null&&n.deferDomainBinding){if(!n.deferredInstanceBindings)throw new Error(`PrefabAsset "${this.id}" cannot defer domain binding without a deferred binding queue.`);return n.deferredInstanceBindings.push(()=>this._bindInstantiatedEntity(l,{...n,...a})),l}return this._bindInstantiatedEntity(l,{...n,...a}),l}_assignSceneInstanceIds(e,t,n){const s=new Map;e.entities.forEach((i,c)=>{s.set(i.id,n&&c===t?n:_e())});const o=new Map;return e.components.forEach(i=>{o.set(i.id,_e())}),this._remapLocalHydrationIds(e,s,o),{sourceEntityIdBySceneId:De(s),sourceComponentKeyBySceneComponentId:De(o)}}_remapLocalHydrationIds(e,t,n){const s=o=>{if(Array.isArray(o))return o.map(a=>s(a));if(!o||typeof o!="object")return o;const i=o;if(typeof i.$entity=="string")return{$entity:t.get(i.$entity)??i.$entity};if(typeof i.$component=="string")return{$component:n.get(i.$component)??i.$component};const c={};for(const[a,d]of Object.entries(i))c[a]=s(d);return c};e.root=t.get(e.root)??e.root,e.entities=e.entities.map(o=>{var a,d;const i=o.id,c=structuredClone(o);return c.id=t.get(i)??i,(a=c.children)!=null&&a.length&&(c.children=c.children.map(u=>t.get(u)??u)),(d=c.components)!=null&&d.length&&(c.components=c.components.map(u=>n.get(u)??u)),c}),e.components=e.components.map(o=>{var c;const i=structuredClone(o);return i.id=n.get(o.id)??o.id,i.props&&(i.props=s(i.props)),(c=i.calls)!=null&&c.length&&(i.calls=s(i.calls)),i})}async _ensureSourceEntityManagerReady(){if(!this._entityManager.rootEntities[0]&&(await this._entityManager.init(this),!this._entityManager.rootEntities[0]))throw new Error(`PrefabAsset "${this.id}" has no source root entity after source initialization.`)}_updateCreateByAddResumeSnapshot(){const e=this.getMainData(),t=this.getMetaData(),n=this.name??"Prefab";if(typeof e!="string"||e.length===0)throw new Error(`[PrefabAsset] ${n} (${this.id}) cannot update create-by-add resume snapshot without serialized main data.`);const s=new Blob([e],{type:"application/json"});this.root.assetStore.updateCreateByAddResumeSnapshot(this.id,{assetName:n,serializedMeta:JSON.stringify(t),mainBlob:s})}_bindInstantiatedEntity(e,t){if(e.entityManager&&!e.entityManager.isDomainScoped)return;const n=this._entityManager.rootEntities[0];if(!n)return;const{prefab:s}=this.root.domainStore.state,o=s.byAssetId[this.id]??[],i=o.map(h=>s.bindings[h]).find(h=>(h==null?void 0:h.instanceRootEntityId)===e.id||(t==null?void 0:t.expectedBindingId)===(h==null?void 0:h.id)),c=i?new Set(Object.keys(i.overrides.removedEntities??{})):void 0,a=i?new Map(Object.entries(i.overrides.removedComponents??{}).map(([h,f])=>[h,new Set(Object.keys(f??{}))])):void 0,{entityMappings:d,componentMappings:u,sourceEntitySnapshots:l}=this._collectInstanceMappings(n,e,c!=null&&c.size||a!=null&&a.size?{...t,...c!=null&&c.size?{allowMissingSceneChildSourceIds:c}:{},...a!=null&&a.size?{allowMissingSceneComponentSourceKeys:a}:{}}:t);if(!d.length)return;for(const h of o){const f=s.bindings[h];if((f==null?void 0:f.instanceRootEntityId)===e.id||(t==null?void 0:t.expectedBindingId)===h){t!=null&&t.syncPreservedInstanceState&&this._syncPreservedInstanceStateFromSource(f,l),this.root.prefabFacade.updateBindingSourceBaseline({assetId:this.id,bindingId:h,instanceRootEntityId:e.id,sourceRevision:f.sourceRevision,entityMappings:d,componentMappings:u,sourceEntitySnapshots:l});return}}let m=1;for(const h of o){const f=s.bindings[h];f&&f.sourceRevision>m&&(m=f.sourceRevision)}this.root.prefabFacade.bindExistingInstance({assetId:this.id,instanceRootEntityId:e.id,sourceRevision:m,entityMappings:d,componentMappings:u,sourceEntitySnapshots:l,undoable:(t==null?void 0:t.undoable)===!0})}_syncPreservedInstanceStateFromSource(e,t){const n=this.root.domainStore.getNormalizedState(),s=[];for(const[o,i]of Object.entries(t)){const c=i.sceneEntityId??e.sourceToSceneEntity[o];if(!c)continue;const a=n.entities[c];if(!a)continue;const d=`/entities/${ne(c)}`,u=e.overrides.entityProps[o];(u==null?void 0:u.name)===void 0&&i.name!==void 0&&a.name!==i.name&&s.push({op:"replace",path:`${d}/name`,value:i.name}),(u==null?void 0:u.isActive)===void 0&&i.isActive!==void 0&&a.isActive!==i.isActive&&s.push({op:"replace",path:`${d}/isActive`,value:i.isActive}),(u==null?void 0:u.layer)===void 0&&(i.layer===void 0?a.layer!==void 0&&s.push({op:"remove",path:`${d}/layer`}):a.layer!==i.layer&&s.push({op:a.layer===void 0?"add":"replace",path:`${d}/layer`,value:i.layer}));const l=u==null?void 0:u.transform;for(const h of["position","rotation","scale"]){if((l==null?void 0:l[h])!==void 0)continue;const f=i.transform[h];Pe(a.transform[h],f)||s.push({op:"replace",path:`${d}/transform/${h}`,value:f})}const m=e.overrides.componentProps[o]??{};for(const[h,f]of Object.entries(i.components)){const y=f.sceneComponentId;if(!y)continue;const p=n.components[y];if(!p)continue;const b=`${d}/components/${ne(y)}`,_=m[h]??{},P=f.props??{};for(const[g,T]of Object.entries(P)){if(Object.prototype.hasOwnProperty.call(_,g))continue;const K=`${b}/props/${ne(g)}`;Pe(p.props[g],T)||s.push({op:Object.prototype.hasOwnProperty.call(p.props,g)?"replace":"add",path:K,value:T})}for(const g of Object.keys(p.props))Object.prototype.hasOwnProperty.call(P,g)||Object.prototype.hasOwnProperty.call(_,g)||s.push({op:"remove",path:`${b}/props/${ne(g)}`})}}this.root.domainStore.applySystem(s)}_collectInstanceMappings(e,t,n){var s,o,i;return Sn({assetId:this.id,prefabFile:this._requirePrefabSourceFile(),sourceRoot:e,sceneRoot:t,normalized:(i=(o=(s=this.root)==null?void 0:s.domainStore)==null?void 0:o.getNormalizedState)==null?void 0:i.call(o),sceneSourceEntityIds:n==null?void 0:n.sourceEntityIdBySceneId,sceneSourceComponentKeys:n==null?void 0:n.sourceComponentKeyBySceneComponentId,allowMissingSceneChildSourceIds:n==null?void 0:n.allowMissingSceneChildSourceIds,allowMissingSceneComponentSourceKeys:n==null?void 0:n.allowMissingSceneComponentSourceKeys,resolveInstanceAssetDisplayName:c=>{var a,d;return(d=(a=this.root.assetStore.assets)==null?void 0:a[c])==null?void 0:d.name},resolveInstanceAsset:(c,a)=>{var m,h,f;const d=(m=this.root.assetStore.assets)==null?void 0:m[c];if(!d)throw new Error(`Prefab source entity "${a}" references missing instance asset "${c}".`);const u=(f=(h=d.getMetaConfig)==null?void 0:h.call(d))==null?void 0:f.type;if(u!=="Prefab"&&u!=="glTF")throw new Error(`Prefab source entity "${a}" references unsupported instance asset "${c}" of type "${String(u)}".`);const l=d.prefabFile;return{id:d.id,kind:u,...u==="Prefab"&&typeof(l==null?void 0:l.root)=="string"?{sourceRootEntityId:l.root}:{}}},convertSourceRefsToDomainRefs:c=>this._convertSourceRefsToDomainRefs(c),collectComponentProps:(c,a)=>this._collectSnapshotComponentProps(c,a),combineLayers:c=>we(c)})}_requirePrefabSourceFile(e="using prefab source file"){const t=this.prefabFile;if(!t)throw new Error(`Prefab asset "${this.id}" has no source file while ${e}.`);if(!Array.isArray(t.entities))throw new Error(`Prefab asset "${this.id}" source file is missing entity anchors.`);return t}_resolveSourceChildInsertionIndex(e,t,n){var l,m,h;const s=this._requirePrefabSourceFile(),o=s.entities.findIndex(f=>f.id===e);if(o<0)return t;const i=new Set(((l=s.entities[o])==null?void 0:l.children)??[]);if(i.size===0)return 0;const c=((m=n.parentEntity)==null?void 0:m.children)??[],a=c.findIndex(f=>f.id===n.id),d=a>=0?a:Math.min(Math.max(t,0),c.length);let u=0;for(let f=0;f<d;f+=1){const y=(h=c[f])==null?void 0:h.instanceSourceEntityId;y&&i.has(y)&&(u+=1)}return Math.min(Math.max(u,0),i.size)}_collectSnapshotComponentProps(e,t){return e&&Reflect.ownKeys(St(e)).length>0?this._convertSourceRefsToDomainRefs(It(e)):this._convertSourceRefsToDomainRefs(structuredClone(t.props??{}))}async replaceInstance(e,t,n){var h,f,y,p;const s=t.entities.get(e);if(!s)return null;const o=(h=s==null?void 0:s.engineObject)==null?void 0:h.transform,i=o?{position:{x:o.position.x,y:o.position.y,z:o.position.z},rotation:{x:o.rotation.x,y:o.rotation.y,z:o.rotation.z},scale:{x:o.scale.x,y:o.scale.y,z:o.scale.z}}:void 0,c=(y=(f=s.root.domainStore.getNormalizedState().entities[e])==null?void 0:f.instance)==null?void 0:y.bindingId,a=[],d=await this.instantiate(t,n!=null&&n.resetRootTransform?void 0:i,{...n!=null&&n.undoable?{undoable:!0}:{},expectedBindingId:c,deferDomainBinding:!0,deferredInstanceBindings:a});d.convertToPrefabRefEntity();const u=((p=t.root)==null?void 0:p.domainStore)??s.root.domainStore,l=t.entities.get(e),m=u.getNormalizedState().entities[e];return!l||!(m!=null&&m.instance)?(d.destroy(),null):(t.isDomainScoped&&!u.state.entities[d.id]&&t.registerEntityTreeInDomain(d,null,void 0,{...i&&!(n!=null&&n.resetRootTransform)?{transform:i}:{},deferInstanceBinding:!0}),a.splice(0).forEach(b=>b()),n!=null&&n.structuralDeltaMode?t.replaceEntity(e,d,{structuralDeltaMode:n.structuralDeltaMode}):t.replaceEntity(e,d),d)}_refreshTrackedInstanceBindings(e){var s;const t=this.root.sceneStore,n=this._queryInstanceEntityIdsFromDomain();for(const o of n){const i=(s=t.getEntityModel)==null?void 0:s.call(t,o);i&&this._bindInstantiatedEntity(i,e)}}_instantiateEngineObject(){return this.engineObject.instantiate()}_onDrop(e,t){if(!t||t.id===this.id)return;this.dropping=!1;const{sceneStore:n,sceneUIStore:s}=this.root,o=Array.from(s.selectedKeys);if(o.length>1)for(let i=0;i<o.length;i++)N.createByEntity(n.getEntityModel(o[i]));else bt({title:J("prefab.replace.title").toString(),description:J("prefab.replace.description",{name:this.name}).toString(),confirmText:J("prefab.replace.confirm").toString(),onConfirm:()=>{const i=n.getEntityModel(o[0]);this.updateByEntity(i,!0)}})}_rebaseInstanceRevisions(){const{prefabFacade:e,domainStore:t}=this.root,n=t.state.prefab.byAssetId[this.id];if(!n||n.length===0)return;let s=0;for(const o of n){const i=t.state.prefab.bindings[o];i&&i.sourceRevision>s&&(s=i.sourceRevision)}e.updatePrefabContent(this.id,s+1)}_collectEntitySubtree(e,t={}){const n=[],s=(o,i=!1)=>{if(n.push(o),!(this._isNestedInstanceRootForSource(o)&&!(i&&t.materializeRootPrefabInstance)))for(const a of o.children)a.prefabEntityRemoved||s(a)};return s(e,!0),n}_collectDependentAssetsFromPrefabFile(){var n;const e=new Set,t=this.root.assetStore;for(const s of Et(this.prefabFile,{currentAssetId:this.id})){const o=(n=t.assets)==null?void 0:n[s];if(!o)throw new Error(`[SceneV2] Unable to resolve prefab asset ref "${s}" while collecting dependencies`);o.id!==this.id&&e.add(o)}return e}_syncDependentAssetsFromPrefabFile(){this.root.assetStore,this.dependentAssets=Array.from(this._collectDependentAssetsFromPrefabFile(),e=>({id:e.id,name:e.name,type:e.getMetaConfig().type}))}_updateContent(e){return this._contentQueue.enqueue(async()=>{try{await this._updateContentInternal(e)}catch(t){if(t instanceof Error&&t.message==="cancelled")return;throw M.error("_updateContent failed:",t),t}})}async _updateContentInternal(e){const{url:t,dependentAssets:n}=this,s=(e==null?void 0:e.persist)!==!1;await Promise.all(n.map(a=>this.root.assetStore.getAssetByRef({refId:a.id}))),await this._entityManager.init(this);const o=this.engineObject;if(o){this.root.assetStore.engineObjectToAssetMap.delete(o);try{o.destroy()}catch(a){M.warn("failed to destroy oldEngineObject:",a)}}const i=new gt(this.engine,t);this.bindEngineObject(i),this.root.assetStore.engineObjectToAssetMap.set(i,this);let c=this._entityManager.rootEntities[0];if(c||(c=this._entityManager.createEntity("prefab","defaultPrefab"),c.bindEngineObject(new Ce(this.engine,"prefab")),M.error(`The prefab which id is ${this.id} is broken, use default prefab instead.`)),c.engineObject||(M.warn("rootEntity engineObject is null, binding new Entity"),c.bindEngineObject(new Ce(this.engine,"prefab"))),this._markAsTemplate(c),i._root=c.engineObject,c.once("delete",()=>{M.error(`The prefab which id is ${this.id} is broken.`),this._updateContent().catch(a=>{M.error(`Failed to rebuild broken prefab which id is ${this.id}.`,a)})}),this._updateDragTempEntity(),this.updateThumbnail(),s&&(this.root.assetFacade.persistAssetMeta(this.id),this.root.assetFacade.persistAssetMain(this.id)),(e==null?void 0:e.replaceInstances)!==!1){const a=new Set((e==null?void 0:e.resetRootTransformBindingIds)??[]),d=e!=null&&e.undoable?{undoable:!0}:void 0,u=this.root.sceneStore,l=this._queryInstanceEntityIdsFromDomain();await Promise.all(l.map(m=>{var f,y;const h=(y=(f=this.root.domainStore.getNormalizedState().entities[m])==null?void 0:f.instance)==null?void 0:y.bindingId;return this.replaceInstance(m,u,{...d??{},resetRootTransform:h!==void 0&&a.has(h),...e!=null&&e.structuralDeltaMode?{structuralDeltaMode:e.structuralDeltaMode}:{}})}))}else{const a={...e!=null&&e.undoable?{undoable:!0}:{},syncPreservedInstanceState:!0};this._refreshTrackedInstanceBindings(a)}this._rebaseInstanceRevisions()}_markAsTemplate(e){const t=e.engineObject;if(!t){M.warn("_markAsTemplate: engineObject is null",{prefabId:this.id,entityModelId:e.id});return}const n=t;n._templateResource||n._markAsTemplate(this.engineObject),e.selfChildren.forEach(s=>{this._markAsTemplate(s)})}};Y([wt()],N.prototype,"prefabFile",2);Y([_t(),Pt],N.prototype,"dependentAssets",2);Y([Fe],N.prototype,"replaceDependentAsset",1);Y([Fe],N.prototype,"_onDrop",1);N=Y([Ct({type:"Prefab",label:J("asset.prefab.title"),extname:"prefab",dragLayer:he.Prefab,customInspector:Zt,viewer:tn,thumbnail:ae,async bundle(r){return{content:new Blob([r.content],{type:"application/json"})}}})],N);export{N as PrefabAsset};
|
|
1
|
+
var Le=Object.defineProperty;var Ve=(r,e,t)=>e in r?Le(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var C=(r,e,t)=>(Ve(r,typeof e!="symbol"?e+"":e,t),t);import{e0 as qe,e1 as Ie,e2 as Ue,aJ as be,aK as Je,aL as O,bC as Ge,q as he,aO as We,aw as He,e3 as Qe,C as Ye,bH as Xe,e4 as Ee,e5 as Ze,e6 as W,e7 as et,e8 as tt,e9 as nt,b_ as st,e as J,ea as ge,eb as rt,ec as ot,ed as it,ee as ct,ef as at,eg as dt,eh as ut,ei as ft,ej as lt,ek as ht,el as pt,em as mt,en as we,eo as yt,bY as _e,ep as ne,eq as Pe,er as St,es as It,et as bt,eu as Et,ev as gt,K as Ce,m as wt,aU as _t,x as Pt,aC as Fe,n as Ct,dN as Rt,ew as $t}from"./index-eeedc550.js";import{T as vt}from"./TaskQueue-05c94a4d.js";import{u as Re,I as At}from"./index-828538e1.js";import"./postmen-fe9eecc4.js";import{A as Tt}from"./AssetViewer-f505fb55.js";function A(r){return structuredClone(r)}function H(r,e){const t=r.entities.findIndex(n=>n.id===e);if(t<0)throw new Error(`Prefab source entity "${e}" not found`);return t}function ke(r,e){const t=r.components.findIndex(n=>n.id===e);if(t<0)throw new Error(`Prefab source component "${e}" not found`);return t}function oe(r,e,t){if(!t)return;const n=e==="scale"?[1,1,1]:[0,0,0],s=r[e]??n;r[e]=[t.x??s[0],t.y??s[1],t.z??s[2]]}function $e(r,e,t){const n=new Set(e),s=new Set;for(const o of t){if(s.has(o))throw new Error(`Prefab source ${r} id "${o}" is duplicated in the added source tree`);if(n.has(o))throw new Error(`Prefab source ${r} id "${o}" already exists`);s.add(o)}}function xt(r){return r.entities.map(e=>e.id)}function Ne(r){return r.components.map(e=>e.id)}function Ot(r){const e=new Set(r.entityIds),t=new Set(r.componentIds);return r.entities.map((n,s)=>{var c,a;const o=r.entityIds[s],i=structuredClone(n);return i.id=o,(c=i.children)!=null&&c.length&&(i.children=i.children.map(d=>{const u=typeof d=="number"?r.entityIds[d]:d;if(!e.has(u))throw new Error(`Prefab added source entity "${o}" child "${String(d)}" is outside added entity tree`);return u})),(a=i.components)!=null&&a.length&&(i.components=i.components.map(d=>{const u=typeof d=="number"?r.componentIds[d]:d;if(!t.has(u))throw new Error(`Prefab added source entity "${o}" component "${String(d)}" is outside added component list`);return u})),i})}function Mt(r){return r.components.map((e,t)=>({...structuredClone(e),id:r.componentIds[t]}))}function Dt(r,e){const t=new Map(r.entities.map(o=>[o.id,o])),n=new Set,s=o=>{if(n.has(o))return;n.add(o);const i=t.get(o);for(const c of(i==null?void 0:i.children)??[])s(c)};return s(e),n}function Ft(r,e,t){var o,i,c;if(!t)return A(r);const n=A(r),s=n.entities[H(n,e)];return t.name!==void 0&&(s.name=t.name),t.isActive!==void 0&&(t.isActive?delete s.isActive:s.isActive=!1),t.layer!==void 0&&(t.layer===0?delete s.layer:s.layer=t.layer),t.isLocked!==void 0&&(t.isLocked?s.isLocked=!0:delete s.isLocked),oe(s,"position",(o=t.transform)==null?void 0:o.position),oe(s,"rotation",(i=t.transform)==null?void 0:i.rotation),oe(s,"scale",(c=t.transform)==null?void 0:c.scale),n}function kt(r,e,t){if(!t||Object.keys(t).length===0)return A(r);const n=A(r),s=n.components[ke(n,e)];return s.props=qe(s.props??{},t),n}function Nt(r,e){if(e.entities.length===0||e.entities.length!==e.entityIds.length)throw new Error("Prefab added entity tree must include matching entities and entityIds");if(e.components.length!==e.componentIds.length)throw new Error("Prefab added entity tree must include matching components and componentIds");$e("entity",xt(r),e.entityIds),$e("component",Ne(r),e.componentIds);const t=A(r),n=t.entities[H(t,e.parentSourceEntityId)],s=Ot(e),o=Mt(e),i=e.entityIds[0];t.entities.push(...s),t.components.push(...o);const c=[...n.children??[]],a=Math.min(Math.max(e.index,0),c.length);return c.splice(a,0,i),n.children=c,t}function jt(r,e){var l;const t=A(r),n=t.entities[H(t,e.instanceSourceEntityId)];if(!n.instance)throw new Error(`Prefab source entity "${e.instanceSourceEntityId}" is not an instance entity`);const s=(l=n.instance).overrides??(l.overrides={}),o=[...s.addedEntities??[]],i=Math.max(0,e.index);let c=0,a=o.length;for(let m=0;m<o.length;m+=1)if(o[m].parent===e.parentSourceEntityId){if(c===i){a=m;break}c+=1,a=m+1}const d=structuredClone(e.entity),u=d.id??`${e.instanceSourceEntityId}:added:${o.length}`;return d.id=u,o.splice(a,0,{id:u,parent:e.parentSourceEntityId,entity:d}),s.addedEntities=o,t}function zt(r,e){if(r.root===e)throw new Error("Cannot remove prefab root entity from source");H(r,e);const t=Dt(r,e),n=new Set;for(const o of r.entities)if(t.has(o.id))for(const i of o.components??[])n.add(i);const s=A(r);return s.entities=s.entities.filter(o=>!t.has(o.id)).map(o=>{const i=structuredClone(o),c=(i.children??[]).filter(d=>!t.has(d)),a=(i.components??[]).filter(d=>!n.has(d));return c.length?i.children=c:delete i.children,a.length?i.components=a:delete i.components,i}),s.components=s.components.filter(o=>!n.has(o.id)),s}function Bt(r,e,t,n){if(Ne(r).includes(t))throw new Error(`Prefab source component id "${t}" already exists`);const s=A(r),o=s.entities[H(s,e)];return s.components.push({...structuredClone(n),id:t}),o.components=[...o.components??[],t],s}function Kt(r,e){ke(r,e);const t=A(r);return t.components=t.components.filter(n=>n.id!==e),t.entities=t.entities.map(n=>{const s=structuredClone(n),o=(s.components??[]).filter(i=>i!==e);return o.length?s.components=o:delete s.components,s}),t}function Lt(r){switch(r.kind){case"add-source-entity":if(r.sourceEntityIds.length===0)throw new Error("Prefab source edit add-source-entity requires at least one source entity id");return;case"remove-source-entity":if(!r.sourceEntityId)throw new Error("Prefab source edit remove-source-entity requires a source entity id");return;case"add-source-component":if(!r.sourceComponentId)throw new Error("Prefab source edit add-source-component requires a source component id");return;case"remove-source-component":if(!r.sourceComponentId)throw new Error("Prefab source edit remove-source-component requires a source component id");return;case"add-nested-instance-entity":if(!r.instanceSourceEntityId)throw new Error("Prefab source edit add-nested-instance-entity requires an instance source entity id");if(!r.parentSourceEntityId)throw new Error("Prefab source edit add-nested-instance-entity requires a parent source entity id");return}}function ve(r,e){return r.length===e.length&&r.every((t,n)=>t===e[n])}function G(r,e,t){const n=new Set(e);for(const s of t)if(!n.has(s))throw new Error(`Prefab source edit expected ${r} id "${s}" to exist`)}function se(r,e,t){const n=new Set(e);for(const s of t)if(n.has(s))throw new Error(`Prefab source edit expected ${r} id "${s}" to be removed`)}function D(r){return r.entities.map(e=>e.id)}function z(r){return r.components.map(e=>e.id)}function je(r,e){const t=r.entities.findIndex(n=>n.id===e);if(t<0)throw new Error(`Prefab source edit expected entity id "${e}" to exist`);return t}function Vt(r,e){var n;const t=je(r,e);if(!((n=r.entities[t])!=null&&n.instance))throw new Error(`Prefab source edit expected entity id "${e}" to be an instance entity`)}function Ae(r,e,t){var s,o,i;const n=je(r,e);return(((i=(o=(s=r.entities[n])==null?void 0:s.instance)==null?void 0:o.overrides)==null?void 0:i.addedEntities)??[]).filter(c=>c.parent===t).length}function F(r,e,t,n,s){if(r!=null){if(Array.isArray(r)){r.forEach((o,i)=>F(o,e,t,`${n}[${i}]`,s));return}if(Ue(r)){r.$component===e&&s.push({entityId:t,propPath:n});for(const[o,i]of Object.entries(r))F(i,e,t,`${n}.${o}`,s)}}}function ze(r,e,t,n,s){var o;F(r.props,e,t,`${n}.props`,s),(o=r.calls)==null||o.forEach((i,c)=>F(i,e,t,`${n}.calls[${c}]`,s))}function Be(r,e,t,n,s){var o,i,c;(o=r.components)==null||o.forEach((a,d)=>ze(a,e,t,`${n}.components[${d}]`,s)),(i=r.children)==null||i.forEach((a,d)=>Be(a,e,t,`${n}.children[${d}]`,s)),Ke((c=r.instance)==null?void 0:c.overrides,e,t,`${n}.instance.overrides`,s)}function Ke(r,e,t,n,s){var o,i,c;(o=r==null?void 0:r.componentProps)==null||o.forEach((a,d)=>F(a.props,e,t,`${n}.componentProps[${d}].props`,s)),(i=r==null?void 0:r.addedComponents)==null||i.forEach((a,d)=>ze(a.component,e,t,`${n}.addedComponents[${d}].component`,s)),(c=r==null?void 0:r.addedEntities)==null||c.forEach((a,d)=>Be(a.entity,e,t,`${n}.addedEntities[${d}].entity`,s))}function qt(r,e){var s,o;const t=[],n=new Map;for(const i of r.entities)for(const c of i.components??[])n.set(c,i.id);for(const i of r.components){if(i.id===e)continue;const c=n.get(i.id)??"<unowned>";F(i.props,e,c,`components.${i.id}.props`,t),(s=i.calls)==null||s.forEach((a,d)=>F(a,e,c,`components.${i.id}.calls[${d}]`,t))}for(const i of r.entities)Ke((o=i.instance)==null?void 0:o.overrides,e,i.id,`entities.${i.id}.instance.overrides`,t);return t}function Ut(r,e){const t=qt(r,e);if(t.length!==0)throw new Error(`Cannot remove component "${e}": it is referenced by $component bindings in ${t.map(n=>`entity "${n.entityId}" prop "${n.propPath}"`).join(", ")}. Remove the bindings first.`)}function Jt(r,e){switch(e.kind){case"add-source-entity":se("entity",D(r),e.sourceEntityIds);return;case"remove-source-entity":G("entity",D(r),[e.sourceEntityId]);return;case"add-source-component":se("component",z(r),[e.sourceComponentId]);return;case"remove-source-component":G("component",z(r),[e.sourceComponentId]),Ut(r,e.sourceComponentId);return;case"add-nested-instance-entity":G("entity",D(r),[e.instanceSourceEntityId]),Vt(r,e.instanceSourceEntityId);return}}function Gt(r,e,t){switch(t.kind){case"add-source-entity":G("entity",D(e),t.sourceEntityIds);return;case"remove-source-entity":se("entity",D(e),[t.sourceEntityId]);return;case"add-source-component":G("component",z(e),[t.sourceComponentId]);return;case"remove-source-component":se("component",z(e),[t.sourceComponentId]);return;case"add-nested-instance-entity":{if(!ve(D(r),D(e))||!ve(z(r),z(e)))throw new Error("Prefab source edit add-nested-instance-entity must not change source entity or component ids");const n=Ae(r,t.instanceSourceEntityId,t.parentSourceEntityId);if(Ae(e,t.instanceSourceEntityId,t.parentSourceEntityId)!==n+1)throw new Error(`Prefab source edit expected nested added entity count under "${t.parentSourceEntityId}" to increase by 1`);return}}}function Q(r){Lt(r.intent),Ie(r.prefabFile),Jt(r.prefabFile,r.intent);const e=r.mutation(r.prefabFile);return Ie(e),Gt(r.prefabFile,e,r.intent),e}function Wt(r,e){return Q({prefabFile:r,intent:{kind:"add-source-entity",sourceEntityIds:e.entityIds},mutation:t=>Nt(t,e)})}function Ht(r,e){return Q({prefabFile:r,intent:{kind:"add-nested-instance-entity",instanceSourceEntityId:e.instanceSourceEntityId,parentSourceEntityId:e.parentSourceEntityId},mutation:t=>jt(t,e)})}function Qt(r,e){return Q({prefabFile:r,intent:{kind:"remove-source-entity",sourceEntityId:e},mutation:t=>zt(t,e)})}function Yt(r,e){return Q({prefabFile:r,intent:{kind:"add-source-component",sourceComponentId:e.sourceComponentId},mutation:t=>Bt(t,e.sourceEntityId,e.sourceComponentId,e.component)})}function Xt(r,e){return Q({prefabFile:r,intent:{kind:"remove-source-component",sourceComponentId:e},mutation:t=>Kt(t,e)})}class ae{static update(e,t){!this.entity&&(this.entity=e.createChild("prefab"));const n=this.tempCloneEntity=t.instantiateEngineObject();this.entity.addChild(n)}static clear(){var e;(e=this.entity)==null||e.clearChildren(),this.tempCloneEntity&&this.tempCloneEntity.destroy(),this.tempCloneEntity=null}}C(ae,"entity"),C(ae,"tempCloneEntity");const Zt=be(({asset:r})=>{const{dependentAssets:e}=r,{configDataStore:t}=Re(),{t:n}=Je(),s=be(({dependentAssetInfo:o})=>{const{assetStore:i}=Re(),c=Object.values(i.assets).filter(u=>{const l=u.getMetaConfig().type,m=u.id===o.id,h=u.id===r.id,f=!m&&!h&&!u.isSubAsset;return o.type==="glTF"||o.type==="Prefab"?l==="glTF"||l==="Prefab"&&f:u.getMetaConfig().type===o.type&&f}),a=i.assets[o.id],d=a==null?void 0:a.name;return O.jsx(Ge,{dropLayer:he.Asset,placeholder:n("prefab.inspector.missed"),assets:c,onSelect:u=>{r.replaceDependentAsset(o,u)},onLocate:()=>{i.selectAsset(o.id)},value:d,asset:a})});return O.jsxs(O.Fragment,{children:[O.jsx(We,{title:n("prefab.inspector.basic-info"),defaultOpen:!0,children:t.isBuc&&O.jsx(He,{label:n("prefab.inspector.url")})}),O.jsx(Qe,{label:n("prefab.inspector.dependent-assets"),children:e.map((o,i)=>O.jsx(s,{dependentAssetInfo:o},`${o.id}-${i}`))})]})}),en={asset:{version:"2.0"},root:"defaultPrefab",entities:[{id:"defaultPrefab",name:"prefab"}],components:[]};class tn extends Tt{constructor(){super(...arguments);C(this,"_animators",[]);C(this,"_particles",[])}setViewAsset(t,n){const s=t.entityManager.rootEntities[0];this._entity=s.engineObject,n.addChild(this._entity),s.getComponentsIncludeChildren("Animator",this._animators).forEach(c=>{c.applyBoundPathChange("enabled",Ye.Toggle,c.enabled)}),this._entity.getComponentsIncludeChildren(Xe,this._particles).forEach(c=>{c.generator.stop(!1,Ee.StopEmittingAndClear),c.generator.main.simulationSpeed=1,c.generator.play()})}stopViewAsset(){super.stopViewAsset(),this._particles.forEach(t=>{t.generator.stop(!1,Ee.StopEmittingAndClear)})}}const nn=new Set(["$ref","refId"]);function de(r,e,t){if(Array.isArray(r))return r.map(o=>de(o,e,t));if(!r||typeof r!="object")return r;const n=r,s={};for(const[o,i]of Object.entries(n))s[o]=nn.has(o)&&i===e?t:de(i,e,t);return s}function sn(r,e,t){return de(r,e,t)}function rn(r,e,t){const n=Ze(t);if(typeof e.id!="string"||e.id.length===0)throw new Error(`[SceneV2] Unable to replace prefab asset ref "${e.id}": missing old asset id`);return sn(r,e.id,n)}function on(r,e){const t=e.entities.findIndex(n=>n.id===e.root);if(!e.entities[t])throw new Error(`Prefab asset "${r}" source root "${e.root}" was not found.`);return t}function k(r,e,t){const n=e.entities[t];if(!n)throw new Error(`Prefab asset "${r}" source entity at index "${t}" was not found.`);return n}function B(r,e,t){var s;const n=(s=e.entities[t])==null?void 0:s.id;if(!n)throw new Error(`Prefab asset "${r}" source entity at index "${t}" is missing a stable source id.`);return n}function cn(r,e,t){var s;const n=(s=e.components[t])==null?void 0:s.id;if(!n)throw new Error(`Prefab asset "${r}" source component at index "${t}" is missing a stable source id.`);return n}function Te(r,e,t){const n=k(r,e,t);if(W(n))return[];const s=(n.children??[]).map(o=>e.entities.findIndex(i=>i.id===o));for(const o of s)if(!e.entities[o])throw new Error(`Prefab asset "${r}" source child index "${o}" on entity "${t}" was not found.`);return s}function xe(r,e,t){const n=k(r,e,t);return W(n)?[]:(n.components??[]).map(s=>{const o=e.components.findIndex(c=>c.id===s),i=e.components[o];if(!i)throw new Error(`Prefab asset "${r}" source component "${s}" was not found.`);return{key:cn(r,e,o),type:i.type,schema:i}})}function Oe(r,e,t,n,s){var a,d;const o=B(r,e,t),i=n.find(u=>u.id===o&&!s.has(u.id));if(i)return i;const c=k(r,e,t);if(!W(c)&&!((d=(a=c.instance)==null?void 0:a.asset)!=null&&d.$ref))throw new Error(`Prefab source child "${o}" cannot be matched to a loaded source entity.`)}function an(r,e,t,n){const s=o=>!t.type||o.type===t.type;if(n){const o=r.find(i=>i.key===n&&!e.has(i.key)&&s(i));if(o)return o}if(t.id){const o=r.find(i=>i.key===t.id&&!e.has(i.key)&&s(i));if(o)return o}}function dn(r,e,t,n){const s=(e==null?void 0:e.components)??[],o=t==null?void 0:t.get(r.key);if(o){const c=s.find(a=>(a==null?void 0:a.id)===o&&!a.ignoreToJSON);if(c)return c}const i=s.find(c=>{var d;return!(c!=null&&c.id)||n.has(c.id)||c.ignoreToJSON||((d=c.instance)==null?void 0:d.sourceComponentKey)!==r.key?!1:!c.type||c.type===r.type});if(i)return i}function un(r){var a,d,u,l,m,h,f,y;const e=k(r.assetId,r.prefabFile,r.sourceIndex),t=B(r.assetId,r.prefabFile,r.sourceIndex),n=(d=(a=e==null?void 0:e.instance)==null?void 0:a.asset)==null?void 0:d.$ref;if(!n||!W(e))return!1;const s=((m=(l=(u=r.normalized)==null?void 0:u.entities)==null?void 0:l[r.sceneChild.id])==null?void 0:m.instance)??r.sceneChild.instance,o=s==null?void 0:s.bindingId,i=o?(y=(f=(h=r.normalized)==null?void 0:h.prefab)==null?void 0:f.bindings)==null?void 0:y[o]:void 0,c=r.resolveInstanceAsset(n,t);return c?i?i.instanceRootEntityId===r.sceneChild.id&&i.assetId===c.id&&i.assetKind===c.kind:(s==null?void 0:s.assetId)===c.id&&(s==null?void 0:s.assetKind)===c.kind&&(!(s!=null&&s.role)||s.role==="root"):!1}function fn(r){var s,o;const t=(o=(s=k(r.assetId,r.prefabFile,r.sourceIndex).instance)==null?void 0:s.asset)==null?void 0:o.$ref;if(typeof t!="string")return;const n=r.resolveInstanceAsset(t,r.sourceEntityId);if(!n)throw new Error(`Prefab source entity "${r.sourceEntityId}" references missing instance asset "${t}".`);if(n.kind!=="Prefab"&&n.kind!=="glTF")throw new Error(`Prefab source entity "${r.sourceEntityId}" references unsupported instance asset "${t}" of type "${String(n.kind)}".`);return n}function ln(r,e){var o,i,c,a;if(!(r!=null&&r.id))return;const t=((i=(o=e==null?void 0:e.entities)==null?void 0:o[r.id])==null?void 0:i.instance)??r.instance,n=t==null?void 0:t.bindingId,s=n?(a=(c=e==null?void 0:e.prefab)==null?void 0:c.bindings)==null?void 0:a[n]:void 0;return typeof(s==null?void 0:s.sourceRootEntityId)=="string"?s.sourceRootEntityId:void 0}function ie(r,e){return{x:Number((r==null?void 0:r.x)??e.x),y:Number((r==null?void 0:r.y)??e.y),z:Number((r==null?void 0:r.z)??e.z)}}function hn(r,e){const t=r==null?void 0:r.transform;return{position:t!=null&&t.position?ie(t.position,{x:0,y:0,z:0}):e.position,rotation:t!=null&&t.rotation?ie(t.rotation,{x:0,y:0,z:0}):e.rotation,scale:t!=null&&t.scale?ie(t.scale,{x:1,y:1,z:1}):e.scale}}function pn(r,e,t){const n=r==null?void 0:r.layer;return Array.isArray(n)?t?t(n):e:typeof n=="number"?n:e}function mn(r){var c,a,d,u,l,m;const e=(c=r.normalized)==null?void 0:c.components,t=(r.sceneComponentId?e==null?void 0:e[r.sceneComponentId]:void 0)??((a=r.component)!=null&&a.id?e==null?void 0:e[r.component.id]:void 0),n={},s=(t==null?void 0:t.refId)??(typeof((d=r.schema.script)==null?void 0:d.$ref)=="string"?nt(r.schema.script.$ref):void 0);s&&(n.refId=s);const o=(t==null?void 0:t.scriptKey)??((u=r.schema.script)==null?void 0:u.key);o&&(n.scriptKey=o);const i=(l=t==null?void 0:t.calls)!=null&&l.length?structuredClone(t.calls):(m=r.schema.calls)!=null&&m.length?r.convertSourceRefsToDomainRefs(structuredClone(r.schema.calls)):void 0;return i!=null&&i.length&&(n.calls=i),n}function yn(r){var e,t;return r.sceneEntityIdBySource.has(r.sourceEntityId)?((t=(e=r.allowMissingSceneComponentSourceKeys)==null?void 0:e.get(r.sourceEntityId))==null?void 0:t.has(r.sourceComponentKey))===!0:!0}function Sn(r){const{assetId:e,prefabFile:t,sourceRoot:n,sceneRoot:s,normalized:o}=r,i=[],c=[],a=new Map,d=new Map,u=on(e,t),l=y=>{var b,_;const p=((_=(b=o==null?void 0:o.entities)==null?void 0:b[y.id])==null?void 0:_.instance)??y.instance;return(p==null?void 0:p.role)==="added"},m=(y,p,b,_)=>{var q,ee,te,U;if(l(b))return;const P=B(e,t,y),g=k(e,t,y),T=W(g);i.push({sceneEntityId:b.id,sourceEntityId:P,role:_}),a.set(P,b.id);const K=xe(e,t,y),X=b.components??[],R=new Set;for(const I of X){if(!(I!=null&&I.id)||I.ignoreToJSON)continue;const S=((ee=(q=o==null?void 0:o.components)==null?void 0:q[I.id])==null?void 0:ee.instance)??I.instance;if((S==null?void 0:S.role)==="added")continue;const w=((te=r.sceneSourceComponentKeys)==null?void 0:te.get(I.id))??(S==null?void 0:S.sourceComponentKey),E=an(K,R,I,w);if(!E){if(!T)throw new Error(`Prefab asset "${e}" live scene component "${I.id}" on source entity "${P}" cannot be matched to a prefab source component.`);continue}R.add(E.key),c.push({sceneEntityId:b.id,sceneComponentId:I.id,sourceComponentKey:E.key});const $=d.get(P)??new Map;$.set(E.key,I.id),d.set(P,$)}const j=Te(e,t,y),Z=(p==null?void 0:p.children)??[],x=b.children??[],L=new Set,V=new Set;for(let I=0;I<j.length;I++){const S=j[I],w=B(e,t,S),E=Oe(e,t,S,Z,L);E!=null&&E.id&&L.add(E.id);const $=x.find(v=>{var me,ye,Se;if(V.has(v.id)||l(v))return!1;if(v.id===w||E!=null&&E.id&&v.id===E.id||un({assetId:e,prefabFile:t,sourceIndex:S,sceneChild:v,normalized:o,resolveInstanceAsset:r.resolveInstanceAsset}))return!0;const re=((ye=(me=o==null?void 0:o.entities)==null?void 0:me[v.id])==null?void 0:ye.instance)??v.instance,pe=((Se=r.sceneSourceEntityIds)==null?void 0:Se.get(v.id))??(re==null?void 0:re.sourceEntityId)??v.instanceSourceEntityId;return pe===w||(E==null?void 0:E.id)&&pe===E.id});if(!$){if((U=r.allowMissingSceneChildSourceIds)!=null&&U.has(w))continue;throw new Error(`Prefab asset "${e}" source child "${w}" cannot be matched to live scene child under source entity "${P}".`)}V.add($.id),m(S,E,$,"linked")}},h={},f=(y,p,b,_)=>{const P=k(e,t,y),g=B(e,t,y),T={},K=xe(e,t,y),X=new Set;K.forEach(I=>{var $;const S=dn(I,p,d.get(g),X);if(S!=null&&S.ignoreToJSON)return;S!=null&&S.id&&X.add(S.id);const w=typeof(S==null?void 0:S.toJSON)=="function"?S.toJSON():I.schema,E=($=d.get(g))==null?void 0:$.get(I.key);if(!E&&!yn({sourceEntityId:g,sourceComponentKey:I.key,sceneEntityIdBySource:a,allowMissingSceneComponentSourceKeys:r.allowMissingSceneComponentSourceKeys}))throw new Error(`Prefab asset "${e}" source component "${I.key}" on source entity "${g}" cannot be matched to live scene component.`);T[I.key]={sceneComponentId:E,type:w.type??(S==null?void 0:S.type),...mn({component:S,schema:w,sceneComponentId:E,normalized:o,convertSourceRefsToDomainRefs:r.convertSourceRefsToDomainRefs}),props:r.collectComponentProps(S,w)}});const R=fn({assetId:e,prefabFile:t,sourceIndex:y,sourceEntityId:g,resolveInstanceAsset:r.resolveInstanceAsset}),j=R==null?void 0:R.kind,Z=et({sourceEntity:P,fallbackSourceEntityId:g,instanceAssetKind:j,bindingSourceRootEntityId:ln(p,o)??(R==null?void 0:R.sourceRootEntityId)}),x=tt(P,g,{...typeof Z=="string"?{rootOverrideTarget:Z}:{},resolveInstanceAssetDisplayName:r.resolveInstanceAssetDisplayName}),L=pn(p,x.layer,r.combineLayers),V=(p==null?void 0:p.isLocked)??x.isLocked,q=Te(e,t,y),ee=q.map(I=>B(e,t,I));h[g]={sceneEntityId:a.get(g),parentSourceEntityId:b,childSourceEntityIds:ee,childIndex:_,...j?{instanceAssetKind:j}:{},name:(p==null?void 0:p.name)??x.name,isActive:(p==null?void 0:p.isActive)??x.isActive,...L!==void 0?{layer:L}:{},...V!==void 0?{isLocked:V}:{},transform:hn(p,x.transform),components:T};const te=(p==null?void 0:p.children)??[],U=new Set;q.forEach((I,S)=>{const w=Oe(e,t,I,te,U);w!=null&&w.id&&U.add(w.id),f(I,w,g,S)})};return m(u,n,s,"root"),f(u,n,null,0),{entityMappings:i,componentMappings:c,sourceEntitySnapshots:h}}class In{constructor(e){this.host=e}async apply(e,t){const n=this.host.readSourceFile(),s=e(n);try{if(this.host.writeSourceFile(s),this.host.syncDependentAssets(),this.host.updateCreateByAddResumeSnapshot(),(t==null?void 0:t.refresh)===!1)return;await this.host.refreshContent((t==null?void 0:t.structuralDeltaMode)==="domain-source-replace"?{structuralDeltaMode:"domain-source-replace"}:void 0)}catch(o){throw this.host.writeSourceFile(n),this.host.syncDependentAssets(),this.host.updateCreateByAddResumeSnapshot(),o}}}var bn=Object.defineProperty,En=Object.getOwnPropertyDescriptor,Y=(r,e,t,n)=>{for(var s=n>1?void 0:n?En(e,t):e,o=r.length-1,i;o>=0;o--)(i=r[o])&&(s=(n?i(e,t,s):i(s))||s);return n&&s&&bn(e,t,s),s};const M=Rt("PrefabAsset"),Me=new $t("PrefabAsset");function gn(r){if(!Array.isArray(r))return null;const e=new Set(["id","name","type"]),t=[];for(const n of r){if(!n||typeof n!="object")return null;const s=n;if(!Object.keys(s).every(o=>e.has(o))||typeof s.id!="string"||typeof s.name!="string"||typeof s.type!="string")return null;t.push({id:s.id,name:s.name,type:s.type})}return t}const ue=[0,0,0],fe=[0,0,0],le=[1,1,1];function De(r){const e=new Map;for(const[t,n]of r)e.set(n,t);return e}function ce(r,e,t){const n=r??e;return[(t==null?void 0:t.x)??n[0],(t==null?void 0:t.y)??n[1],(t==null?void 0:t.z)??n[2]]}function wn(r,e){e&&Object.assign(r,{...e.position?{position:ce(r.position,ue,e.position)}:{},...e.rotation?{rotation:ce(r.rotation,fe,e.rotation)}:{},...e.scale?{scale:ce(r.scale,le,e.scale)}:{}})}let N=class extends At{constructor(e){super(e);C(this,"acceptDragLayer",he.Entity);C(this,"_entityManager");C(this,"_contentQueue",new vt);C(this,"prefabFile",null);C(this,"dependentAssets",[]);C(this,"_skipInitUpdateContent",!1);this._entityManager=new it(e)}static async createByEntity(e){var t,n,s;if(e.isPrefabSubEntity||e.isGLTFSubEntity){st.error(J("prefab.error.create-from-sub"));return}ge()&&rt();try{Me.info("createByEntity START",{entityName:e.name,entityId:e.id,isGLTFWrap:e.isGLTFWrapEntity,childCount:(t=e.children)==null?void 0:t.length,childNames:(n=e.children)==null?void 0:n.map(i=>i.name),hasGLTFChild:(s=e.children)==null?void 0:s.some(i=>i.isGLTFRefEntity)});const{assetFacade:o}=e.root;await e.root.runInUndoGroup("asset.create",async()=>{const i=await o.createAssetByAdd({assetType:"Prefab",name:e.name});await i.updateByEntity(e,!1,{undoable:!0,replaceInstances:!1}),i.addInstance(e,{undoable:!0}),i._bindInstantiatedEntity(e,{undoable:!0})})}finally{ge()&&ot()}}get entityManager(){return this._entityManager}get entities(){var e;return((e=this.prefabFile)==null?void 0:e.entities)??[]}async initByMain(e,t){const n=gn(this.meta.dependentAssets);if(this.url=t,this.prefabFile=ct(await e.text()),n?this.dependentAssets=n:this._syncDependentAssetsFromPrefabFile(),this._skipInitUpdateContent){this._skipInitUpdateContent=!1;return}await this._updateContent()}async initByCreation(){return this.prefabFile=en,this._skipInitUpdateContent=!0,this.getMainData()}getMainData(){return at(this._requirePrefabSourceFile("serializing prefab main data"))}async updateByEntity(e,t=!1,n){Me.info("updateByEntity START",{entityName:e.name,entityId:e.id,isGLTFWrap:e.isGLTFWrapEntity,updateInstanceFrom:t});const s=this._serializeRootEntityTreeForSource(e),o=s.entities;if(o[0]){delete o[0].position;const i=o[0].instance?this._resolveNestedInstanceRootOverrideTarget(e):void 0;dt(o[0],i)}this.prefabFile={asset:{version:"2.0"},root:s.entityIds[0],entities:o,components:s.components},this._syncDependentAssetsFromPrefabFile(),this._updateCreateByAddResumeSnapshot(),t&&this.addInstance(e),await this._updateContent({...n!=null&&n.undoable?{undoable:!0}:{},...(n==null?void 0:n.replaceInstances)===!1?{replaceInstances:!1}:{}})}async refreshFromData(e){await this._updateContent(e)}async _editPrefabSource(e,t){await new In({readSourceFile:()=>this.prefabFile,writeSourceFile:n=>{this.prefabFile=n},syncDependentAssets:()=>this._syncDependentAssetsFromPrefabFile(),updateCreateByAddResumeSnapshot:()=>this._updateCreateByAddResumeSnapshot(),refreshContent:n=>this._updateContent(n)}).apply(e,t)}async applyEntityPropsOverride(e,t,n){await this._editPrefabSource(s=>Ft(s,e,t),n)}async applyComponentPropsOverride(e,t,n){const s=t?this._componentPropsOverrideToSourcePatch(e,t):void 0;await this._editPrefabSource(o=>kt(o,e,s),n)}async applyAddedEntityOverride(e,t,n,s){const o=this._serializeEntityTreeForSource(n),i=this._resolveSourceChildInsertionIndex(e,t,n);await this._editPrefabSource(c=>Wt(c,{parentSourceEntityId:e,index:i,entities:o.entities,entityIds:o.entityIds,components:o.components,componentIds:o.componentIds}),{...s,structuralDeltaMode:"domain-source-replace"})}async applyNestedInstanceAddedEntityOverride(e,t,n,s,o){const i=this._serializeEntityInlineForSource(s);await this._editPrefabSource(c=>Ht(c,{instanceSourceEntityId:e,parentSourceEntityId:t,index:n,entity:i}),{...o,structuralDeltaMode:"domain-source-replace"})}async applyRemovedEntityOverride(e,t){await this._editPrefabSource(n=>Qt(n,e),{...t,structuralDeltaMode:"domain-source-replace"})}async applyAddedComponentOverride(e,t,n,s){await this._editPrefabSource(o=>Yt(o,{sourceEntityId:e,sourceComponentId:t,component:this._componentSchemaToSourceRefs(n)}),{...s,structuralDeltaMode:"domain-source-replace"})}async applyRemovedComponentOverride(e,t){await this._editPrefabSource(n=>Xt(n,e),{...t,structuralDeltaMode:"domain-source-replace"})}replaceDependentAsset(e,t){this.prefabFile=rn(this.prefabFile,e,t.id),e.id=t.id,e.name=t.name,e.type=t.getMetaConfig().type,this._updateContent()}_createSourceSerializeContext(e=[]){var n,s;const t=(s=(n=this.root.domainStore)==null?void 0:n.getNormalizedState)==null?void 0:s.call(n);return new ut(e,o=>{var c;const i=(c=t==null?void 0:t.components)==null?void 0:c[o];if(i)return{refId:i.refId,scriptKey:i.scriptKey,calls:i.calls}})}_createSourceRefCodec(){const e=this.root.assetStore;return ft({resolveAssetKind:t=>{var s,o,i,c;const n=(c=(i=(o=(s=e.assets)==null?void 0:s[t])==null?void 0:o.getMetaConfig)==null?void 0:i.call(o))==null?void 0:c.type;return n==="Prefab"||n==="glTF"?n:void 0}})}_convertDomainRefsToSourceRefs(e){return this._createSourceSerializeContext().convertRefs(e)}_convertSourceRefsToDomainRefs(e){return lt(e)}_componentSchemaToSourceRefs(e){var s,o;const t=this._createSourceSerializeContext(),n=structuredClone(e);return(s=n.script)!=null&&s.$ref&&(n.script={$ref:this._componentScriptRefToSourceRef(n.script.$ref),...n.script.key?{key:n.script.key}:{}}),n.props&&(n.props=t.convertRefs(n.props)),(o=n.calls)!=null&&o.length&&(n.calls=t.convertRefs(n.calls)),n}_componentScriptRefToSourceRef(e){return this._createSourceRefCodec().domainToSource(e,"prefab script")}_findSourceComponentModel(e){var n,s;const t=[...((n=this._entityManager)==null?void 0:n.rootEntities)??[]];for(;t.length>0;){const o=t.pop(),i=(s=o==null?void 0:o.components)==null?void 0:s.find(c=>(c==null?void 0:c.id)===e);if(i)return i;t.push(...(o==null?void 0:o.children)??[])}}_componentPropsOverrideToSourcePatch(e,t){const n=this._findSourceComponentModel(e);if(!n||typeof n.toJSON!="function")return this._convertDomainRefsToSourceRefs(t);const s=c=>this._componentSchemaToSourceRefs(c.toJSON()),o=ht(n,s),i=pt(n,t,s);return mt(o,i)}_serializeEntityTreeForSource(e,t={}){const n=t.materializeRootPrefabInstance?null:this._serializeNestedInstanceRootEntityForSource(e);if(n)return{entities:[n],entityIds:[e.id],components:[],componentIds:[]};const s=this._collectEntitySubtree(e,{materializeRootPrefabInstance:t.materializeRootPrefabInstance}),o=s.map(c=>c.id),i=this._createSourceSerializeContext(o);return{entities:s.map((c,a)=>a===0&&t.materializeRootPrefabInstance?c.toV2(i,!0):this._serializeNestedInstanceRootEntityForSource(c)??c.toV2(i,!0)),entityIds:i.entityIds,components:i.components,componentIds:i.componentIds}}_serializeRootEntityTreeForSource(e){const t=this._serializeNestedInstanceRootInlineForSource(e);return t?{entities:[t],entityIds:[e.id],components:[],componentIds:[]}:this._serializeEntityTreeForSource(e)}_sourceEntityTreeToInlineEntity(e,t=0){const n=e.entities[t];if(!n)throw new Error(`Prefab source added entity tree is missing entity index ${t}`);const{children:s,components:o,...i}=n,c=structuredClone(i),a=new Map(e.components.map(u=>[u.id,u]));o!=null&&o.length&&(c.components=o.map(u=>{const l=a.get(u);if(!l)throw new Error(`Prefab source added entity tree is missing component "${String(u)}"`);return structuredClone(l)}));const d=new Map(e.entities.map((u,l)=>[u.id,l]));return s!=null&&s.length&&(c.children=s.map(u=>{const l=d.get(u);if(l===void 0)throw new Error(`Prefab source added entity tree is missing child "${String(u)}"`);return this._sourceEntityTreeToInlineEntity(e,l)})),c}_serializeEntityInlineForSource(e){const t=this._serializeNestedInstanceRootInlineForSource(e);return t||this._sourceEntityTreeToInlineEntity(this._serializeEntityTreeForSource(e))}_serializeNestedInstanceRootEntityForSource(e){const t=this._resolveNestedInstanceAssetRef(e);if(!t)return null;const n=this._serializeNestedInstanceRootFromEntityModel(e,t);if(n)return n;const s={id:e.id,instance:{asset:t}};return this._mergeEntitySourcePropsIntoInstanceOverrides(s,e),s}_serializeNestedInstanceRootInlineForSource(e){const t=this._serializeNestedInstanceRootEntityForSource(e);if(!t)return null;const{children:n,components:s,...o}=t;return o}_serializeNestedInstanceRootFromEntityModel(e,t){if(typeof e.toV2!="function")return null;const n=this._createSourceSerializeContext([e.id]),s=e.toV2(n,!1);if(!s.instance)return null;const{children:o,components:i,...c}=structuredClone(s);return c.instance={...c.instance,asset:{...c.instance.asset??{},$ref:t.$ref}},this._mergeEntitySourcePropsIntoInstanceOverrides(c,e),c}_mergeEntitySourcePropsIntoInstanceOverrides(e,t){if(!e.instance)return;const n={};if(this._writeEntitySourceProps(n,t),Object.keys(n).length===0)return;const s=e.instance.overrides??{},o=[...s.entityProps??[]],i=this._resolveNestedInstanceRootOverrideTarget(t),c=o.findIndex(a=>a.target===i);if(c>=0){const a=o[c];o[c]={...n,...a,target:i}}else o.unshift({target:i,...n});e.instance.overrides={...s,entityProps:o}}_resolveNestedInstanceRootOverrideTarget(e){var s,o;const t=this._findInstanceRootBinding(e.id);if(t!=null&&t.sourceRootEntityId)return t.sourceRootEntityId;if(((t==null?void 0:t.assetKind)??((o=(s=this._resolveNestedInstanceAsset(e))==null?void 0:s.getMetaConfig)==null?void 0:o.call(s).type))==="glTF")return"root";throw new Error(`Cannot serialize nested instance "${e.id}": missing source root entity id for instance overrides.`)}_resolveNestedInstanceAssetRef(e){var o;if(!this._isNestedInstanceRootForSource(e))return null;const t=this._resolveNestedInstanceAsset(e);if(!t)throw new Error(`Cannot serialize nested instance "${e.id}": source asset is not registered.`);const n=(o=t.getMetaConfig)==null?void 0:o.call(t).type;if(n!=="Prefab"&&n!=="glTF")throw new Error(`Cannot serialize nested instance "${e.id}": asset "${t.id}" is type "${n}".`);return{$ref:this._createSourceRefCodec().domainToSource(t.id,`nested instance "${e.id}"`)}}_isNestedInstanceRootForSource(e){var n;const t=this._findInstanceRootBinding(e.id);return(t==null?void 0:t.assetKind)==="Prefab"||(t==null?void 0:t.assetKind)==="glTF"?!0:!!(e.isGLTFRefEntity&&!((n=e.parentEntity)!=null&&n.isGLTFRefEntity))}_findInstanceRootBinding(e){var t,n,s;return Object.values(((s=(n=(t=this.root.domainStore)==null?void 0:t.state)==null?void 0:n.prefab)==null?void 0:s.bindings)??{}).find(o=>o.instanceRootEntityId===e)}_resolveNestedInstanceAsset(e){var s,o;const t=this._findInstanceRootBinding(e.id);if((t==null?void 0:t.assetKind)==="Prefab"||(t==null?void 0:t.assetKind)==="glTF")return(s=this.root.assetStore.assets)==null?void 0:s[t.assetId];const n=(o=e.engineObject)==null?void 0:o._templateResource;if(n)return this.root.assetStore.engineObjectToAssetMap.get(n)}_writeEntitySourceProps(e,t){t.name&&(e.name=t.name),t.isActive===!1&&(e.isActive=!1),t.isLocked&&(e.isLocked=!0);const n=t.layer,s=Array.isArray(n)?we(n):typeof n=="number"?n:0;s!==0&&(e.layer=s),this._writeEntityTransformTuples(e,t)}_writeEntityTransformTuples(e,t){const n=t.transform;if(!n)return;const s=(d,u)=>[Number((d==null?void 0:d.x)??u[0]),Number((d==null?void 0:d.y)??u[1]),Number((d==null?void 0:d.z)??u[2])],o=(d,u)=>d[0]===u[0]&&d[1]===u[1]&&d[2]===u[2],i=s(n.position,ue);o(i,ue)||(e.position=i);const c=s(n.rotation,fe);o(c,fe)||(e.rotation=c);const a=s(n.scale,le);o(a,le)||(e.scale=a)}destroy(){super.destroy(),this.engineObject&&(this.engineObject._root.destroy(),this.engineObject.destroy())}unpackAllInstances(){var n;const e=this.root.sceneStore,t=this._queryInstanceEntityIdsFromDomain();for(const s of t){const o=(n=e.getEntityModel)==null?void 0:n.call(e,s);o==null||o.unpackPrefab()}super.unpackAllInstances()}async instantiate(e,t,n){var m;const s=structuredClone(this.prefabFile),o=yt(s);if(typeof s.root!="string")throw new Error(`Prefab asset "${this.id}" source root must be a stable source entity id.`);const i=o.entityIndexById.get(s.root);if(i===void 0)throw new Error(`Prefab asset "${this.id}" source root "${s.root}" was not indexed.`);const c=s.entities[i];c&&wn(c,t);const a=this._assignSceneInstanceIds(s,i,n==null?void 0:n.expectedRootId),d=await e.hydrateSourceV2LocalEntities(s,{resolveAssetKind:h=>{var y,p,b,_;const f=(_=(b=(p=(y=this.root.assetStore.assets)==null?void 0:y[h])==null?void 0:p.getMetaConfig)==null?void 0:b.call(p))==null?void 0:_.type;return f==="Prefab"||f==="glTF"?f:void 0},resolveInstanceAssetDisplayName:h=>{var f,y;return(y=(f=this.root.assetStore.assets)==null?void 0:f[h])==null?void 0:y.name},resolvePrefabSourceFile:h=>{var y,p,b,_;const f=(p=(y=this.root.assetStore).getAsset)==null?void 0:p.call(y,h);return((_=(b=f==null?void 0:f.getMetaConfig)==null?void 0:b.call(f))==null?void 0:_.type)==="Prefab"?f.prefabFile:void 0},clearExisting:!1,registerDomain:(n==null?void 0:n.deferDomainBinding)!==!0,deferredInstanceBindings:(n==null?void 0:n.deferredInstanceBindings)??[]}),u=(m=s.entities[i])==null?void 0:m.id,l=(u?e.entities.get(u):void 0)??d[0];if(await this._ensureSourceEntityManagerReady(),l.convertToPrefabRefEntity(),(n==null?void 0:n.deferDomainBinding)!==!0&&e.isDomainScoped&&!this.root.domainStore.state.entities[l.id]&&e.registerEntityTreeInDomain(l,null),this.addInstance(l,n),n!=null&&n.deferDomainBinding){if(!n.deferredInstanceBindings)throw new Error(`PrefabAsset "${this.id}" cannot defer domain binding without a deferred binding queue.`);return n.deferredInstanceBindings.push(()=>this._bindInstantiatedEntity(l,{...n,...a})),l}return this._bindInstantiatedEntity(l,{...n,...a}),l}_assignSceneInstanceIds(e,t,n){const s=new Map;e.entities.forEach((i,c)=>{s.set(i.id,n&&c===t?n:_e())});const o=new Map;return e.components.forEach(i=>{o.set(i.id,_e())}),this._remapLocalHydrationIds(e,s,o),{sourceEntityIdBySceneId:De(s),sourceComponentKeyBySceneComponentId:De(o)}}_remapLocalHydrationIds(e,t,n){const s=o=>{if(Array.isArray(o))return o.map(a=>s(a));if(!o||typeof o!="object")return o;const i=o;if(typeof i.$entity=="string")return{$entity:t.get(i.$entity)??i.$entity};if(typeof i.$component=="string")return{$component:n.get(i.$component)??i.$component};const c={};for(const[a,d]of Object.entries(i))c[a]=s(d);return c};e.root=t.get(e.root)??e.root,e.entities=e.entities.map(o=>{var a,d;const i=o.id,c=structuredClone(o);return c.id=t.get(i)??i,(a=c.children)!=null&&a.length&&(c.children=c.children.map(u=>t.get(u)??u)),(d=c.components)!=null&&d.length&&(c.components=c.components.map(u=>n.get(u)??u)),c}),e.components=e.components.map(o=>{var c;const i=structuredClone(o);return i.id=n.get(o.id)??o.id,i.props&&(i.props=s(i.props)),(c=i.calls)!=null&&c.length&&(i.calls=s(i.calls)),i})}async _ensureSourceEntityManagerReady(){if(!this._entityManager.rootEntities[0]&&(await this._entityManager.init(this),!this._entityManager.rootEntities[0]))throw new Error(`PrefabAsset "${this.id}" has no source root entity after source initialization.`)}_updateCreateByAddResumeSnapshot(){const e=this.getMainData(),t=this.getMetaData(),n=this.name??"Prefab";if(typeof e!="string"||e.length===0)throw new Error(`[PrefabAsset] ${n} (${this.id}) cannot update create-by-add resume snapshot without serialized main data.`);const s=new Blob([e],{type:"application/json"});this.root.assetStore.updateCreateByAddResumeSnapshot(this.id,{assetName:n,serializedMeta:JSON.stringify(t),mainBlob:s})}_bindInstantiatedEntity(e,t){if(e.entityManager&&!e.entityManager.isDomainScoped)return;const n=this._entityManager.rootEntities[0];if(!n)return;const{prefab:s}=this.root.domainStore.state,o=s.byAssetId[this.id]??[],i=o.map(h=>s.bindings[h]).find(h=>(h==null?void 0:h.instanceRootEntityId)===e.id||(t==null?void 0:t.expectedBindingId)===(h==null?void 0:h.id)),c=i?new Set(Object.keys(i.overrides.removedEntities??{})):void 0,a=i?new Map(Object.entries(i.overrides.removedComponents??{}).map(([h,f])=>[h,new Set(Object.keys(f??{}))])):void 0,{entityMappings:d,componentMappings:u,sourceEntitySnapshots:l}=this._collectInstanceMappings(n,e,c!=null&&c.size||a!=null&&a.size?{...t,...c!=null&&c.size?{allowMissingSceneChildSourceIds:c}:{},...a!=null&&a.size?{allowMissingSceneComponentSourceKeys:a}:{}}:t);if(!d.length)return;for(const h of o){const f=s.bindings[h];if((f==null?void 0:f.instanceRootEntityId)===e.id||(t==null?void 0:t.expectedBindingId)===h){t!=null&&t.syncPreservedInstanceState&&this._syncPreservedInstanceStateFromSource(f,l),this.root.prefabFacade.updateBindingSourceBaseline({assetId:this.id,bindingId:h,instanceRootEntityId:e.id,sourceRevision:f.sourceRevision,entityMappings:d,componentMappings:u,sourceEntitySnapshots:l});return}}let m=1;for(const h of o){const f=s.bindings[h];f&&f.sourceRevision>m&&(m=f.sourceRevision)}this.root.prefabFacade.bindExistingInstance({assetId:this.id,instanceRootEntityId:e.id,sourceRevision:m,entityMappings:d,componentMappings:u,sourceEntitySnapshots:l,undoable:(t==null?void 0:t.undoable)===!0})}_syncPreservedInstanceStateFromSource(e,t){const n=this.root.domainStore.getNormalizedState(),s=[];for(const[o,i]of Object.entries(t)){const c=i.sceneEntityId??e.sourceToSceneEntity[o];if(!c)continue;const a=n.entities[c];if(!a)continue;const d=`/entities/${ne(c)}`,u=e.overrides.entityProps[o];(u==null?void 0:u.name)===void 0&&i.name!==void 0&&a.name!==i.name&&s.push({op:"replace",path:`${d}/name`,value:i.name}),(u==null?void 0:u.isActive)===void 0&&i.isActive!==void 0&&a.isActive!==i.isActive&&s.push({op:"replace",path:`${d}/isActive`,value:i.isActive}),(u==null?void 0:u.layer)===void 0&&(i.layer===void 0?a.layer!==void 0&&s.push({op:"remove",path:`${d}/layer`}):a.layer!==i.layer&&s.push({op:a.layer===void 0?"add":"replace",path:`${d}/layer`,value:i.layer}));const l=u==null?void 0:u.transform;for(const h of["position","rotation","scale"]){if((l==null?void 0:l[h])!==void 0)continue;const f=i.transform[h];Pe(a.transform[h],f)||s.push({op:"replace",path:`${d}/transform/${h}`,value:f})}const m=e.overrides.componentProps[o]??{};for(const[h,f]of Object.entries(i.components)){const y=f.sceneComponentId;if(!y)continue;const p=n.components[y];if(!p)continue;const b=`${d}/components/${ne(y)}`,_=m[h]??{},P=f.props??{};for(const[g,T]of Object.entries(P)){if(Object.prototype.hasOwnProperty.call(_,g))continue;const K=`${b}/props/${ne(g)}`;Pe(p.props[g],T)||s.push({op:Object.prototype.hasOwnProperty.call(p.props,g)?"replace":"add",path:K,value:T})}for(const g of Object.keys(p.props))Object.prototype.hasOwnProperty.call(P,g)||Object.prototype.hasOwnProperty.call(_,g)||s.push({op:"remove",path:`${b}/props/${ne(g)}`})}}this.root.domainStore.applySystem(s)}_collectInstanceMappings(e,t,n){var s,o,i;return Sn({assetId:this.id,prefabFile:this._requirePrefabSourceFile(),sourceRoot:e,sceneRoot:t,normalized:(i=(o=(s=this.root)==null?void 0:s.domainStore)==null?void 0:o.getNormalizedState)==null?void 0:i.call(o),sceneSourceEntityIds:n==null?void 0:n.sourceEntityIdBySceneId,sceneSourceComponentKeys:n==null?void 0:n.sourceComponentKeyBySceneComponentId,allowMissingSceneChildSourceIds:n==null?void 0:n.allowMissingSceneChildSourceIds,allowMissingSceneComponentSourceKeys:n==null?void 0:n.allowMissingSceneComponentSourceKeys,resolveInstanceAssetDisplayName:c=>{var a,d;return(d=(a=this.root.assetStore.assets)==null?void 0:a[c])==null?void 0:d.name},resolveInstanceAsset:(c,a)=>{var m,h,f;const d=(m=this.root.assetStore.assets)==null?void 0:m[c];if(!d)throw new Error(`Prefab source entity "${a}" references missing instance asset "${c}".`);const u=(f=(h=d.getMetaConfig)==null?void 0:h.call(d))==null?void 0:f.type;if(u!=="Prefab"&&u!=="glTF")throw new Error(`Prefab source entity "${a}" references unsupported instance asset "${c}" of type "${String(u)}".`);const l=d.prefabFile;return{id:d.id,kind:u,...u==="Prefab"&&typeof(l==null?void 0:l.root)=="string"?{sourceRootEntityId:l.root}:{}}},convertSourceRefsToDomainRefs:c=>this._convertSourceRefsToDomainRefs(c),collectComponentProps:(c,a)=>this._collectSnapshotComponentProps(c,a),combineLayers:c=>we(c)})}_requirePrefabSourceFile(e="using prefab source file"){const t=this.prefabFile;if(!t)throw new Error(`Prefab asset "${this.id}" has no source file while ${e}.`);if(!Array.isArray(t.entities))throw new Error(`Prefab asset "${this.id}" source file is missing entity anchors.`);return t}_resolveSourceChildInsertionIndex(e,t,n){var l,m,h;const s=this._requirePrefabSourceFile(),o=s.entities.findIndex(f=>f.id===e);if(o<0)return t;const i=new Set(((l=s.entities[o])==null?void 0:l.children)??[]);if(i.size===0)return 0;const c=((m=n.parentEntity)==null?void 0:m.children)??[],a=c.findIndex(f=>f.id===n.id),d=a>=0?a:Math.min(Math.max(t,0),c.length);let u=0;for(let f=0;f<d;f+=1){const y=(h=c[f])==null?void 0:h.instanceSourceEntityId;y&&i.has(y)&&(u+=1)}return Math.min(Math.max(u,0),i.size)}_collectSnapshotComponentProps(e,t){return e&&Reflect.ownKeys(St(e)).length>0?this._convertSourceRefsToDomainRefs(It(e)):this._convertSourceRefsToDomainRefs(structuredClone(t.props??{}))}async replaceInstance(e,t,n){var h,f,y,p;const s=t.entities.get(e);if(!s)return null;const o=(h=s==null?void 0:s.engineObject)==null?void 0:h.transform,i=o?{position:{x:o.position.x,y:o.position.y,z:o.position.z},rotation:{x:o.rotation.x,y:o.rotation.y,z:o.rotation.z},scale:{x:o.scale.x,y:o.scale.y,z:o.scale.z}}:void 0,c=(y=(f=s.root.domainStore.getNormalizedState().entities[e])==null?void 0:f.instance)==null?void 0:y.bindingId,a=[],d=await this.instantiate(t,n!=null&&n.resetRootTransform?void 0:i,{...n!=null&&n.undoable?{undoable:!0}:{},expectedBindingId:c,deferDomainBinding:!0,deferredInstanceBindings:a});d.convertToPrefabRefEntity();const u=((p=t.root)==null?void 0:p.domainStore)??s.root.domainStore,l=t.entities.get(e),m=u.getNormalizedState().entities[e];return!l||!(m!=null&&m.instance)?(d.destroy(),null):(t.isDomainScoped&&!u.state.entities[d.id]&&t.registerEntityTreeInDomain(d,null,void 0,{...i&&!(n!=null&&n.resetRootTransform)?{transform:i}:{},deferInstanceBinding:!0}),a.splice(0).forEach(b=>b()),n!=null&&n.structuralDeltaMode?t.replaceEntity(e,d,{structuralDeltaMode:n.structuralDeltaMode}):t.replaceEntity(e,d),d)}_refreshTrackedInstanceBindings(e){var s;const t=this.root.sceneStore,n=this._queryInstanceEntityIdsFromDomain();for(const o of n){const i=(s=t.getEntityModel)==null?void 0:s.call(t,o);i&&this._bindInstantiatedEntity(i,e)}}_instantiateEngineObject(){return this.engineObject.instantiate()}_onDrop(e,t){if(!t||t.id===this.id)return;this.dropping=!1;const{sceneStore:n,sceneUIStore:s}=this.root,o=Array.from(s.selectedKeys);if(o.length>1)for(let i=0;i<o.length;i++)N.createByEntity(n.getEntityModel(o[i]));else bt({title:J("prefab.replace.title").toString(),description:J("prefab.replace.description",{name:this.name}).toString(),confirmText:J("prefab.replace.confirm").toString(),onConfirm:()=>{const i=n.getEntityModel(o[0]);this.updateByEntity(i,!0)}})}_rebaseInstanceRevisions(){const{prefabFacade:e,domainStore:t}=this.root,n=t.state.prefab.byAssetId[this.id];if(!n||n.length===0)return;let s=0;for(const o of n){const i=t.state.prefab.bindings[o];i&&i.sourceRevision>s&&(s=i.sourceRevision)}e.updatePrefabContent(this.id,s+1)}_collectEntitySubtree(e,t={}){const n=[],s=(o,i=!1)=>{if(n.push(o),!(this._isNestedInstanceRootForSource(o)&&!(i&&t.materializeRootPrefabInstance)))for(const a of o.children)a.prefabEntityRemoved||s(a)};return s(e,!0),n}_collectDependentAssetsFromPrefabFile(){var n;const e=new Set,t=this.root.assetStore;for(const s of Et(this.prefabFile,{currentAssetId:this.id})){const o=(n=t.assets)==null?void 0:n[s];if(!o)throw new Error(`[SceneV2] Unable to resolve prefab asset ref "${s}" while collecting dependencies`);o.id!==this.id&&e.add(o)}return e}_syncDependentAssetsFromPrefabFile(){this.root.assetStore,this.dependentAssets=Array.from(this._collectDependentAssetsFromPrefabFile(),e=>({id:e.id,name:e.name,type:e.getMetaConfig().type}))}_updateContent(e){return this._contentQueue.enqueue(async()=>{try{await this._updateContentInternal(e)}catch(t){if(t instanceof Error&&t.message==="cancelled")return;throw M.error("_updateContent failed:",t),t}})}async _updateContentInternal(e){const{url:t,dependentAssets:n}=this,s=(e==null?void 0:e.persist)!==!1;await Promise.all(n.map(a=>this.root.assetStore.getAssetByRef({refId:a.id}))),await this._entityManager.init(this);const o=this.engineObject;if(o){this.root.assetStore.engineObjectToAssetMap.delete(o);try{o.destroy()}catch(a){M.warn("failed to destroy oldEngineObject:",a)}}const i=new gt(this.engine,t);this.bindEngineObject(i),this.root.assetStore.engineObjectToAssetMap.set(i,this);let c=this._entityManager.rootEntities[0];if(c||(c=this._entityManager.createEntity("prefab","defaultPrefab"),c.bindEngineObject(new Ce(this.engine,"prefab")),M.error(`The prefab which id is ${this.id} is broken, use default prefab instead.`)),c.engineObject||(M.warn("rootEntity engineObject is null, binding new Entity"),c.bindEngineObject(new Ce(this.engine,"prefab"))),this._markAsTemplate(c),i._root=c.engineObject,c.once("delete",()=>{M.error(`The prefab which id is ${this.id} is broken.`),this._updateContent().catch(a=>{M.error(`Failed to rebuild broken prefab which id is ${this.id}.`,a)})}),this._updateDragTempEntity(),this.updateThumbnail(),s&&(this.root.assetFacade.persistAssetMeta(this.id),this.root.assetFacade.persistAssetMain(this.id)),(e==null?void 0:e.replaceInstances)!==!1){const a=new Set((e==null?void 0:e.resetRootTransformBindingIds)??[]),d=e!=null&&e.undoable?{undoable:!0}:void 0,u=this.root.sceneStore,l=this._queryInstanceEntityIdsFromDomain();await Promise.all(l.map(m=>{var f,y;const h=(y=(f=this.root.domainStore.getNormalizedState().entities[m])==null?void 0:f.instance)==null?void 0:y.bindingId;return this.replaceInstance(m,u,{...d??{},resetRootTransform:h!==void 0&&a.has(h),...e!=null&&e.structuralDeltaMode?{structuralDeltaMode:e.structuralDeltaMode}:{}})}))}else{const a={...e!=null&&e.undoable?{undoable:!0}:{},syncPreservedInstanceState:!0};this._refreshTrackedInstanceBindings(a)}this._rebaseInstanceRevisions()}_markAsTemplate(e){const t=e.engineObject;if(!t){M.warn("_markAsTemplate: engineObject is null",{prefabId:this.id,entityModelId:e.id});return}const n=t;n._templateResource||n._markAsTemplate(this.engineObject),e.selfChildren.forEach(s=>{this._markAsTemplate(s)})}};Y([wt()],N.prototype,"prefabFile",2);Y([_t(),Pt],N.prototype,"dependentAssets",2);Y([Fe],N.prototype,"replaceDependentAsset",1);Y([Fe],N.prototype,"_onDrop",1);N=Y([Ct({type:"Prefab",label:J("asset.prefab.title"),extname:"prefab",dragLayer:he.Prefab,customInspector:Zt,viewer:tn,thumbnail:ae,async bundle(r){return{content:new Blob([r.content],{type:"application/json"})}}})],N);export{N as PrefabAsset};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var wt=Object.defineProperty;var Mt=(M,s,i)=>s in M?wt(M,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):M[s]=i;var A=(M,s,i)=>(Mt(M,typeof s!="symbol"?s+"":s,i),i);import{ai as rt,B as q,bv as Rt,a5 as ut,a6 as dt,a7 as mt,a9 as ft,a3 as G,bw as tt,a4 as et,bx as Pt,j as It,by as At,K as Ht,y as Vt,p as _,e as b,C as B,t as _t,m as N,n as Bt,o as Nt,q as Tt}from"./index-d497fb6d.js";import"./index-8a22fe59.js";import"./postmen-0413c689.js";import"./meshopt_simplifier.module-cd99529d.js";import{a as Dt}from"./bundlers-9b0d37fc.js";import{M as Et}from"./MeshThumbnail-9bbe01dc.js";const z=class z{static createSphere(s=.5,i=18){i=Math.max(2,Math.floor(i));const o=i+1,e=o*o,c=i*i,l=z._generateIndices(e,c*6),R=Math.PI,t=R*2,a=1/o,y=1/i,m=8,h=new Float32Array(e*m);for(let x=0;x<e;++x){const u=x%o,d=x*a|0,p=u*y,n=d*y,w=p*t,f=n*R,v=Math.sin(f),I=-s*Math.cos(w)*v,P=s*Math.cos(f),S=s*Math.sin(w)*v;let r=x*m;h[r++]=I,h[r++]=P,h[r++]=S,h[r++]=I,h[r++]=P,h[r++]=S,h[r++]=p,h[r++]=n}let C=0;for(let x=0;x<c;++x){const u=x%i,p=(x*y|0)*o+u,n=p+1,w=p+o,f=w+1;l[C++]=n,l[C++]=p,l[C++]=f,l[C++]=p,l[C++]=w,l[C++]=f}const g=new q;return g.min.set(-s,-s,-s),g.max.set(s,s,s),{indices:l,vertices:h,bounds:g}}static createCuboid(s=1,i=1,o=1){const e=s/2,c=i/2,l=o/2,R=8,t=new Float32Array(24*R);t[0]=-e,t[1]=c,t[2]=-l,t[6]=0,t[7]=0,t[8]=e,t[9]=c,t[10]=-l,t[14]=1,t[15]=0,t[16]=e,t[17]=c,t[18]=l,t[22]=1,t[23]=1,t[24]=-e,t[25]=c,t[26]=l,t[30]=0,t[31]=1;for(let m=0;m<4;m++){let h=R*m+3;t[h++]=0,t[h++]=1,t[h++]=0}t[32]=-e,t[33]=-c,t[34]=-l,t[38]=0,t[39]=1,t[40]=e,t[41]=-c,t[42]=-l,t[46]=1,t[47]=1,t[48]=e,t[49]=-c,t[50]=l,t[54]=1,t[55]=0,t[56]=-e,t[57]=-c,t[58]=l,t[62]=0,t[63]=0;for(let m=0;m<4;m++){let h=R*m+35;t[h++]=0,t[h++]=-1,t[h++]=0}t[64]=-e,t[65]=c,t[66]=-l,t[70]=0,t[71]=0,t[72]=-e,t[73]=c,t[74]=l,t[78]=1,t[79]=0,t[80]=-e,t[81]=-c,t[82]=l,t[86]=1,t[87]=1,t[88]=-e,t[89]=-c,t[90]=-l,t[94]=0,t[95]=1;for(let m=0;m<4;m++){let h=R*m+67;t[h++]=-1,t[h++]=0,t[h++]=0}t[96]=e,t[97]=c,t[98]=-l,t[102]=1,t[103]=0,t[104]=e,t[105]=c,t[106]=l,t[110]=0,t[111]=0,t[112]=e,t[113]=-c,t[114]=l,t[118]=0,t[119]=1,t[120]=e,t[121]=-c,t[122]=-l,t[126]=1,t[127]=1;for(let m=0;m<4;m++){let h=R*m+99;t[h++]=1,t[h++]=0,t[h++]=0}t[128]=-e,t[129]=c,t[130]=l,t[134]=0,t[135]=0,t[136]=e,t[137]=c,t[138]=l,t[142]=1,t[143]=0,t[144]=e,t[145]=-c,t[146]=l,t[150]=1,t[151]=1,t[152]=-e,t[153]=-c,t[154]=l,t[158]=0,t[159]=1;for(let m=0;m<4;m++){let h=R*m+131;t[h++]=0,t[h++]=0,t[h++]=1}t[160]=-e,t[161]=c,t[162]=-l,t[166]=1,t[167]=0,t[168]=e,t[169]=c,t[170]=-l,t[174]=0,t[175]=0,t[176]=e,t[177]=-c,t[178]=-l,t[182]=0,t[183]=1,t[184]=-e,t[185]=-c,t[186]=-l,t[190]=1,t[191]=1;for(let m=0;m<4;m++){let h=R*m+163;t[h++]=0,t[h++]=0,t[h++]=-1}const a=new Uint16Array(36);a[0]=0,a[1]=2,a[2]=1,a[3]=2,a[4]=0,a[5]=3,a[6]=4,a[7]=6,a[8]=7,a[9]=6,a[10]=4,a[11]=5,a[12]=8,a[13]=10,a[14]=9,a[15]=10,a[16]=8,a[17]=11,a[18]=12,a[19]=14,a[20]=15,a[21]=14,a[22]=12,a[23]=13,a[24]=16,a[25]=18,a[26]=17,a[27]=18,a[28]=16,a[29]=19,a[30]=20,a[31]=22,a[32]=23,a[33]=22,a[34]=20,a[35]=21;const y=new q;return y.min.set(-e,-c,-l),y.max.set(e,c,l),{vertices:t,bounds:y,indices:a}}static createPlane(s=1,i=1,o=1,e=1){o=Math.max(1,Math.floor(o)),e=Math.max(1,Math.floor(e));const c=o+1,l=e+1,R=s/2,t=i/2,a=s/o,y=i/e,m=c*l,h=e*o,C=z._generateIndices(m,h*6),g=1/c,x=1/o,u=1/e,d=8,p=new Float32Array(m*d);for(let f=0;f<m;++f){const v=f%c,I=f*g|0;let P=f*d;p[P++]=v*a-R,p[P++]=0,p[P++]=I*y-t,p[P++]=0,p[P++]=1,p[P++]=0,p[P++]=v*x,p[P++]=I*u}let n=0;for(let f=0;f<h;++f){const v=f%o,P=(f*x|0)*c+v,S=P+1,r=P+c,D=r+1;C[n++]=P,C[n++]=r,C[n++]=S,C[n++]=r,C[n++]=D,C[n++]=S}const w=new q;return w.min.set(-R,0,-t),w.max.set(R,0,t),{bounds:w,vertices:p,indices:C}}static createCylinder(s=.5,i=.5,o=2,e=20,c=1){e=Math.floor(e),c=Math.floor(c);const l=e+1,R=c+1,t=o*.5,a=o/c,y=l*R,m=e*c,h=e*2,C=y+2+h,g=z._generateIndices(C,m*6+h*3),x=1/l,u=1/e,d=1/c,p=8,n=new Float32Array(C*p);let w=0;const f=Math.PI,v=Math.PI*2,I=i-s,P=I/o,S=I/c;for(let F=0;F<y;++F){const Z=F%l,W=F*x|0,O=Z*u,J=W*d,$=f+O*v,nt=Math.sin($),pt=Math.cos($),ht=i-W*S,xt=ht*nt,vt=W*a-t,Ct=ht*pt;let L=F*p;n[L++]=xt,n[L++]=vt,n[L++]=Ct,n[L++]=nt,n[L++]=P,n[L++]=pt,n[L++]=O,n[L++]=1-J}for(let F=0;F<m;++F){const Z=F%e,O=(F*u|0)*l+Z,J=O+1,$=O+l,nt=$+1;g[w++]=J,g[w++]=$,g[w++]=O,g[w++]=J,g[w++]=nt,g[w++]=$}let r=y*p;n[r++]=0,n[r++]=-t,n[r++]=0,n[r++]=0,n[r++]=-1,n[r++]=0,n[r++]=.5,n[r++]=.5,n[r++]=0,n[r++]=t,n[r++]=0,n[r++]=0,n[r++]=1,n[r++]=0,n[r++]=.5,n[r++]=.5,r=(y+2)*p;const D=1/(s*2),j=1/(i*2),E=l*c;for(let F=0;F<e;++F){const Z=F*p;let W=n[Z],O=n[Z+2];n[r++]=W,n[r++]=-t,n[r++]=O,n[r++]=0,n[r++]=-1,n[r++]=0,n[r++]=W*j+.5,n[r++]=.5-O*j;const J=(F+E)*p;W=n[J],O=n[J+2],n[r++]=W,n[r++]=t,n[r++]=O,n[r++]=0,n[r++]=1,n[r++]=0,n[r++]=W*D+.5,n[r++]=.5-O*D}const Y=y+1,X=y+2,U=X+1;for(let F=0;F<e;++F){const Z=F*2,W=F===e-1?0:Z+2;g[w++]=y,g[w++]=X+W,g[w++]=X+Z,g[w++]=Y,g[w++]=U+Z,g[w++]=U+W}const Q=new q,K=Math.max(s,i);return Q.min.set(-K,-t,-K),Q.max.set(K,t,K),{bounds:Q,vertices:n,indices:g}}static createTorus(s=.5,i=.1,o=30,e=30,c=360){o=Math.floor(o),e=Math.floor(e);const l=(o+1)*(e+1),R=o*e,t=z._generateIndices(l,R*6),a=8,y=new Float32Array(l*a);c=c/180*Math.PI;let m=0;const h=z._tempVec30;for(let x=0;x<=o;x++)for(let u=0;u<=e;u++){const d=u/e*c,p=x/o*Math.PI*2,n=Math.cos(p),w=Math.sin(p),f=Math.cos(d),v=Math.sin(d),I=(s+i*n)*f,P=(s+i*n)*v,S=i*w;y[m++]=I,y[m++]=P,y[m++]=S;const r=s*f,D=s*v;h.set(I-r,P-D,S).normalize(),y[m++]=h.x,y[m++]=h.y,y[m++]=h.z,y[m++]=u/e,y[m++]=x/o}m=0;for(let x=1;x<=o;x++)for(let u=1;u<=e;u++){const d=(e+1)*x+u-1,p=(e+1)*(x-1)+u-1,n=(e+1)*(x-1)+u,w=(e+1)*x+u;t[m++]=d,t[m++]=p,t[m++]=w,t[m++]=p,t[m++]=n,t[m++]=w}const C=new q,g=s+i;return C.min.set(-g,-g,-i),C.max.set(g,g,i),{bounds:C,vertices:y,indices:t}}static createCone(s=.5,i=2,o=20,e=1){o=Math.floor(o),e=Math.floor(e);const c=o+1,l=e+1,R=i*.5,t=i/e,a=c*l,y=o*e,m=a+1+o,h=z._generateIndices(m,y*6+o*3),C=1/c,g=1/o,x=1/e,u=8,d=new Float32Array(m*8);let p=0;const n=Math.PI,w=Math.PI*2,f=s/i;for(let r=0;r<a;++r){const D=r%c,j=r*C|0,E=D*g,Y=j*x,X=n+E*w,U=Math.sin(X),Q=Math.cos(X),K=s-j*s,F=K*U,Z=j*t-R,W=K*Q;let O=r*u;d[O++]=F,d[O++]=Z,d[O++]=W,d[O++]=U,d[O++]=f,d[O++]=Q,d[O++]=E,d[O++]=1-Y}for(let r=0;r<y;++r){const D=r%o,E=(r*g|0)*c+D,Y=E+1,X=E+c,U=X+1;h[p++]=Y,h[p++]=X,h[p++]=E,h[p++]=Y,h[p++]=U,h[p++]=X}let v=a*u;d[v++]=0,d[v++]=-R,d[v++]=0,d[v++]=0,d[v++]=-1,d[v++]=0,d[v++]=.5,d[v++]=.5,v=(a+1)*u;const I=1/(s*2);for(let r=0;r<o;++r){const D=d[r*u],j=d[r*u+2];d[v++]=D,d[v++]=-R,d[v++]=j,d[v++]=0,d[v++]=-1,d[v++]=0,d[v++]=D*I+.5,d[v++]=.5-j*I}const P=a+1;for(let r=0;r<o;++r){const D=r,j=r===o-1?0:D+1;h[p++]=a,h[p++]=P+j,h[p++]=P+D}const S=new q;return S.min.set(-s,-R,-s),S.max.set(s,R,s),{bounds:S,vertices:d,indices:h}}static createCapsule(s=.5,i=2,o=6,e=1){o=Math.max(2,Math.floor(o)),e=Math.floor(e);const c=o+1,l=e+1,R=i*.5,t=i/e,a=c*l,y=o*e,m=c*c,h=o*o,C=a+2*m,g=z._generateIndices(C,(y+2*h)*6),x=1/c,u=1/o,d=1/e,p=Math.PI,n=Math.PI*2,w=8,f=new Float32Array(C*w);let v=0;for(let P=0;P<a;++P){const S=P%c,r=P*x|0,D=S*u,j=r*d,E=p+D*n,Y=Math.sin(E),X=Math.cos(E);let U=P*w;f[U++]=s*Y,f[U++]=r*t-R,f[U++]=s*X,f[U++]=Y,f[U++]=0,f[U++]=X,f[U++]=D,f[U++]=1-j}for(let P=0;P<y;++P){const S=P%o,D=(P*u|0)*c+S,j=D+1,E=D+c,Y=E+1;g[v++]=j,g[v++]=E,g[v++]=D,g[v++]=j,g[v++]=Y,g[v++]=E}z._createCapsuleCap(s,i,o,p,n,a,1,f,g,v),z._createCapsuleCap(s,i,o,p,-n,a+m,-1,f,g,v+6*h);const I=new q;return I.min.set(-s,-s-R,-s),I.max.set(s,s+R,s),{bounds:I,vertices:f,indices:g}}static _generateIndices(s,i){let o=null;return s>65535?o=new Uint32Array(i):o=new Uint16Array(i),o}static _createCapsuleCap(s,i,o,e,c,l,R,t,a,y){const m=o+1,h=i*.5*R,C=m*m,g=o*o,x=1/m,u=1/o,d=8;for(let p=0;p<C;++p){const n=p%m,w=p*x|0,f=n*u,v=w*u,I=e+f*c,P=v*Math.PI*.5,S=Math.sin(P),r=s*Math.sin(I)*S,D=s*Math.cos(P)*R+h,j=s*Math.cos(I)*S;let E=(p+l)*d;t[E++]=r,t[E++]=D,t[E++]=j,t[E++]=r,t[E++]=D-h,t[E++]=j,t[E++]=f,t[E++]=v}for(let p=0;p<g;++p){const n=p%o,f=(p*u|0)*m+n+l,v=f+1,I=f+m,P=I+1;a[y++]=v,a[y++]=f,a[y++]=P,a[y++]=f,a[y++]=I,a[y++]=P}}static createSubdivisionSurfaceSphereData(s=.5,i=3){i=Rt.clamp(Math.floor(i),1,6);const o=new Float32Array(3*(6*Math.pow(4,i)+2)),e=new Float32Array(24*Math.pow(4,i));this._subdiveCatmullClark(i,o,e);const c=o.length/3,l=e.length/4,R=c+Math.pow(2,i+1)-1,t=R+16,a=new Float32Array(t*8),y=this._generateIndices(c,l*6);let m=0;const h={};for(let x=0;x<c;x++){let u=3*x,d=o[u],p=o[u+1],n=o[u+2];const w=1/Math.sqrt(d*d+p*p+n*n);if(d*=w,p*=w,n*=w,u=8*x,a[u]=d*s,a[u+1]=p*s,a[u+2]=n*s,a[u+3]=d,a[u+4]=p,a[u+5]=n,a[u+6]=(Math.PI-Math.atan2(n,d))/(2*Math.PI),a[u+7]=Math.acos(p)/Math.PI,a[u+6]===0){const f=8*(c+m++);a.set(a.subarray(u,u+8),f),a[f+6]=1,h[u/8]=f/8}}let C=0;this._spherePoleIdx=0;for(let x=0;x<l;x++){const u=4*x;let d=e[u],p=e[u+1],n=e[u+2],w=e[u+3];const f=8*d,v=8*p,I=8*n,P=8*w;a[f+2]+a[v+2]+a[I+2]<0&&(a[f+6]===0&&(d=h[d]),a[v+6]===0&&(p=h[p]),a[I+6]===0&&(n=h[n]),a[P+6]===0&&(w=h[w])),y[C]=d,y[C+1]=p,y[C+2]=n,this._generateAndReplacePoleUV(y,a,C,R),y[C+3]=d,y[C+4]=n,y[C+5]=w,this._generateAndReplacePoleUV(y,a,C+3,R),C+=6}const g=new q;return g.min.set(-s,-s,-s),g.max.set(s,s,s),{indices:y,vertices:a,bounds:g}}static _generateAndReplacePoleUV(s,i,o,e){const c=i[8*s[o]+7];if(c===0||c===1){const l=8*s[o],R=8*(e+this._spherePoleIdx);i.set(i.subarray(l,l+8),R),i[R+6]=.5*(i[l+6]+i[8*s[o+1]+6]+i[8*s[o+2]+6]-.5),s[o]=e+this._spherePoleIdx++}}static _subdiveCatmullClark(s,i,o){const e=new Map,c=new Array;i.set(this._sphereSeedPositions),o.set(this._sphereSeedCells);for(let l=0;l<s;l++){const R=6*Math.pow(4,l),t=4*R+2;e.clear(),c.length=0;for(let C=0;C<R;C++){const g=c[C]={facePoint:new rt,adjacentEdges:new Array(4)};for(let x=0;x<4;x++){const u=3*o[4*C+x];g.facePoint.x+=.25*i[u],g.facePoint.y+=.25*i[u+1],g.facePoint.z+=.25*i[u+2]}for(let x=0;x<4;x++){const u=o[4*C+x],d=o[4*C+(x+1)%4],p=Math.min(u,d)*t+Math.max(u,d);if(!e.has(p)){const v={edgePoint:new rt,edgePointIndex:void 0},I=3*u,P=3*d;v.edgePoint.set(.25*(i[I]+i[P]),.25*(i[I+1]+i[P+1]),.25*(i[I+2]+i[P+2])),e.set(p,v)}const n=e.get(p);g.adjacentEdges[x]=n;const w=n.edgePoint,f=g.facePoint;w.x+=.25*f.x,w.y+=.25*f.y,w.z+=.25*f.z}}const a=R+2,y=a+R;let m=0;this._sphereEdgeIdx=0;const h=o.slice(0,4*R);for(let C=0;C<R;C++){const g=c[C];g.facePoint.copyToArray(i,3*(a+C));const x=a+C;let u,d,p;for(let n=0;n<4;n++){const w=h[m++];switch(n){case 0:{const v=g.adjacentEdges[n%4],I=g.adjacentEdges[(n+3)%4];d=this._calculateEdgeIndex(i,v,y),u=this._calculateEdgeIndex(i,I,y),p=u;break}case 1:case 2:{const v=g.adjacentEdges[n%4];u=d,d=this._calculateEdgeIndex(i,v,y);break}case 3:{u=d,d=p;break}}const f=4*(4*C+n);o[f]=w,o[f+1]=d,o[f+2]=x,o[f+3]=u}}}}static _calculateEdgeIndex(s,i,o){if(i.edgePointIndex!==void 0)return i.edgePointIndex;{i.edgePoint.copyToArray(s,3*(o+this._sphereEdgeIdx));const e=o+this._sphereEdgeIdx++;return i.edgePointIndex=e,e}}};A(z,"_tempVec30",new rt),A(z,"_sphereSeedPositions",new Float32Array([-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,1,-1,-1,-1,-1,-1,1,-1])),A(z,"_sphereSeedCells",new Float32Array([0,1,2,3,3,2,4,5,5,4,6,7,7,0,3,5,7,6,1,0,6,4,2,1])),A(z,"_sphereEdgeIdx",0),A(z,"_spherePoleIdx",0);let k=z;function Ft(){return[new G(tt.Position,0,et.Vector3,0),new G(tt.Normal,12,et.Vector3,0),new G(tt.UV,24,et.Vector2,0)]}function yt(M,s,{vertices:i,indices:o,bounds:e}){const c=new ut(s,dt.VertexBuffer,i,mt.Static),l=new ut(s,dt.IndexBuffer,o,mt.Static);M.setVertexElements(Ft()),M.setIndexBufferBinding(l,o instanceof Uint16Array?ft.UInt16:ft.UInt32),M.setVertexBufferBinding(c,32),M.bounds=e,M.subMesh?M.subMesh.count=o.length:M.addSubMesh(0,o.length)}class St extends Pt{constructor(s,i,o){super(s),this.engine=i,this.generateData=o}restoreContent(){yt(this.resource,this.engine,this.generateData())}}function Ot(M,s,i){s.resourceManager.addContentRestorer(new St(M,s,i))}var jt=Object.defineProperty,Ut=Object.getOwnPropertyDescriptor,V=(M,s,i,o)=>{for(var e=o>1?void 0:o?Ut(s,i):s,c=M.length-1,l;c>=0;c--)(l=M[c])&&(e=(o?l(s,i,e):l(e))||e);return o&&e&&jt(s,i,e),e},bt=(M=>(M.Sphere="sphere",M.Cuboid="cuboid",M.Plane="plane",M.Cylinder="cylinder",M.Torus="torus",M.Cone="cone",M.Capsule="capsule",M))(bt||{});const gt=M=>M.type==="sphere",it=M=>M.type==="capsule",at=M=>M.type==="cone",lt=M=>M.type==="cuboid",ot=M=>M.type==="cylinder",st=M=>M.type==="torus",ct=M=>M.type==="plane",T=M=>M._updateData();let H=class extends It{constructor(s){super(s);A(this,"type","sphere");A(this,"sphereRadius",.5);A(this,"sphereStep",3);A(this,"capsuleRadius",.5);A(this,"capsuleHeight",2);A(this,"capsuleRadialSegments",6);A(this,"capsuleHeightSegments",1);A(this,"coneRadius",.5);A(this,"coneHeight",2);A(this,"coneRadialSegment",20);A(this,"coneHeightSegment",1);A(this,"cuboidWidth",1);A(this,"cuboidHeight",1);A(this,"cuboidDepth",1);A(this,"cylinderRadiusTop",.5);A(this,"cylinderRadiusBottom",.5);A(this,"cylinderHeight",2);A(this,"cylinderRadialSegment",20);A(this,"cylinderHeightSegment",1);A(this,"planeWidth",1);A(this,"planeHeight",1);A(this,"planeHorizontalSegments",1);A(this,"planeVerticalSegments",1);A(this,"torusRadius",.5);A(this,"torusTubeRadius",.1);A(this,"torusRadialSegments",30);A(this,"torusTubularSegments",30);A(this,"torusArc",360)}async initByCreation(s,i,o){const c=(typeof(o==null?void 0:o.primitiveType)=="string"?o.primitiveType:"").trim().toLowerCase();return{type:{sphere:"sphere",cube:"cuboid",cuboid:"cuboid",cylinder:"cylinder",plane:"plane",capsule:"capsule",cone:"cone",torus:"torus"}[c]??"sphere"}}async initByMain(s,i){const o=JSON.parse(await s.text()),e=this.engine,c=o.type,l=new At(e,c);l.setVertexElements([new G(tt.Position,0,et.Vector3,0),new G(tt.Normal,12,et.Vector3,0),new G(tt.UV,24,et.Vector2,0)]);for(const y in o)this[y]=o[y];this.bindEngineObject(l),Ot(l,e,()=>this._generateDataByType(this.type)),this._updateData();const R=new Ht(e,c&&c.charAt(0).toUpperCase()+c.slice(1)),t=R.addComponent(Vt);t.mesh=this.engineObject;const a=await this.root.assetStore.getAssetByRef({refId:"0000200"});t.setMaterial(a.engineObject),this.setDragTempEntity(R)}instantiate(){const s=this.root.sceneStore.createEntity(),i=this.getDragTempEntity();return s.initByEngineObject(i.clone()),s}_updateData(){const s=this.engine,i=this._engineObject;yt(i,s,this._generateDataByType(this.type))}_generateDataByType(s){switch(s){case"sphere":return k.createSubdivisionSurfaceSphereData(this.sphereRadius,this.sphereStep);case"capsule":return k.createCapsule(this.capsuleRadius,this.capsuleHeight,this.capsuleRadialSegments,this.capsuleHeightSegments);case"cone":return k.createCone(this.coneRadius,this.coneHeight,this.coneRadialSegment,this.coneHeightSegment);case"cuboid":return k.createCuboid(this.cuboidWidth,this.cuboidHeight,this.cuboidDepth);case"cylinder":return k.createCylinder(this.cylinderRadiusTop,this.cylinderRadiusBottom,this.cylinderHeight,this.cylinderRadialSegment,this.cylinderHeightSegment);case"plane":return k.createPlane(this.planeWidth,this.planeHeight,this.planeHorizontalSegments,this.planeVerticalSegments);case"torus":return k.createTorus(this.torusRadius,this.torusTubeRadius,this.torusRadialSegments,this.torusTubularSegments,this.torusArc);default:return k.createSphere(this.sphereRadius,this.sphereStep)}}};V([_({label:b("asset.primitive-mesh.type.label"),info:b("asset.primitive-mesh.type.info"),type:B.Select,value:"sphere",options:_t(bt),onChange(M){M._updateData()}}),N()],H.prototype,"type",2);V([_({label:b("asset.primitive-mesh.sphere.radius.label"),info:b("asset.primitive-mesh.sphere.radius.info"),type:B.Number,min:0,dragStep:.1,when:gt,onChange:T}),N()],H.prototype,"sphereRadius",2);V([_({label:b("asset.primitive-mesh.sphere.step.label"),info:b("asset.primitive-mesh.sphere.step.info"),type:B.Number,min:1,dragStep:1,when:gt,onChange:T}),N()],H.prototype,"sphereStep",2);V([_({label:b("asset.primitive-mesh.capsule.radius.label"),info:b("asset.primitive-mesh.capsule.radius.info"),type:B.Number,min:0,dragStep:.1,when:it,onChange:T}),N()],H.prototype,"capsuleRadius",2);V([_({label:b("asset.primitive-mesh.capsule.height.label"),info:b("asset.primitive-mesh.capsule.height.info"),type:B.Number,min:0,dragStep:.1,when:it,onChange:T}),N()],H.prototype,"capsuleHeight",2);V([_({label:b("asset.primitive-mesh.capsule.radial-segments.label"),info:b("asset.primitive-mesh.capsule.radial-segments.info"),type:B.Number,min:1,dragStep:1,when:it,onChange:T}),N()],H.prototype,"capsuleRadialSegments",2);V([_({label:b("asset.primitive-mesh.capsule.height-segments.label"),info:b("asset.primitive-mesh.capsule.height-segments.info"),type:B.Number,min:1,dragStep:1,when:it,onChange:T}),N()],H.prototype,"capsuleHeightSegments",2);V([_({label:b("asset.primitive-mesh.cone.radius.label"),info:b("asset.primitive-mesh.cone.radius.info"),type:B.Number,min:0,dragStep:.1,when:at,onChange:T}),N()],H.prototype,"coneRadius",2);V([_({label:b("asset.primitive-mesh.cone.height.label"),info:b("asset.primitive-mesh.cone.height.info"),type:B.Number,min:0,dragStep:.1,when:at,onChange:T}),N()],H.prototype,"coneHeight",2);V([_({label:b("asset.primitive-mesh.cone.radial-segments.label"),info:b("asset.primitive-mesh.cone.radial-segments.info"),type:B.Number,min:1,dragStep:1,when:at,onChange:T}),N()],H.prototype,"coneRadialSegment",2);V([_({label:b("asset.primitive-mesh.cone.height-segments.label"),info:b("asset.primitive-mesh.cone.height-segments.info"),type:B.Number,min:1,dragStep:1,when:at,onChange:T}),N()],H.prototype,"coneHeightSegment",2);V([_({label:b("asset.primitive-mesh.cuboid.width.label"),info:b("asset.primitive-mesh.cuboid.width.info"),type:B.Number,min:0,dragStep:.1,when:lt,onChange:T}),N()],H.prototype,"cuboidWidth",2);V([_({label:b("asset.primitive-mesh.cuboid.height.label"),info:b("asset.primitive-mesh.cuboid.height.info"),type:B.Number,min:0,dragStep:.1,when:lt,onChange:T}),N()],H.prototype,"cuboidHeight",2);V([_({label:b("asset.primitive-mesh.cuboid.depth.label"),info:b("asset.primitive-mesh.cuboid.depth.info"),type:B.Number,min:0,dragStep:.1,when:lt,onChange:T}),N()],H.prototype,"cuboidDepth",2);V([_({label:b("asset.primitive-mesh.cylinder.radius-top.label"),info:b("asset.primitive-mesh.cylinder.radius-top.info"),type:B.Number,min:0,dragStep:.1,when:ot,onChange:T}),N()],H.prototype,"cylinderRadiusTop",2);V([_({label:b("asset.primitive-mesh.cylinder.radius-bottom.label"),info:b("asset.primitive-mesh.cylinder.radius-bottom.info"),type:B.Number,min:0,dragStep:.1,when:ot,onChange:T}),N()],H.prototype,"cylinderRadiusBottom",2);V([_({label:b("asset.primitive-mesh.cylinder.height.label"),info:b("asset.primitive-mesh.cylinder.height.info"),type:B.Number,min:0,dragStep:.1,when:ot,onChange:T}),N()],H.prototype,"cylinderHeight",2);V([_({label:b("asset.primitive-mesh.cylinder.radial-segments.label"),info:b("asset.primitive-mesh.cylinder.radial-segments.info"),type:B.Number,min:1,dragStep:1,when:ot,onChange:T}),N()],H.prototype,"cylinderRadialSegment",2);V([_({label:b("asset.primitive-mesh.cylinder.height-segments.label"),info:b("asset.primitive-mesh.cylinder.height-segments.info"),type:B.Number,min:1,dragStep:1,when:ot,onChange:T}),N()],H.prototype,"cylinderHeightSegment",2);V([_({label:b("asset.primitive-mesh.plane.width.label"),info:b("asset.primitive-mesh.plane.width.info"),type:B.Number,min:0,dragStep:.1,when:ct,onChange:T}),N()],H.prototype,"planeWidth",2);V([_({label:b("asset.primitive-mesh.plane.height.label"),info:b("asset.primitive-mesh.plane.height.info"),type:B.Number,min:0,dragStep:.1,when:ct,onChange:T}),N()],H.prototype,"planeHeight",2);V([_({label:b("asset.primitive-mesh.plane.horizontal-segments.label"),info:b("asset.primitive-mesh.plane.horizontal-segments.info"),type:B.Number,min:1,dragStep:1,when:ct,onChange:T}),N()],H.prototype,"planeHorizontalSegments",2);V([_({label:b("asset.primitive-mesh.plane.vertical-segments.label"),info:b("asset.primitive-mesh.plane.vertical-segments.info"),type:B.Number,min:1,dragStep:1,when:ct,onChange:T}),N()],H.prototype,"planeVerticalSegments",2);V([_({label:b("asset.primitive-mesh.torus.radius.label"),info:b("asset.primitive-mesh.torus.radius.info"),type:B.Number,min:0,dragStep:.1,when:st,onChange:T}),N()],H.prototype,"torusRadius",2);V([_({label:b("asset.primitive-mesh.torus.tube-radius.label"),info:b("asset.primitive-mesh.torus.tube-radius.info"),type:B.Number,min:0,dragStep:.1,when:st,onChange:T}),N()],H.prototype,"torusTubeRadius",2);V([_({label:b("asset.primitive-mesh.torus.radial-segments.label"),info:b("asset.primitive-mesh.torus.radial-segments.info"),type:B.Number,min:1,dragStep:1,when:st,onChange:T}),N()],H.prototype,"torusRadialSegments",2);V([_({label:b("asset.primitive-mesh.torus.tubular-segments.label"),info:b("asset.primitive-mesh.torus.tubular-segments.info"),type:B.Number,min:1,dragStep:1,when:st,onChange:T}),N()],H.prototype,"torusTubularSegments",2);V([_({label:b("asset.primitive-mesh.torus.arc.label"),info:b("asset.primitive-mesh.torus.arc.info"),type:B.Number,min:0,dragStep:.1,when:st,onChange:T}),N()],H.prototype,"torusArc",2);H=V([Bt({type:"PrimitiveMesh",label:b("asset.primitive-mesh.title"),loaderType:"PrimitiveMesh",importMenuConfig:{type:Nt.Add},defaultName:"Mesh",dragLayer:Tt.PrimitiveMesh,thumbnail:Et,async bundle({content:M}){return{content:new Blob([Dt(await M.text())])}}})],H);export{H as PrimitiveMesh};
|
|
1
|
+
var wt=Object.defineProperty;var Mt=(M,s,i)=>s in M?wt(M,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):M[s]=i;var A=(M,s,i)=>(Mt(M,typeof s!="symbol"?s+"":s,i),i);import{ai as rt,B as q,bv as Rt,a5 as ut,a6 as dt,a7 as mt,a9 as ft,a3 as G,bw as tt,a4 as et,bx as Pt,j as It,by as At,K as Ht,y as Vt,p as _,e as b,C as B,t as _t,m as N,n as Bt,o as Nt,q as Tt}from"./index-eeedc550.js";import"./index-828538e1.js";import"./postmen-fe9eecc4.js";import"./meshopt_simplifier.module-cd99529d.js";import{a as Dt}from"./bundlers-9b0d37fc.js";import{M as Et}from"./MeshThumbnail-3bb8bccf.js";const z=class z{static createSphere(s=.5,i=18){i=Math.max(2,Math.floor(i));const o=i+1,e=o*o,c=i*i,l=z._generateIndices(e,c*6),R=Math.PI,t=R*2,a=1/o,y=1/i,m=8,h=new Float32Array(e*m);for(let x=0;x<e;++x){const u=x%o,d=x*a|0,p=u*y,n=d*y,w=p*t,f=n*R,v=Math.sin(f),I=-s*Math.cos(w)*v,P=s*Math.cos(f),S=s*Math.sin(w)*v;let r=x*m;h[r++]=I,h[r++]=P,h[r++]=S,h[r++]=I,h[r++]=P,h[r++]=S,h[r++]=p,h[r++]=n}let C=0;for(let x=0;x<c;++x){const u=x%i,p=(x*y|0)*o+u,n=p+1,w=p+o,f=w+1;l[C++]=n,l[C++]=p,l[C++]=f,l[C++]=p,l[C++]=w,l[C++]=f}const g=new q;return g.min.set(-s,-s,-s),g.max.set(s,s,s),{indices:l,vertices:h,bounds:g}}static createCuboid(s=1,i=1,o=1){const e=s/2,c=i/2,l=o/2,R=8,t=new Float32Array(24*R);t[0]=-e,t[1]=c,t[2]=-l,t[6]=0,t[7]=0,t[8]=e,t[9]=c,t[10]=-l,t[14]=1,t[15]=0,t[16]=e,t[17]=c,t[18]=l,t[22]=1,t[23]=1,t[24]=-e,t[25]=c,t[26]=l,t[30]=0,t[31]=1;for(let m=0;m<4;m++){let h=R*m+3;t[h++]=0,t[h++]=1,t[h++]=0}t[32]=-e,t[33]=-c,t[34]=-l,t[38]=0,t[39]=1,t[40]=e,t[41]=-c,t[42]=-l,t[46]=1,t[47]=1,t[48]=e,t[49]=-c,t[50]=l,t[54]=1,t[55]=0,t[56]=-e,t[57]=-c,t[58]=l,t[62]=0,t[63]=0;for(let m=0;m<4;m++){let h=R*m+35;t[h++]=0,t[h++]=-1,t[h++]=0}t[64]=-e,t[65]=c,t[66]=-l,t[70]=0,t[71]=0,t[72]=-e,t[73]=c,t[74]=l,t[78]=1,t[79]=0,t[80]=-e,t[81]=-c,t[82]=l,t[86]=1,t[87]=1,t[88]=-e,t[89]=-c,t[90]=-l,t[94]=0,t[95]=1;for(let m=0;m<4;m++){let h=R*m+67;t[h++]=-1,t[h++]=0,t[h++]=0}t[96]=e,t[97]=c,t[98]=-l,t[102]=1,t[103]=0,t[104]=e,t[105]=c,t[106]=l,t[110]=0,t[111]=0,t[112]=e,t[113]=-c,t[114]=l,t[118]=0,t[119]=1,t[120]=e,t[121]=-c,t[122]=-l,t[126]=1,t[127]=1;for(let m=0;m<4;m++){let h=R*m+99;t[h++]=1,t[h++]=0,t[h++]=0}t[128]=-e,t[129]=c,t[130]=l,t[134]=0,t[135]=0,t[136]=e,t[137]=c,t[138]=l,t[142]=1,t[143]=0,t[144]=e,t[145]=-c,t[146]=l,t[150]=1,t[151]=1,t[152]=-e,t[153]=-c,t[154]=l,t[158]=0,t[159]=1;for(let m=0;m<4;m++){let h=R*m+131;t[h++]=0,t[h++]=0,t[h++]=1}t[160]=-e,t[161]=c,t[162]=-l,t[166]=1,t[167]=0,t[168]=e,t[169]=c,t[170]=-l,t[174]=0,t[175]=0,t[176]=e,t[177]=-c,t[178]=-l,t[182]=0,t[183]=1,t[184]=-e,t[185]=-c,t[186]=-l,t[190]=1,t[191]=1;for(let m=0;m<4;m++){let h=R*m+163;t[h++]=0,t[h++]=0,t[h++]=-1}const a=new Uint16Array(36);a[0]=0,a[1]=2,a[2]=1,a[3]=2,a[4]=0,a[5]=3,a[6]=4,a[7]=6,a[8]=7,a[9]=6,a[10]=4,a[11]=5,a[12]=8,a[13]=10,a[14]=9,a[15]=10,a[16]=8,a[17]=11,a[18]=12,a[19]=14,a[20]=15,a[21]=14,a[22]=12,a[23]=13,a[24]=16,a[25]=18,a[26]=17,a[27]=18,a[28]=16,a[29]=19,a[30]=20,a[31]=22,a[32]=23,a[33]=22,a[34]=20,a[35]=21;const y=new q;return y.min.set(-e,-c,-l),y.max.set(e,c,l),{vertices:t,bounds:y,indices:a}}static createPlane(s=1,i=1,o=1,e=1){o=Math.max(1,Math.floor(o)),e=Math.max(1,Math.floor(e));const c=o+1,l=e+1,R=s/2,t=i/2,a=s/o,y=i/e,m=c*l,h=e*o,C=z._generateIndices(m,h*6),g=1/c,x=1/o,u=1/e,d=8,p=new Float32Array(m*d);for(let f=0;f<m;++f){const v=f%c,I=f*g|0;let P=f*d;p[P++]=v*a-R,p[P++]=0,p[P++]=I*y-t,p[P++]=0,p[P++]=1,p[P++]=0,p[P++]=v*x,p[P++]=I*u}let n=0;for(let f=0;f<h;++f){const v=f%o,P=(f*x|0)*c+v,S=P+1,r=P+c,D=r+1;C[n++]=P,C[n++]=r,C[n++]=S,C[n++]=r,C[n++]=D,C[n++]=S}const w=new q;return w.min.set(-R,0,-t),w.max.set(R,0,t),{bounds:w,vertices:p,indices:C}}static createCylinder(s=.5,i=.5,o=2,e=20,c=1){e=Math.floor(e),c=Math.floor(c);const l=e+1,R=c+1,t=o*.5,a=o/c,y=l*R,m=e*c,h=e*2,C=y+2+h,g=z._generateIndices(C,m*6+h*3),x=1/l,u=1/e,d=1/c,p=8,n=new Float32Array(C*p);let w=0;const f=Math.PI,v=Math.PI*2,I=i-s,P=I/o,S=I/c;for(let F=0;F<y;++F){const Z=F%l,W=F*x|0,O=Z*u,J=W*d,$=f+O*v,nt=Math.sin($),pt=Math.cos($),ht=i-W*S,xt=ht*nt,vt=W*a-t,Ct=ht*pt;let L=F*p;n[L++]=xt,n[L++]=vt,n[L++]=Ct,n[L++]=nt,n[L++]=P,n[L++]=pt,n[L++]=O,n[L++]=1-J}for(let F=0;F<m;++F){const Z=F%e,O=(F*u|0)*l+Z,J=O+1,$=O+l,nt=$+1;g[w++]=J,g[w++]=$,g[w++]=O,g[w++]=J,g[w++]=nt,g[w++]=$}let r=y*p;n[r++]=0,n[r++]=-t,n[r++]=0,n[r++]=0,n[r++]=-1,n[r++]=0,n[r++]=.5,n[r++]=.5,n[r++]=0,n[r++]=t,n[r++]=0,n[r++]=0,n[r++]=1,n[r++]=0,n[r++]=.5,n[r++]=.5,r=(y+2)*p;const D=1/(s*2),j=1/(i*2),E=l*c;for(let F=0;F<e;++F){const Z=F*p;let W=n[Z],O=n[Z+2];n[r++]=W,n[r++]=-t,n[r++]=O,n[r++]=0,n[r++]=-1,n[r++]=0,n[r++]=W*j+.5,n[r++]=.5-O*j;const J=(F+E)*p;W=n[J],O=n[J+2],n[r++]=W,n[r++]=t,n[r++]=O,n[r++]=0,n[r++]=1,n[r++]=0,n[r++]=W*D+.5,n[r++]=.5-O*D}const Y=y+1,X=y+2,U=X+1;for(let F=0;F<e;++F){const Z=F*2,W=F===e-1?0:Z+2;g[w++]=y,g[w++]=X+W,g[w++]=X+Z,g[w++]=Y,g[w++]=U+Z,g[w++]=U+W}const Q=new q,K=Math.max(s,i);return Q.min.set(-K,-t,-K),Q.max.set(K,t,K),{bounds:Q,vertices:n,indices:g}}static createTorus(s=.5,i=.1,o=30,e=30,c=360){o=Math.floor(o),e=Math.floor(e);const l=(o+1)*(e+1),R=o*e,t=z._generateIndices(l,R*6),a=8,y=new Float32Array(l*a);c=c/180*Math.PI;let m=0;const h=z._tempVec30;for(let x=0;x<=o;x++)for(let u=0;u<=e;u++){const d=u/e*c,p=x/o*Math.PI*2,n=Math.cos(p),w=Math.sin(p),f=Math.cos(d),v=Math.sin(d),I=(s+i*n)*f,P=(s+i*n)*v,S=i*w;y[m++]=I,y[m++]=P,y[m++]=S;const r=s*f,D=s*v;h.set(I-r,P-D,S).normalize(),y[m++]=h.x,y[m++]=h.y,y[m++]=h.z,y[m++]=u/e,y[m++]=x/o}m=0;for(let x=1;x<=o;x++)for(let u=1;u<=e;u++){const d=(e+1)*x+u-1,p=(e+1)*(x-1)+u-1,n=(e+1)*(x-1)+u,w=(e+1)*x+u;t[m++]=d,t[m++]=p,t[m++]=w,t[m++]=p,t[m++]=n,t[m++]=w}const C=new q,g=s+i;return C.min.set(-g,-g,-i),C.max.set(g,g,i),{bounds:C,vertices:y,indices:t}}static createCone(s=.5,i=2,o=20,e=1){o=Math.floor(o),e=Math.floor(e);const c=o+1,l=e+1,R=i*.5,t=i/e,a=c*l,y=o*e,m=a+1+o,h=z._generateIndices(m,y*6+o*3),C=1/c,g=1/o,x=1/e,u=8,d=new Float32Array(m*8);let p=0;const n=Math.PI,w=Math.PI*2,f=s/i;for(let r=0;r<a;++r){const D=r%c,j=r*C|0,E=D*g,Y=j*x,X=n+E*w,U=Math.sin(X),Q=Math.cos(X),K=s-j*s,F=K*U,Z=j*t-R,W=K*Q;let O=r*u;d[O++]=F,d[O++]=Z,d[O++]=W,d[O++]=U,d[O++]=f,d[O++]=Q,d[O++]=E,d[O++]=1-Y}for(let r=0;r<y;++r){const D=r%o,E=(r*g|0)*c+D,Y=E+1,X=E+c,U=X+1;h[p++]=Y,h[p++]=X,h[p++]=E,h[p++]=Y,h[p++]=U,h[p++]=X}let v=a*u;d[v++]=0,d[v++]=-R,d[v++]=0,d[v++]=0,d[v++]=-1,d[v++]=0,d[v++]=.5,d[v++]=.5,v=(a+1)*u;const I=1/(s*2);for(let r=0;r<o;++r){const D=d[r*u],j=d[r*u+2];d[v++]=D,d[v++]=-R,d[v++]=j,d[v++]=0,d[v++]=-1,d[v++]=0,d[v++]=D*I+.5,d[v++]=.5-j*I}const P=a+1;for(let r=0;r<o;++r){const D=r,j=r===o-1?0:D+1;h[p++]=a,h[p++]=P+j,h[p++]=P+D}const S=new q;return S.min.set(-s,-R,-s),S.max.set(s,R,s),{bounds:S,vertices:d,indices:h}}static createCapsule(s=.5,i=2,o=6,e=1){o=Math.max(2,Math.floor(o)),e=Math.floor(e);const c=o+1,l=e+1,R=i*.5,t=i/e,a=c*l,y=o*e,m=c*c,h=o*o,C=a+2*m,g=z._generateIndices(C,(y+2*h)*6),x=1/c,u=1/o,d=1/e,p=Math.PI,n=Math.PI*2,w=8,f=new Float32Array(C*w);let v=0;for(let P=0;P<a;++P){const S=P%c,r=P*x|0,D=S*u,j=r*d,E=p+D*n,Y=Math.sin(E),X=Math.cos(E);let U=P*w;f[U++]=s*Y,f[U++]=r*t-R,f[U++]=s*X,f[U++]=Y,f[U++]=0,f[U++]=X,f[U++]=D,f[U++]=1-j}for(let P=0;P<y;++P){const S=P%o,D=(P*u|0)*c+S,j=D+1,E=D+c,Y=E+1;g[v++]=j,g[v++]=E,g[v++]=D,g[v++]=j,g[v++]=Y,g[v++]=E}z._createCapsuleCap(s,i,o,p,n,a,1,f,g,v),z._createCapsuleCap(s,i,o,p,-n,a+m,-1,f,g,v+6*h);const I=new q;return I.min.set(-s,-s-R,-s),I.max.set(s,s+R,s),{bounds:I,vertices:f,indices:g}}static _generateIndices(s,i){let o=null;return s>65535?o=new Uint32Array(i):o=new Uint16Array(i),o}static _createCapsuleCap(s,i,o,e,c,l,R,t,a,y){const m=o+1,h=i*.5*R,C=m*m,g=o*o,x=1/m,u=1/o,d=8;for(let p=0;p<C;++p){const n=p%m,w=p*x|0,f=n*u,v=w*u,I=e+f*c,P=v*Math.PI*.5,S=Math.sin(P),r=s*Math.sin(I)*S,D=s*Math.cos(P)*R+h,j=s*Math.cos(I)*S;let E=(p+l)*d;t[E++]=r,t[E++]=D,t[E++]=j,t[E++]=r,t[E++]=D-h,t[E++]=j,t[E++]=f,t[E++]=v}for(let p=0;p<g;++p){const n=p%o,f=(p*u|0)*m+n+l,v=f+1,I=f+m,P=I+1;a[y++]=v,a[y++]=f,a[y++]=P,a[y++]=f,a[y++]=I,a[y++]=P}}static createSubdivisionSurfaceSphereData(s=.5,i=3){i=Rt.clamp(Math.floor(i),1,6);const o=new Float32Array(3*(6*Math.pow(4,i)+2)),e=new Float32Array(24*Math.pow(4,i));this._subdiveCatmullClark(i,o,e);const c=o.length/3,l=e.length/4,R=c+Math.pow(2,i+1)-1,t=R+16,a=new Float32Array(t*8),y=this._generateIndices(c,l*6);let m=0;const h={};for(let x=0;x<c;x++){let u=3*x,d=o[u],p=o[u+1],n=o[u+2];const w=1/Math.sqrt(d*d+p*p+n*n);if(d*=w,p*=w,n*=w,u=8*x,a[u]=d*s,a[u+1]=p*s,a[u+2]=n*s,a[u+3]=d,a[u+4]=p,a[u+5]=n,a[u+6]=(Math.PI-Math.atan2(n,d))/(2*Math.PI),a[u+7]=Math.acos(p)/Math.PI,a[u+6]===0){const f=8*(c+m++);a.set(a.subarray(u,u+8),f),a[f+6]=1,h[u/8]=f/8}}let C=0;this._spherePoleIdx=0;for(let x=0;x<l;x++){const u=4*x;let d=e[u],p=e[u+1],n=e[u+2],w=e[u+3];const f=8*d,v=8*p,I=8*n,P=8*w;a[f+2]+a[v+2]+a[I+2]<0&&(a[f+6]===0&&(d=h[d]),a[v+6]===0&&(p=h[p]),a[I+6]===0&&(n=h[n]),a[P+6]===0&&(w=h[w])),y[C]=d,y[C+1]=p,y[C+2]=n,this._generateAndReplacePoleUV(y,a,C,R),y[C+3]=d,y[C+4]=n,y[C+5]=w,this._generateAndReplacePoleUV(y,a,C+3,R),C+=6}const g=new q;return g.min.set(-s,-s,-s),g.max.set(s,s,s),{indices:y,vertices:a,bounds:g}}static _generateAndReplacePoleUV(s,i,o,e){const c=i[8*s[o]+7];if(c===0||c===1){const l=8*s[o],R=8*(e+this._spherePoleIdx);i.set(i.subarray(l,l+8),R),i[R+6]=.5*(i[l+6]+i[8*s[o+1]+6]+i[8*s[o+2]+6]-.5),s[o]=e+this._spherePoleIdx++}}static _subdiveCatmullClark(s,i,o){const e=new Map,c=new Array;i.set(this._sphereSeedPositions),o.set(this._sphereSeedCells);for(let l=0;l<s;l++){const R=6*Math.pow(4,l),t=4*R+2;e.clear(),c.length=0;for(let C=0;C<R;C++){const g=c[C]={facePoint:new rt,adjacentEdges:new Array(4)};for(let x=0;x<4;x++){const u=3*o[4*C+x];g.facePoint.x+=.25*i[u],g.facePoint.y+=.25*i[u+1],g.facePoint.z+=.25*i[u+2]}for(let x=0;x<4;x++){const u=o[4*C+x],d=o[4*C+(x+1)%4],p=Math.min(u,d)*t+Math.max(u,d);if(!e.has(p)){const v={edgePoint:new rt,edgePointIndex:void 0},I=3*u,P=3*d;v.edgePoint.set(.25*(i[I]+i[P]),.25*(i[I+1]+i[P+1]),.25*(i[I+2]+i[P+2])),e.set(p,v)}const n=e.get(p);g.adjacentEdges[x]=n;const w=n.edgePoint,f=g.facePoint;w.x+=.25*f.x,w.y+=.25*f.y,w.z+=.25*f.z}}const a=R+2,y=a+R;let m=0;this._sphereEdgeIdx=0;const h=o.slice(0,4*R);for(let C=0;C<R;C++){const g=c[C];g.facePoint.copyToArray(i,3*(a+C));const x=a+C;let u,d,p;for(let n=0;n<4;n++){const w=h[m++];switch(n){case 0:{const v=g.adjacentEdges[n%4],I=g.adjacentEdges[(n+3)%4];d=this._calculateEdgeIndex(i,v,y),u=this._calculateEdgeIndex(i,I,y),p=u;break}case 1:case 2:{const v=g.adjacentEdges[n%4];u=d,d=this._calculateEdgeIndex(i,v,y);break}case 3:{u=d,d=p;break}}const f=4*(4*C+n);o[f]=w,o[f+1]=d,o[f+2]=x,o[f+3]=u}}}}static _calculateEdgeIndex(s,i,o){if(i.edgePointIndex!==void 0)return i.edgePointIndex;{i.edgePoint.copyToArray(s,3*(o+this._sphereEdgeIdx));const e=o+this._sphereEdgeIdx++;return i.edgePointIndex=e,e}}};A(z,"_tempVec30",new rt),A(z,"_sphereSeedPositions",new Float32Array([-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,1,-1,-1,-1,-1,-1,1,-1])),A(z,"_sphereSeedCells",new Float32Array([0,1,2,3,3,2,4,5,5,4,6,7,7,0,3,5,7,6,1,0,6,4,2,1])),A(z,"_sphereEdgeIdx",0),A(z,"_spherePoleIdx",0);let k=z;function Ft(){return[new G(tt.Position,0,et.Vector3,0),new G(tt.Normal,12,et.Vector3,0),new G(tt.UV,24,et.Vector2,0)]}function yt(M,s,{vertices:i,indices:o,bounds:e}){const c=new ut(s,dt.VertexBuffer,i,mt.Static),l=new ut(s,dt.IndexBuffer,o,mt.Static);M.setVertexElements(Ft()),M.setIndexBufferBinding(l,o instanceof Uint16Array?ft.UInt16:ft.UInt32),M.setVertexBufferBinding(c,32),M.bounds=e,M.subMesh?M.subMesh.count=o.length:M.addSubMesh(0,o.length)}class St extends Pt{constructor(s,i,o){super(s),this.engine=i,this.generateData=o}restoreContent(){yt(this.resource,this.engine,this.generateData())}}function Ot(M,s,i){s.resourceManager.addContentRestorer(new St(M,s,i))}var jt=Object.defineProperty,Ut=Object.getOwnPropertyDescriptor,V=(M,s,i,o)=>{for(var e=o>1?void 0:o?Ut(s,i):s,c=M.length-1,l;c>=0;c--)(l=M[c])&&(e=(o?l(s,i,e):l(e))||e);return o&&e&&jt(s,i,e),e},bt=(M=>(M.Sphere="sphere",M.Cuboid="cuboid",M.Plane="plane",M.Cylinder="cylinder",M.Torus="torus",M.Cone="cone",M.Capsule="capsule",M))(bt||{});const gt=M=>M.type==="sphere",it=M=>M.type==="capsule",at=M=>M.type==="cone",lt=M=>M.type==="cuboid",ot=M=>M.type==="cylinder",st=M=>M.type==="torus",ct=M=>M.type==="plane",T=M=>M._updateData();let H=class extends It{constructor(s){super(s);A(this,"type","sphere");A(this,"sphereRadius",.5);A(this,"sphereStep",3);A(this,"capsuleRadius",.5);A(this,"capsuleHeight",2);A(this,"capsuleRadialSegments",6);A(this,"capsuleHeightSegments",1);A(this,"coneRadius",.5);A(this,"coneHeight",2);A(this,"coneRadialSegment",20);A(this,"coneHeightSegment",1);A(this,"cuboidWidth",1);A(this,"cuboidHeight",1);A(this,"cuboidDepth",1);A(this,"cylinderRadiusTop",.5);A(this,"cylinderRadiusBottom",.5);A(this,"cylinderHeight",2);A(this,"cylinderRadialSegment",20);A(this,"cylinderHeightSegment",1);A(this,"planeWidth",1);A(this,"planeHeight",1);A(this,"planeHorizontalSegments",1);A(this,"planeVerticalSegments",1);A(this,"torusRadius",.5);A(this,"torusTubeRadius",.1);A(this,"torusRadialSegments",30);A(this,"torusTubularSegments",30);A(this,"torusArc",360)}async initByCreation(s,i,o){const c=(typeof(o==null?void 0:o.primitiveType)=="string"?o.primitiveType:"").trim().toLowerCase();return{type:{sphere:"sphere",cube:"cuboid",cuboid:"cuboid",cylinder:"cylinder",plane:"plane",capsule:"capsule",cone:"cone",torus:"torus"}[c]??"sphere"}}async initByMain(s,i){const o=JSON.parse(await s.text()),e=this.engine,c=o.type,l=new At(e,c);l.setVertexElements([new G(tt.Position,0,et.Vector3,0),new G(tt.Normal,12,et.Vector3,0),new G(tt.UV,24,et.Vector2,0)]);for(const y in o)this[y]=o[y];this.bindEngineObject(l),Ot(l,e,()=>this._generateDataByType(this.type)),this._updateData();const R=new Ht(e,c&&c.charAt(0).toUpperCase()+c.slice(1)),t=R.addComponent(Vt);t.mesh=this.engineObject;const a=await this.root.assetStore.getAssetByRef({refId:"0000200"});t.setMaterial(a.engineObject),this.setDragTempEntity(R)}instantiate(){const s=this.root.sceneStore.createEntity(),i=this.getDragTempEntity();return s.initByEngineObject(i.clone()),s}_updateData(){const s=this.engine,i=this._engineObject;yt(i,s,this._generateDataByType(this.type))}_generateDataByType(s){switch(s){case"sphere":return k.createSubdivisionSurfaceSphereData(this.sphereRadius,this.sphereStep);case"capsule":return k.createCapsule(this.capsuleRadius,this.capsuleHeight,this.capsuleRadialSegments,this.capsuleHeightSegments);case"cone":return k.createCone(this.coneRadius,this.coneHeight,this.coneRadialSegment,this.coneHeightSegment);case"cuboid":return k.createCuboid(this.cuboidWidth,this.cuboidHeight,this.cuboidDepth);case"cylinder":return k.createCylinder(this.cylinderRadiusTop,this.cylinderRadiusBottom,this.cylinderHeight,this.cylinderRadialSegment,this.cylinderHeightSegment);case"plane":return k.createPlane(this.planeWidth,this.planeHeight,this.planeHorizontalSegments,this.planeVerticalSegments);case"torus":return k.createTorus(this.torusRadius,this.torusTubeRadius,this.torusRadialSegments,this.torusTubularSegments,this.torusArc);default:return k.createSphere(this.sphereRadius,this.sphereStep)}}};V([_({label:b("asset.primitive-mesh.type.label"),info:b("asset.primitive-mesh.type.info"),type:B.Select,value:"sphere",options:_t(bt),onChange(M){M._updateData()}}),N()],H.prototype,"type",2);V([_({label:b("asset.primitive-mesh.sphere.radius.label"),info:b("asset.primitive-mesh.sphere.radius.info"),type:B.Number,min:0,dragStep:.1,when:gt,onChange:T}),N()],H.prototype,"sphereRadius",2);V([_({label:b("asset.primitive-mesh.sphere.step.label"),info:b("asset.primitive-mesh.sphere.step.info"),type:B.Number,min:1,dragStep:1,when:gt,onChange:T}),N()],H.prototype,"sphereStep",2);V([_({label:b("asset.primitive-mesh.capsule.radius.label"),info:b("asset.primitive-mesh.capsule.radius.info"),type:B.Number,min:0,dragStep:.1,when:it,onChange:T}),N()],H.prototype,"capsuleRadius",2);V([_({label:b("asset.primitive-mesh.capsule.height.label"),info:b("asset.primitive-mesh.capsule.height.info"),type:B.Number,min:0,dragStep:.1,when:it,onChange:T}),N()],H.prototype,"capsuleHeight",2);V([_({label:b("asset.primitive-mesh.capsule.radial-segments.label"),info:b("asset.primitive-mesh.capsule.radial-segments.info"),type:B.Number,min:1,dragStep:1,when:it,onChange:T}),N()],H.prototype,"capsuleRadialSegments",2);V([_({label:b("asset.primitive-mesh.capsule.height-segments.label"),info:b("asset.primitive-mesh.capsule.height-segments.info"),type:B.Number,min:1,dragStep:1,when:it,onChange:T}),N()],H.prototype,"capsuleHeightSegments",2);V([_({label:b("asset.primitive-mesh.cone.radius.label"),info:b("asset.primitive-mesh.cone.radius.info"),type:B.Number,min:0,dragStep:.1,when:at,onChange:T}),N()],H.prototype,"coneRadius",2);V([_({label:b("asset.primitive-mesh.cone.height.label"),info:b("asset.primitive-mesh.cone.height.info"),type:B.Number,min:0,dragStep:.1,when:at,onChange:T}),N()],H.prototype,"coneHeight",2);V([_({label:b("asset.primitive-mesh.cone.radial-segments.label"),info:b("asset.primitive-mesh.cone.radial-segments.info"),type:B.Number,min:1,dragStep:1,when:at,onChange:T}),N()],H.prototype,"coneRadialSegment",2);V([_({label:b("asset.primitive-mesh.cone.height-segments.label"),info:b("asset.primitive-mesh.cone.height-segments.info"),type:B.Number,min:1,dragStep:1,when:at,onChange:T}),N()],H.prototype,"coneHeightSegment",2);V([_({label:b("asset.primitive-mesh.cuboid.width.label"),info:b("asset.primitive-mesh.cuboid.width.info"),type:B.Number,min:0,dragStep:.1,when:lt,onChange:T}),N()],H.prototype,"cuboidWidth",2);V([_({label:b("asset.primitive-mesh.cuboid.height.label"),info:b("asset.primitive-mesh.cuboid.height.info"),type:B.Number,min:0,dragStep:.1,when:lt,onChange:T}),N()],H.prototype,"cuboidHeight",2);V([_({label:b("asset.primitive-mesh.cuboid.depth.label"),info:b("asset.primitive-mesh.cuboid.depth.info"),type:B.Number,min:0,dragStep:.1,when:lt,onChange:T}),N()],H.prototype,"cuboidDepth",2);V([_({label:b("asset.primitive-mesh.cylinder.radius-top.label"),info:b("asset.primitive-mesh.cylinder.radius-top.info"),type:B.Number,min:0,dragStep:.1,when:ot,onChange:T}),N()],H.prototype,"cylinderRadiusTop",2);V([_({label:b("asset.primitive-mesh.cylinder.radius-bottom.label"),info:b("asset.primitive-mesh.cylinder.radius-bottom.info"),type:B.Number,min:0,dragStep:.1,when:ot,onChange:T}),N()],H.prototype,"cylinderRadiusBottom",2);V([_({label:b("asset.primitive-mesh.cylinder.height.label"),info:b("asset.primitive-mesh.cylinder.height.info"),type:B.Number,min:0,dragStep:.1,when:ot,onChange:T}),N()],H.prototype,"cylinderHeight",2);V([_({label:b("asset.primitive-mesh.cylinder.radial-segments.label"),info:b("asset.primitive-mesh.cylinder.radial-segments.info"),type:B.Number,min:1,dragStep:1,when:ot,onChange:T}),N()],H.prototype,"cylinderRadialSegment",2);V([_({label:b("asset.primitive-mesh.cylinder.height-segments.label"),info:b("asset.primitive-mesh.cylinder.height-segments.info"),type:B.Number,min:1,dragStep:1,when:ot,onChange:T}),N()],H.prototype,"cylinderHeightSegment",2);V([_({label:b("asset.primitive-mesh.plane.width.label"),info:b("asset.primitive-mesh.plane.width.info"),type:B.Number,min:0,dragStep:.1,when:ct,onChange:T}),N()],H.prototype,"planeWidth",2);V([_({label:b("asset.primitive-mesh.plane.height.label"),info:b("asset.primitive-mesh.plane.height.info"),type:B.Number,min:0,dragStep:.1,when:ct,onChange:T}),N()],H.prototype,"planeHeight",2);V([_({label:b("asset.primitive-mesh.plane.horizontal-segments.label"),info:b("asset.primitive-mesh.plane.horizontal-segments.info"),type:B.Number,min:1,dragStep:1,when:ct,onChange:T}),N()],H.prototype,"planeHorizontalSegments",2);V([_({label:b("asset.primitive-mesh.plane.vertical-segments.label"),info:b("asset.primitive-mesh.plane.vertical-segments.info"),type:B.Number,min:1,dragStep:1,when:ct,onChange:T}),N()],H.prototype,"planeVerticalSegments",2);V([_({label:b("asset.primitive-mesh.torus.radius.label"),info:b("asset.primitive-mesh.torus.radius.info"),type:B.Number,min:0,dragStep:.1,when:st,onChange:T}),N()],H.prototype,"torusRadius",2);V([_({label:b("asset.primitive-mesh.torus.tube-radius.label"),info:b("asset.primitive-mesh.torus.tube-radius.info"),type:B.Number,min:0,dragStep:.1,when:st,onChange:T}),N()],H.prototype,"torusTubeRadius",2);V([_({label:b("asset.primitive-mesh.torus.radial-segments.label"),info:b("asset.primitive-mesh.torus.radial-segments.info"),type:B.Number,min:1,dragStep:1,when:st,onChange:T}),N()],H.prototype,"torusRadialSegments",2);V([_({label:b("asset.primitive-mesh.torus.tubular-segments.label"),info:b("asset.primitive-mesh.torus.tubular-segments.info"),type:B.Number,min:1,dragStep:1,when:st,onChange:T}),N()],H.prototype,"torusTubularSegments",2);V([_({label:b("asset.primitive-mesh.torus.arc.label"),info:b("asset.primitive-mesh.torus.arc.info"),type:B.Number,min:0,dragStep:.1,when:st,onChange:T}),N()],H.prototype,"torusArc",2);H=V([Bt({type:"PrimitiveMesh",label:b("asset.primitive-mesh.title"),loaderType:"PrimitiveMesh",importMenuConfig:{type:Nt.Add},defaultName:"Mesh",dragLayer:Tt.PrimitiveMesh,thumbnail:Et,async bundle({content:M}){return{content:new Blob([Dt(await M.text())])}}})],H);export{H as PrimitiveMesh};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{aH as n,aI as s,aJ as o,aK as i,aL as t,aM as d,aN as c,aO as g}from"./index-
|
|
1
|
+
import{aH as n,aI as s,aJ as o,aK as i,aL as t,aM as d,aN as c,aO as g}from"./index-eeedc550.js";import{M as h}from"./MaterialInspector-ebbe39d5.js";const m=n("div",{marginLeft:"5px"}),u=n(s,{borderRadius:"$3",padding:"$1_5",marginLeft:"-$1_5",marginRight:"-$0_5",marginBottom:"$1",color:"$gray11",cursor:"pointer",backgroundColor:"transparent",transition:"background-color 0.2s","&:hover":{backgroundColor:"$grayA3"},variants:{open:{true:{boxShadow:"inset 0 0 0 1px $colors$grayA3",backgroundColor:"$grayA5","&:hover":{backgroundColor:"$grayA5"}}}}});function x(r){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",...r,children:t.jsx("path",{fill:"currentColor",d:"m12 17.4l-3.9 3.9q-.275.275-.7.275t-.7-.275t-.275-.7t.275-.7l3.875-3.875q.575-.575 1.425-.575t1.425.575L17.3 19.9q.275.275.275.7t-.275.7t-.7.275t-.7-.275zm0-10.8l3.9-3.9q.275-.275.7-.275t.7.275t.275.7t-.275.7l-3.875 3.875Q12.85 8.55 12 8.55t-1.425-.575L6.7 4.1q-.275-.275-.275-.7t.275-.7t.7-.275t.7.275z"})})}function p(r){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",...r,children:t.jsx("path",{fill:"currentColor",d:"m12 19.15l3.875-3.875q.3-.3.7-.3t.7.3t.3.713t-.3.712l-3.85 3.875q-.575.575-1.425.575t-1.425-.575L6.7 16.7q-.3-.3-.288-.712t.313-.713t.713-.3t.712.3zm0-14.3L8.15 8.7q-.3.3-.7.288t-.7-.288q-.3-.3-.312-.712t.287-.713l3.85-3.85Q11.15 2.85 12 2.85t1.425.575l3.85 3.85q.3.3.288.713t-.313.712q-.3.275-.7.288t-.7-.288z"})})}const b=o(function(e){const{t:a}=i();return t.jsxs(u,{align:"v",justifyContent:"between",open:e.open,children:[t.jsxs(s,{align:"v",gap:"xs",children:[t.jsx("img",{src:e.thumbnailUrl,alt:a("mesh-renderer.material.thumbnail"),width:"20px",height:"20px"}),t.jsxs(m,{children:[a("mesh-renderer.material.title"),"(",e.name,")"]})]}),t.jsx(d,{size:"xs",variant:"subtle",children:e.open?t.jsx(x,{}):t.jsx(p,{})})]})}),f=r=>{const{materialAsset:e}=r,[a,l]=c.useState(!1);return t.jsx(g,{nesting:!0,title:t.jsx(b,{open:a,thumbnailUrl:e.thumbnailUrl,name:e.name}),defaultOpen:!1,open:a,onOpenChange:l,children:t.jsx(h,{asset:e})})};export{f as R};
|
package/dist/preview-client/_static/{RenderTargetAsset-bf38a725.js → RenderTargetAsset-81649762.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
var C=Object.defineProperty;var M=(s,t,e)=>t in s?C(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var h=(s,t,e)=>(M(s,typeof t!="symbol"?t+"":t,e),e);import{N as R,$ as y,b0 as l,j as x,a$ as v,bz as S,p as b,C as m,m as f,n as G,e as F,o as O,q as D}from"./index-
|
|
1
|
+
var C=Object.defineProperty;var M=(s,t,e)=>t in s?C(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var h=(s,t,e)=>(M(s,typeof t!="symbol"?t+"":t,e),e);import{N as R,$ as y,b0 as l,j as x,a$ as v,bz as S,p as b,C as m,m as f,n as G,e as F,o as O,q as D}from"./index-eeedc550.js";import"./index-828538e1.js";import"./postmen-fe9eecc4.js";import{A as B}from"./AssetViewer-f505fb55.js";class A{static update(t,e){var o;this.spriteEntity?this.spriteEntity.isActive=!0:this.initScene(t),this.entity=this.spriteEntity;const i=(o=e.engineObject)==null?void 0:o.getColorTexture(0);i&&(this.sprite.texture=i)}static clear(){this.spriteEntity&&(this.spriteEntity.isActive=!1)}static initScene(t){const e=this.spriteEntity=t.createChild("rt-thumbnail");this.spriteRenderer=e.addComponent(R),this.spriteRenderer.sprite=this.sprite=new y(t.engine)}}h(A,"entity"),h(A,"spriteEntity"),h(A,"spriteRenderer"),h(A,"sprite");class j extends B{constructor(){super(...arguments);h(this,"_asset");h(this,"_sprite");h(this,"_onRebuild",()=>{var e;if(this._sprite&&((e=this._asset)!=null&&e.engineObject)){const i=this._asset.engineObject.getColorTexture(0);i&&(this._sprite.texture=i)}})}setViewAsset(e,i){var _;this._asset=e;const o=i.engine,r=i.createChild("rt_preview"),n=(_=e.engineObject)==null?void 0:_.getColorTexture(0),a=new y(o,n),c=r.addComponent(R);c.sprite=a,this._sprite=a,this._entity=r,e.onRebuild(this._onRebuild)}stopViewAsset(){super.stopViewAsset(),this._asset&&this._asset.offRebuild(this._onRebuild),this._asset=null,this._sprite=null}getDescription(e){return`${e.width}x${e.height}`}}var E=Object.defineProperty,V=Object.getOwnPropertyDescriptor,g=(s,t,e,i)=>{for(var o=i>1?void 0:i?V(t,e):t,r=s.length-1,n;r>=0;r--)(n=s[r])&&(o=(i?n(t,e,o):n(o))||o);return i&&o&&E(t,e,o),o};const I=[{label:"R8G8B8A8",value:l.R8G8B8A8},{label:"R8G8B8",value:l.R8G8B8},{label:"R16G16B16A16",value:l.R16G16B16A16},{label:"R32G32B32A32",value:l.R32G32B32A32},{label:"R11G11B10_UFloat",value:l.R11G11B10_UFloat}],w=-1,L=[{label:"None",value:w},{label:"Depth",value:l.Depth},{label:"Depth16",value:l.Depth16},{label:"Depth24",value:l.Depth24},{label:"Depth32",value:l.Depth32},{label:"Depth24Stencil8",value:l.Depth24Stencil8},{label:"Depth32Stencil8",value:l.Depth32Stencil8}],U=[{label:"1",value:1},{label:"2",value:2},{label:"4",value:4},{label:"8",value:8}];let u=class extends x{constructor(){super(...arguments);h(this,"_onRebuildCallbacks",[]);h(this,"width",512);h(this,"height",512);h(this,"colorFormat",l.R8G8B8A8);h(this,"depthFormat",l.Depth);h(this,"antiAliasing",1);h(this,"autoGenerateMipmaps",!0)}registerThumbnail(){}onRebuild(t){this._onRebuildCallbacks.push(t)}offRebuild(t){const e=this._onRebuildCallbacks.indexOf(t);e!==-1&&this._onRebuildCallbacks.splice(e,1)}async initByCreation(){return this.getMainData()}getMainData(){var i;const t={width:this.width,height:this.height,colorFormats:[this.colorFormat],depthFormat:this.depthFormat,antiAliasing:this.antiAliasing,autoGenerateMipmaps:this.autoGenerateMipmaps},e=(i=this.engineObject)==null?void 0:i.getColorTexture(0);return e&&(t.colorTextures=[{isSRGBColorSpace:e.isSRGBColorSpace,mipmap:e.mipmapCount>1,filterMode:e.filterMode,wrapModeU:e.wrapModeU,wrapModeV:e.wrapModeV,anisoLevel:e.anisoLevel}]),JSON.stringify(t)}async initByMain(t){const e=JSON.parse(await t.text());this.width=Math.round(e.width??512),this.height=Math.round(e.height??512);const i=e.colorFormats??[e.colorFormat??l.R8G8B8A8];this.colorFormat=i[0],this.depthFormat=e.depthFormat??l.Depth,this.antiAliasing=e.antiAliasing??1,this.autoGenerateMipmaps=e.autoGenerateMipmaps??!1;const r=(e.colorTextures??(e.colorTexture?[e.colorTexture]:[]))[0],n=this._buildRenderTarget((r==null?void 0:r.mipmap)??!0,r==null?void 0:r.isSRGBColorSpace);await this.bindEngineObject(n);const a=n.getColorTexture(0);a&&r&&(r.filterMode!=null&&(a.filterMode=r.filterMode),r.wrapModeU!=null&&(a.wrapModeU=r.wrapModeU),r.wrapModeV!=null&&(a.wrapModeV=r.wrapModeV),r.anisoLevel!=null&&(a.anisoLevel=r.anisoLevel)),await this._generateSubAssets()}destroy(){this._destroySubAssets(),this.engineObject&&this._replaceCameraRenderTarget(this.engineObject,null),this._onRebuildCallbacks.length=0,this._destroyRenderTarget(),super.destroy()}async _rebuild(){var _;if(!this.engineObject)return;const t=this.engineObject,e=t.getColorTexture(0),i=(_=this._subAssets)==null?void 0:_[0],o=i?i.mipmap??!0:!0,r=i?i.isSRGBColorSpace??this.colorFormat===l.R8G8B8A8:this.colorFormat===l.R8G8B8A8,n=e&&e.format===this.colorFormat&&e.width===this.width&&e.height===this.height&&e.isSRGBColorSpace===r&&o===e.mipmapCount>1;let a;try{a=n?this._buildRenderTargetWithTexture(e):this._buildRenderTarget(o,r)}catch(p){console.warn("Failed to create RenderTarget:",p);return}if(!n&&e){const p=a.getColorTexture(0);p&&(p.filterMode=e.filterMode,p.wrapModeU=e.wrapModeU,p.wrapModeV=e.wrapModeV,p.anisoLevel=e.anisoLevel)}const c=this._replaceCameraRenderTarget(t,a);if(t.destroy(),await this.bindEngineObject(a),n||(e==null||e.destroy(),this._destroySubAssets(),await this._generateSubAssets()),c.length>0){const p=c.map(d=>d.enabled);c.forEach(d=>d.enabled=!0),requestAnimationFrame(()=>{this._onRebuildCallbacks.forEach(d=>d()),c.forEach((d,T)=>d.enabled=p[T])})}else this._onRebuildCallbacks.forEach(p=>p())}_buildRenderTarget(t=!0,e){const{width:i,height:o,colorFormat:r}=this;e===void 0&&(e=r===l.R8G8B8A8);const n=new v(this.engine,i,o,r,t,e);return n.isGCIgnored=!0,this._buildRenderTargetWithTexture(n)}_buildRenderTargetWithTexture(t){const{width:e,height:i,depthFormat:o,antiAliasing:r,autoGenerateMipmaps:n}=this,a=o===w?null:o,c=new S(this.engine,e,i,t,a,r);return c.isGCIgnored=!0,c.autoGenerateMipmaps=n,c}_destroyRenderTarget(){var e;const t=this.engineObject;t&&((e=t.getColorTexture(0))==null||e.destroy(),t.destroy())}_replaceCameraRenderTarget(t,e){const i=this.root.projectStore.currentScene;if(!i)return[];const o=[];for(const r of i.entities.values())for(const n of r.components)if(n.type==="Camera"){const a=n.engineObject;(a==null?void 0:a.renderTarget)===t&&(a.renderTarget=e,o.push(a))}return o}async _generateSubAssets(){const t=this.engineObject,e=[],i=t.getColorTexture(0);if(i){i.name=`${this.name}-color`;const o=await this.root.assetStore.createSubAsset("Texture",i,this.id,"colorTextures[0]");o._editable=!0,e.push(o)}this._subAssets=e}_destroySubAssets(){if(this._subAssets){for(const t of this._subAssets)this.root.assetStore.deleteSubAsset(t.id);this._subAssets=[]}}};g([b({type:m.Number,label:"Width",min:1,max:8192,triggerAfterInit:!1,onChange:s=>{s.width=Math.round(s.width),s._rebuild()}}),f()],u.prototype,"width",2);g([b({type:m.Number,label:"Height",min:1,max:8192,triggerAfterInit:!1,onChange:s=>{s.height=Math.round(s.height),s._rebuild()}}),f()],u.prototype,"height",2);g([b({type:m.Select,label:"Color Format",options:I,triggerAfterInit:!1,onChange:s=>s._rebuild()}),f()],u.prototype,"colorFormat",2);g([b({type:m.Select,label:"Depth Format",options:L,triggerAfterInit:!1,onChange:s=>s._rebuild()}),f()],u.prototype,"depthFormat",2);g([b({type:m.Select,label:"Anti-Aliasing",options:U,triggerAfterInit:!1,onChange:s=>s._rebuild()}),f()],u.prototype,"antiAliasing",2);g([b({type:m.Toggle,label:"Auto Generate Mipmaps",triggerAfterInit:!1,onChange:s=>{const t=s.engineObject;t&&(t.autoGenerateMipmaps=s.autoGenerateMipmaps)}}),f()],u.prototype,"autoGenerateMipmaps",2);u=g([G({type:"RenderTarget",label:F("asset.render-target.title"),extname:"renderTarget",importMenuConfig:{type:O.Add},dragLayer:D.RenderTarget,viewer:j,thumbnail:A,async bundle({content:s}){return{content:s}}})],u);export{u as RenderTargetAsset};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var p=Object.defineProperty;var l=(t,e,s)=>e in t?p(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var o=(t,e,s)=>(l(t,typeof e!="symbol"?e+"":e,s),s);import{j as m,u as h,aX as u,aY as d,aZ as f,a_ as y,n as D,e as S,o as v}from"./index-
|
|
1
|
+
var p=Object.defineProperty;var l=(t,e,s)=>e in t?p(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var o=(t,e,s)=>(l(t,typeof e!="symbol"?e+"":e,s),s);import{j as m,u as h,aX as u,aY as d,aZ as f,a_ as y,n as D,e as S,o as v}from"./index-eeedc550.js";import"./index-828538e1.js";import"./postmen-fe9eecc4.js";function b(t){const e={asset:{version:"2.0",generator:"Galacean Editor"},scene:{rootEntities:["1000000","1000001"],background:{mode:0,color:{r:.0157,g:.0157,b:.0157,a:1}},ambient:{},shadow:{},fog:{}},entities:[{id:"1000000",name:"Camera",position:[0,0,10],components:["1000100"]},{id:"1000001",name:"DirectLight",position:[0,3,0],rotation:[-45,-45,0],components:["1000101"]}],components:[{id:"1000100",type:"Camera",props:{isOrthographic:!1,nearClipPlane:.1,farClipPlane:100,viewport:{x:0,y:0,z:1,w:1}}},{id:"1000101",type:"DirectLight",props:{enabled:!0,intensity:.6,color:{r:1,g:1,b:1,a:1}}}]};return t!==void 0&&(e.scene.name=t),e}var g=Object.defineProperty,w=Object.getOwnPropertyDescriptor,C=(t,e,s,n)=>{for(var a=n>1?void 0:n?w(e,s):e,i=t.length-1,r;i>=0;i--)(r=t[i])&&(a=(n?r(e,s,a):r(a))||a);return n&&a&&g(e,s,a),a};let c=class extends m{constructor(e){super(e);o(this,"sceneData",null);h(this)}async initByMain(e,s){this.sceneData=u(await e.text())}getMainData(){return d(this.sceneData)}async rename(e){await super.rename(e),await this.root.assetFacade.persistAssetMain(this.id)}saveMainImmediately(e){var n;const s=this.root.sceneStore;if(this.id===s.refId){if(s.destroyed){f(this.root.projectStore.id,this.serverId);return}const a=y(this.root,this.id);return this.sceneData=a,this.sceneData.scene&&(this.sceneData.scene.name=this.name),super.saveMainImmediately(e)}else if((n=this.sceneData)!=null&&n.scene&&this.sceneData.scene.name!==this.name)return this.sceneData.scene.name=this.name,super.saveMainImmediately(e)}async initByCreation(e,s,n){return this.sceneData=b(this._name)}onDoubleClick(){this.root.projectStore.switchScene({scene:this.id})}};c=C([D({type:"Scene",label:S("asset.scene.title"),defaultName:"Scene",extname:"scene",importMenuConfig:{type:v.Add},async bundle(t){return{content:new Blob([t.content],{type:"application/json"})}}})],c);export{c as SceneAsset};
|