@liveroom-tech/react-immersive 6.2.2 → 6.2.3

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.
Files changed (40) hide show
  1. package/README.md +23 -0
  2. package/dist/{SequencesTab-LTMJTB76.mjs → SequencesTab-JZEE5WAM.mjs} +1 -1
  3. package/dist/binding-builder.d.mts +3 -3
  4. package/dist/binding-builder.d.ts +3 -3
  5. package/dist/binding-builder.js +41 -41
  6. package/dist/binding-builder.mjs +1 -1
  7. package/dist/{chunk-NMRTI3NQ.mjs → chunk-3GA7JFNH.mjs} +1 -1
  8. package/dist/chunk-3I7PPFUV.mjs +1 -0
  9. package/dist/{chunk-IT2PUTJS.mjs → chunk-CHMFH4D4.mjs} +1 -1
  10. package/dist/{chunk-RSUXTWM6.mjs → chunk-CUDL77ZY.mjs} +1 -1
  11. package/dist/{chunk-XKJQC3N5.mjs → chunk-IEKGBS46.mjs} +1 -1
  12. package/dist/chunk-LU3BQ7WG.mjs +69 -0
  13. package/dist/chunk-QZNUWZG7.mjs +50 -0
  14. package/dist/{chunk-WU3SQZGD.mjs → chunk-TI2YXAHW.mjs} +2 -2
  15. package/dist/hosted.d.mts +3 -3
  16. package/dist/hosted.d.ts +3 -3
  17. package/dist/hosted.js +40 -40
  18. package/dist/hosted.mjs +1 -1
  19. package/dist/index.d.mts +8 -4
  20. package/dist/index.d.ts +8 -4
  21. package/dist/index.js +36 -36
  22. package/dist/index.mjs +1 -1
  23. package/dist/{modelFileResolver-Bq4pW9vc.d.mts → modelFileResolver-An1aQ0D3.d.mts} +3 -0
  24. package/dist/{modelFileResolver-Bq4pW9vc.d.ts → modelFileResolver-An1aQ0D3.d.ts} +3 -0
  25. package/dist/{modelViewerProps-BnrJO5DK.d.ts → modelViewerProps-BnVflYRA.d.mts} +21 -3
  26. package/dist/{modelViewerProps-wjBT4fks.d.mts → modelViewerProps-H_K454u_.d.ts} +21 -3
  27. package/dist/{publicProps-BZPMIRwj.d.ts → publicProps-AdNUI06n.d.ts} +1 -1
  28. package/dist/{publicProps-CW5X_HFh.d.mts → publicProps-BOQBJBA_.d.mts} +1 -1
  29. package/dist/simple-model-viewer.d.mts +6 -2
  30. package/dist/simple-model-viewer.d.ts +6 -2
  31. package/dist/simple-model-viewer.js +5 -5
  32. package/dist/simple-model-viewer.mjs +1 -1
  33. package/dist/utils.d.mts +4 -4
  34. package/dist/utils.d.ts +4 -4
  35. package/dist/utils.js +15 -15
  36. package/dist/utils.mjs +1 -1
  37. package/package.json +7 -5
  38. package/dist/chunk-2LGQKX6Z.mjs +0 -50
  39. package/dist/chunk-LEOHZ5HM.mjs +0 -69
  40. package/dist/chunk-UAZ6I25Y.mjs +0 -1
package/dist/utils.mjs CHANGED
@@ -1 +1 @@
1
- import{a as ce,b as se,c as pe}from"./chunk-F5QSXMME.mjs";import{$ as A,Da as ae,E as u,Fa as ue,G as d,Ga as de,H as m,Ha as me,Ia as Se,Ja as le,R as S,T as l,V as f,W as g,X as C,Y as y,Z as x,_ as P,aa as H,ba as F,ca as K,da as W,ia as z,ja as Q,oa as J,pa as Y,ra as Z,va as te,w as a,wa as oe,x as c,xa as ne,y as s,ya as re,z as p,za as ie}from"./chunk-2LGQKX6Z.mjs";import{a as e,b as t,e as o,f as n,g as r}from"./chunk-LX3GXQNU.mjs";import{b,c as E,d as h,e as j,f as R,g as T,h as V,i as I,j as L,k as w,l as D,m as _,n as N,o as q,p as k,q as v,r as U,s as G}from"./chunk-7JCFNZJM.mjs";import"./chunk-37QOMZW6.mjs";import{b as $,c as ee}from"./chunk-CCBFMNAU.mjs";import{b as O,c as B}from"./chunk-GV4ZRXL6.mjs";import"./chunk-7OWHW66D.mjs";import{e as X}from"./chunk-KFLS7GI6.mjs";import{a as i}from"./chunk-UAZ6I25Y.mjs";import{c as M}from"./chunk-BNKTI3CY.mjs";import"./chunk-UCD76KQ6.mjs";import"./chunk-RXZ4Q7CY.mjs";import"./chunk-JR557W27.mjs";export{Y as ACTION_CATALOG,i as DEFAULT_MODEL_VIEWER_LABELS,c as DEFAULT_SCENE_CONFIG,a as DEFAULT_SECTION_CONFIG,de as MATERIAL_BLENDING_MODES,ue as MATERIAL_SIDES,H as MAX_VIEWER_STATE_BYTES,S as MEASUREMENT_UNITS,t as SEQUENCE_EASINGS,e as SEQUENCE_OBJECT_PROPERTIES,oe as applyIsolation,G as applyProductOptions,ee as applyStyleRules,ie as buildBindingsFromNodes,f as calibrateMeasurements,M as chooseMaterialVariant,me as collectObjectHierarchy,$ as colorScaleValue,ae as compareViewerConfigurations,Se as copyBindingStyle,z as createARHandoffUrl,re as createDefaultBinding,D as decodeProductSelections,j as defaultProductSelections,pe as defineObjectBindings,w as encodeProductSelections,R as evaluateProductConfiguration,J as exportConfiguredUSDZ,Z as findCatalogAction,I as formatProductPrice,_ as generateProductSkus,m as groundAsset,ne as inferType,X as inspectAsset,te as isolatedBindingKeys,E as material,C as measurementResult,l as measurementScale,g as measurementValue,P as measurementsToCsv,u as parseAssetTransform,y as parseMeasurements,U as parseProductConfiguration,h as parseProductDefinition,k as parseSceneProduct,s as parseSectionConfig,A as parseSelectionSets,o as parseSequences,K as parseViewerState,le as pasteBindingStyle,b as patchBindings,ce as patchSceneConfig,W as prepareViewerState,L as productCheckoutUrl,N as productDefinitionWarnings,q as productOptionStates,V as productPriceFromDefinition,Q as readARHandoffUrl,T as resolveProductSelections,n as sampleSequenceTrack,se as sceneLight,p as sectionSnapshot,O as selectBindingKeys,B as selectBindings,x as serializeMeasurements,v as serializeProductConfiguration,F as serializeViewerState,d as snapAssetToGrid,r as upsertSequenceKeyframe};
1
+ import{a as ce,b as se,c as pe}from"./chunk-F5QSXMME.mjs";import{$ as x,A as s,Aa as re,B as p,Ba as ie,Fa as ae,G as u,Ha as ue,I as d,Ia as de,J as m,Ja as me,Ka as Se,La as le,T as S,V as l,X as f,Y as g,Z as C,_ as y,aa as P,ba as A,ca as H,da as F,ea as K,fa as W,ka as z,la as Q,qa as J,ra as Y,ta as Z,xa as te,y as a,ya as oe,z as c,za as ne}from"./chunk-QZNUWZG7.mjs";import{a as e,b as t,e as o,f as n,g as r}from"./chunk-LX3GXQNU.mjs";import{b,c as E,d as h,e as j,f as R,g as T,h as V,i as I,j as L,k as w,l as D,m as _,n as N,o as q,p as k,q as v,r as U,s as G}from"./chunk-7JCFNZJM.mjs";import"./chunk-37QOMZW6.mjs";import{b as $,c as ee}from"./chunk-CCBFMNAU.mjs";import{b as O,c as B}from"./chunk-GV4ZRXL6.mjs";import"./chunk-7OWHW66D.mjs";import{e as X}from"./chunk-KFLS7GI6.mjs";import{a as i}from"./chunk-3I7PPFUV.mjs";import{c as M}from"./chunk-BNKTI3CY.mjs";import"./chunk-UCD76KQ6.mjs";import"./chunk-RXZ4Q7CY.mjs";import"./chunk-JR557W27.mjs";export{Y as ACTION_CATALOG,i as DEFAULT_MODEL_VIEWER_LABELS,c as DEFAULT_SCENE_CONFIG,a as DEFAULT_SECTION_CONFIG,de as MATERIAL_BLENDING_MODES,ue as MATERIAL_SIDES,H as MAX_VIEWER_STATE_BYTES,S as MEASUREMENT_UNITS,t as SEQUENCE_EASINGS,e as SEQUENCE_OBJECT_PROPERTIES,oe as applyIsolation,G as applyProductOptions,ee as applyStyleRules,ie as buildBindingsFromNodes,f as calibrateMeasurements,M as chooseMaterialVariant,me as collectObjectHierarchy,$ as colorScaleValue,ae as compareViewerConfigurations,Se as copyBindingStyle,z as createARHandoffUrl,re as createDefaultBinding,D as decodeProductSelections,j as defaultProductSelections,pe as defineObjectBindings,w as encodeProductSelections,R as evaluateProductConfiguration,J as exportConfiguredUSDZ,Z as findCatalogAction,I as formatProductPrice,_ as generateProductSkus,m as groundAsset,ne as inferType,X as inspectAsset,te as isolatedBindingKeys,E as material,C as measurementResult,l as measurementScale,g as measurementValue,P as measurementsToCsv,u as parseAssetTransform,y as parseMeasurements,U as parseProductConfiguration,h as parseProductDefinition,k as parseSceneProduct,s as parseSectionConfig,A as parseSelectionSets,o as parseSequences,K as parseViewerState,le as pasteBindingStyle,b as patchBindings,ce as patchSceneConfig,W as prepareViewerState,L as productCheckoutUrl,N as productDefinitionWarnings,q as productOptionStates,V as productPriceFromDefinition,Q as readARHandoffUrl,T as resolveProductSelections,n as sampleSequenceTrack,se as sceneLight,p as sectionSnapshot,O as selectBindingKeys,B as selectBindings,x as serializeMeasurements,v as serializeProductConfiguration,F as serializeViewerState,d as snapAssetToGrid,r as upsertSequenceKeyframe};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveroom-tech/react-immersive",
3
- "version": "6.2.2",
3
+ "version": "6.2.3",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -27,9 +27,11 @@
27
27
  "require": "./dist/utils.js"
28
28
  },
29
29
  "./hosted": {
30
- "types": "./dist/hosted.d.ts",
31
- "import": "./dist/hosted.mjs",
32
- "require": "./dist/hosted.js"
30
+ "liveroom-internal": {
31
+ "types": "./dist/hosted.d.ts",
32
+ "import": "./dist/hosted.mjs",
33
+ "require": "./dist/hosted.js"
34
+ }
33
35
  },
34
36
  "./styles.css": "./dist/index.css",
35
37
  "./simple-model-viewer.css": "./dist/simple-model-viewer.css",
@@ -57,7 +59,7 @@
57
59
  "typecheck": "tsc --noEmit -p .",
58
60
  "lint": "eslint src",
59
61
  "verify": "npm run typecheck && npm test",
60
- "check:types": "tsc -p scripts/check-types && node scripts/check-types/exports.mjs",
62
+ "check:types": "tsc -p scripts/check-types && node scripts/check-types/exports.mjs && node scripts/check-types/hosted.mjs",
61
63
  "test:browser": "playwright test --config validation/browser/playwright.config.ts",
62
64
  "measure:bundle": "npm run build && node scripts/measure-bundle.mjs"
63
65
  },
@@ -1,50 +0,0 @@
1
- import{e as Ae,f as ut}from"./chunk-LX3GXQNU.mjs";import{p as Mt}from"./chunk-7JCFNZJM.mjs";import{b as Le,c as xt,i as je,t as At}from"./chunk-37QOMZW6.mjs";import{a as ft,b as ve}from"./chunk-GV4ZRXL6.mjs";import{f as pt,h as gt}from"./chunk-7OWHW66D.mjs";import{a as Ct,o as ke,q as jt}from"./chunk-UCD76KQ6.mjs";import{a as ge,b as bt,c as ht,d as Me,e as Ce,f as yt,g as St,h as wt}from"./chunk-RXZ4Q7CY.mjs";var Oe=new WeakMap;function nr(e,t){return Oe.set(e,t),()=>{Oe.get(e)===t&&Oe.delete(e)}}function vt(e){Oe.get(e)?.()}var kt=new WeakMap;function $e(e){let t=kt.get(e);return t||(t={state:"active",listeners:new Set},kt.set(e,t)),t}function Ue(e){return e?$e(e).state:"active"}function _e(e){return Ue(e)==="paused"}function Fe(e,t){let o=$e(e);return o.listeners.add(t),()=>{o.listeners.delete(t)}}function ir(e,t){let o=$e(e);o.state!==t&&(o.state=t,o.listeners.forEach(n=>n()))}async function re(e,t,o){if(Ue(e)==="disconnected")throw new Error("The camera is disconnected from the viewer.");vt(e);let n=async()=>{await t(!1),e.update(0)};if(_e(e))return n();if(!o){await t(!1);return}let r=[];try{await new Promise((a,s)=>{let i=!1,c=l=>{i||(i=!0,l())};if(r.push(Fe(e,()=>{let l=Ue(e);l==="paused"?n().then(()=>c(a),f=>c(()=>s(f))):l==="disconnected"&&c(()=>s(new Error("The camera move was cancelled because the viewer disconnected.")))})),e.addEventListener&&e.removeEventListener){let l=!1,f=()=>{l=!0},u=()=>{l&&c(a)};e.addEventListener("update",f),e.addEventListener("sleep",u),r.push(()=>{e.removeEventListener?.("update",f),e.removeEventListener?.("sleep",u)})}Promise.resolve().then(()=>t(!0)).then(()=>c(a),l=>c(()=>s(l)))})}finally{r.forEach(a=>a())}}import{useCallback as Z,useRef as de,useState as He,useSyncExternalStore as Un}from"react";import{Vector3 as Et}from"three";var qe=new WeakSet;function me(e){qe.add(e)}function sr(e){let t=qe.has(e);return t&&qe.delete(e),t}var We=new WeakSet;function lr(e,t){t?We.add(e):We.delete(e)}function Ot(e,t){return We.has(e)?0:t}import{Box3 as It,Matrix4 as Ln,PerspectiveCamera as Rt,Vector3 as Ge}from"three";function fr(e,t){let o=pt(e);if(!(e.camera instanceof Rt)||!t)return o;let n=t instanceof It?t:new It().setFromObject(t);return n.isEmpty()||(o.framing={aspect:e.camera.aspect,min:n.min.toArray(),max:n.max.toArray()}),o}function Tt(e,t){let o=t.camera,n=e.framing;if(!(o instanceof Rt)||!n||!(o.aspect>0)||Math.abs(o.aspect-n.aspect)<1e-6)return[...e.position];let r=new Ge(...e.position),a=new Ge(...e.target),s=r.clone().sub(a).normalize(),i=new Ln().lookAt(r,a,o.up).invert(),c=Math.tan((e.fov??o.fov)*Math.PI/360)/(e.zoom??o.zoom);if(!(c>0)||!Number.isFinite(c))return[...e.position];let l=0;for(let f of[n.min[0],n.max[0]])for(let u of[n.min[1],n.max[1]])for(let m of[n.min[2],n.max[2]]){let d=new Ge(f,u,m).sub(r).applyMatrix4(i);l=Math.max(l,Math.abs(d.x)/(c*o.aspect)+d.z,Math.abs(d.y)/c+d.z)}return r.addScaledVector(s,l*1.02).toArray()}function Bt(e){return[e.x,e.y,e.z]}function ne(e,t){let o=new Et,n=new Et;return t.getPosition(o),t.getTarget(n),{position:Bt(o),target:Bt(n),fov:"fov"in e&&typeof e.fov=="number"?e.fov:null,zoom:"zoom"in e&&typeof e.zoom=="number"?e.zoom:1,azimuthAngle:t.azimuthAngle,polarAngle:t.polarAngle}}function $n(e,t){return e?e.position[0]===t.position[0]&&e.position[1]===t.position[1]&&e.position[2]===t.position[2]&&e.target[0]===t.target[0]&&e.target[1]===t.target[1]&&e.target[2]===t.target[2]&&e.fov===t.fov&&e.zoom===t.zoom&&e.azimuthAngle===t.azimuthAngle&&e.polarAngle===t.polarAngle:!1}async function ue(e,t,o=.6){let n=e.smoothTime;e.smoothTime=Ot(e,o);try{await re(e,t,!0)}finally{e.smoothTime=n}}function jr(e={}){let t=de(e);t.current=e;let o=de(null),[n,r]=He(null),a=Z(y=>n?Fe(n,y):()=>{},[n]),s=Z(()=>_e(n),[n]),i=Un(a,s,()=>!1),[c,l]=He(null),[f,u]=He(()=>({...e.presets})),m=de(f);m.current=f;let d=Z(y=>{l(x=>$n(x,y)?x:y)},[]),p=Z(y=>{d(y)},[d]),M=de(null),b=de(null),S=de(null),A=Z(y=>{o.current=y,r(y.raw.controls);let x=ne(y.raw.controls.camera,y.raw.controls);d(x),y.raw.scene!==b.current&&(b.current=y.raw.scene,M.current=null,S.current=null),y.homeCameraState&&!M.current&&(M.current=y.homeCameraState);let{initialPosition:j,initialTarget:B,initialTransition:q=!1}=t.current;if((j||B)&&y.raw.scene&&(j||y.homeCameraState)&&S.current!==y.raw.controls){S.current=y.raw.controls,y.homeCameraState||me(y.raw.controls);let W=j??x.position,K=B??x.target;re(y.raw.controls,J=>y.raw.controls.setLookAt(W[0],W[1],W[2],K[0],K[1],K[2],J),q).then(()=>{if(o.current?.raw.controls!==y.raw.controls)return;let J=ne(y.raw.controls.camera,y.raw.controls);M.current={position:J.position,target:J.target},d(J)}).catch(()=>{})}},[d]),g=Z(async()=>{let y=o.current,x=y?.raw.controls;if(!x)return!1;try{let j=M.current;if(j){gt(x,j);let B=Tt(j,x);await ue(x,q=>x.setLookAt(B[0],B[1],B[2],j.target[0],j.target[1],j.target[2],q))}else y?.raw.scene?await ue(x,B=>x.fitToBox(y.raw.scene,B,{paddingTop:.5,paddingBottom:.5,paddingLeft:.5,paddingRight:.5})):await ue(x,B=>x.reset(B));return!0}catch{return!1}},[]),w=Z(async()=>{let y=o.current;if(!y?.raw.controls||!y.raw.scene)return!1;try{return await ue(y.raw.controls,x=>y.raw.controls.fitToBox(y.raw.scene,x,{paddingTop:.5,paddingBottom:.5,paddingLeft:.5,paddingRight:.5})),!0}catch{return!1}},[]),v=Z(async y=>{let x=o.current;if(!x?.raw.controls)return!1;let j=ft(x.objectBindings,y);if(!j)return!1;let B=x.objectBindings[j]?.cameraState;if(B?.position&&B?.target){let[W,K,J]=B.position,[_,I,U]=B.target;try{return await ue(x.raw.controls,L=>x.raw.controls.setLookAt(W,K,J,_,I,U,L)),!0}catch{return!1}}let q=x.raw.nodes[j];if(!q)return!1;try{return await ue(x.raw.controls,W=>x.raw.controls.fitToBox(q,W,{paddingTop:.5,paddingBottom:.5,paddingLeft:.5,paddingRight:.5})),!0}catch{return!1}},[]),P=Z(async(y,x=!0)=>{let j=o.current?.raw.controls;if(!j)return!1;try{return o.current?.homeCameraState||me(j),await re(j,B=>j.setTarget(y[0],y[1],y[2],B),x),d(ne(j.camera,j)),!0}catch{return!1}},[d]),T=Z(async(y,x=!0)=>{let j=o.current?.raw.controls;if(!j)return!1;try{o.current?.homeCameraState||me(j),await re(j,async W=>{let K=[j.setLookAt(y.position[0],y.position[1],y.position[2],y.target[0],y.target[1],y.target[2],W)];y.azimuthAngle!=null&&y.polarAngle!=null&&K.push(j.rotateTo(y.azimuthAngle,y.polarAngle,W)),await Promise.all(K)},x);let B=j.camera,q=!1;return y.fov!=null&&"fov"in B&&typeof B.fov=="number"&&(B.fov=y.fov,q=!0),y.zoom!=null&&"zoom"in B&&typeof B.zoom=="number"&&(B.zoom=y.zoom,q=!0),q&&"updateProjectionMatrix"in B&&B.updateProjectionMatrix(),d(ne(B,j)),!0}catch{return!1}},[d]),N=Z((y,x=!0)=>T(y,x),[T]),O=Z((y,x,j=!0)=>T({position:y,target:x},j),[T]),h=Z(async(y,x,j=!0)=>{let B=o.current?.raw.controls;if(!B)return!1;try{return o.current?.homeCameraState||me(B),await re(B,q=>B.rotateTo(y*Math.PI/180,x*Math.PI/180,q),j),d(ne(B.camera,B)),!0}catch{return!1}},[d]),C=Z(async(y,x=!0)=>{let j=o.current?.raw.controls;if(!j)return!1;try{return o.current?.homeCameraState||me(j),await re(j,B=>j.dollyTo(y,B),x),d(ne(j.camera,j)),!0}catch{return!1}},[d]),k=Z(y=>{let x={...y};m.current=x,u(x)},[]),E=Z(y=>{let x=o.current?.raw.controls,j=y.trim();if(!x||!j)return null;let B=ne(x.camera,x);return m.current={...m.current,[j]:B},u(q=>({...q,[j]:B})),d(B),B},[d]),V=Z((y,x=!0)=>{let j=m.current[y];return j?T(j,x):Promise.resolve(!1)},[T]);return{isRenderPaused:i,cameraState:c,cameraPresets:f,setCameraPresets:k,resetView:g,focusObject:v,fitScene:w,setCameraTarget:P,setCameraState:N,lookAt:O,orbitTo:h,dollyTo:C,savePreset:E,goToPreset:V,handleCameraChange:p,handleViewerReady:A}}function kr(e){let t=e.trim();return t?/\.(hdr|exr|jpg|jpeg|png|webp)(?:[?#].*)?$/i.test(t):!1}var Or=["none","directional","point","spot","hemisphere"],Ir=["pbr","matcap","uv-checker"],Rr=["neutral","apartment","city","dawn","forest","lobby","night","park","studio","sunset","warehouse"];var Tr=["sporadic","constantMild","constantWild"],Er=["linear","radial","mirroredLinear"],Br=["verySmall","small","medium","large","veryLarge","huge"];var Xe={enabled:!1,axis:"y",position:.5,flip:!1},_n={clips:[],autoplayClip:null},Fn={autofocus:{enabled:!1,focusDistance:5,focusRange:5,focalLength:.02,bokehScale:6,target:[0,0,0],mouse:!0,debug:0,manual:!1,smoothTime:.25},toneMapping:{enabled:!1,mode:"aces",exposure:1,resolution:256,whitePoint:4,middleGrey:.6,minLuminance:.01,averageLuminance:1,adaptationRate:1},brightnessContrast:{enabled:!1,brightness:0,contrast:0},hueSaturation:{enabled:!1,hue:0,saturation:0},colorAverage:{enabled:!1},dotScreen:{enabled:!1,angle:Math.PI/2,scale:1},glitch:{enabled:!1,mode:"sporadic",delay:[1.5,3.5],duration:[.6,1],strength:[.3,1],chromaticAberrationOffset:[0,0],columns:.05,ratio:.85},ssao:{enabled:!1,samples:30,rings:4,intensity:8,radius:.25,bias:.025,luminanceInfluence:.6,fade:.01,minRadiusScale:.33,worldDistanceThreshold:20,worldDistanceFalloff:5,worldProximityThreshold:6,worldProximityFalloff:3},bloom:{enabled:!1,intensity:.3,luminanceThreshold:.9,luminanceSmoothing:.2,mipmapBlur:!0,radius:0,levels:8},godRays:{enabled:!1,sunPosition:[5,10,5],samples:60,density:.96,decay:.9,weight:.4,exposure:.6,clampMax:1,blur:!0,kernelSize:"small"},grid:{enabled:!1,scale:1,lineWidth:0},noise:{enabled:!1,opacity:1,premultiply:!1},depthOfField:{enabled:!1,focusDistance:5,focusRange:5,focalLength:.02,bokehScale:6},chromaticAberration:{enabled:!1,offsetX:.002,offsetY:.002,radialModulation:!1,modulationOffset:.15},lensflare:{enabled:!1,lensPosition:[-25,6,-60],smoothTime:.07,glareSize:.2,flareSize:.01,flareSpeed:.01,flareShape:.01,animated:!0,anamorphic:!1,colorGain:"#141414",haloScale:.5,secondaryGhosts:!0,aditionalStreaks:!0,ghostScale:0,opacity:1,starBurst:!1},vignette:{enabled:!1,offset:.3,darkness:.3,eskil:!1},smaa:{enabled:!1},sepia:{enabled:!1,intensity:0},scanline:{enabled:!1,density:1.25},pixelation:{enabled:!1,granularity:5},outline:{enabled:!1,selectionLayer:10,edgeStrength:2.5,pulseSpeed:0,visibleEdgeColor:"#ffffff",hiddenEdgeColor:"#22090a",kernelSize:"large",blur:!1,xRay:!0},selectiveBloom:{enabled:!1,selectionLayer:10,intensity:1,luminanceThreshold:.9,luminanceSmoothing:.025,kernelSize:"large",mipmapBlur:!0,inverted:!1,ignoreBackground:!1},ramp:{enabled:!1,rampType:"linear",rampStart:[.5,.5],rampEnd:[1,1],startColor:"#000000",endColor:"#ffffff",opacity:.5,rampBias:.5,rampGain:.5,rampMask:!1,rampInvert:!1}},fe={model:{rotation:[0,0,0],showAdvancedRotation:!1,renderer:"pbr",shading:"lit",autoRotate:!1,autoRotateSpeed:1},camera:{fieldOfView:50,showAdvancedSettings:!1},lighting:{ambient:{intensity:.25,color:"#ffffff"},lights:[{id:"light-hemi",type:"hemisphere",color:"#ffffff",intensity:.3,position:[0,1,0],attachedToCamera:!1,castShadow:!1,shadowBias:-5e-4,visible:!0},{id:"light-key",type:"directional",color:"#ffffff",intensity:2.5,position:[3,6,3],attachedToCamera:!1,castShadow:!0,shadowBias:-5e-4,visible:!0},{id:"light-fill",type:"directional",color:"#ffffff",intensity:0,position:[-3,4,-3],attachedToCamera:!1,castShadow:!1,shadowBias:-5e-4,visible:!0}]},shadows:{enabled:!0,mapSize:2048,bias:-5e-4,normalBias:.02,radius:3},environment:{source:"preset",preset:"neutral",customEnvironmentUrl:"",intensity:.25,rotation:0,shadowLight:{enabled:!1,intensity:2.5,bias:-5e-4}},wireframe:{enabled:!1,color:"#000000",opacity:1},background:{enabled:!1,type:"color",color:"#1c1c1d",imageUrl:""},groundShadows:{enabled:!1,mode:"shadowCatcher",intensity:.7,borderFade:1,height:0,size:10},postProcessing:Fn,animations:_n,annotations:[]};function be(e){let t=f=>{throw new Error(`Invalid section: ${f}`)},o=f=>f&&typeof f=="object"&&!Array.isArray(f)?f:t("expected an object"),n=f=>typeof f=="string"&&f.trim().length>0&&f.length<=200?f:t("expected a nonempty name or id (up to 200 characters)"),r=f=>typeof f=="number"&&Number.isFinite(f)&&f>=0&&f<=1?f:t("position must be between 0 and 1"),a=f=>!Array.isArray(f)||f.length!==3||!f.every(u=>typeof u=="number"&&Number.isFinite(u))||Math.hypot(...f)<1e-8?t("normal must be a finite, nonzero vector"):[...f],s=f=>{let u=o(f);return!["x","y","z"].includes(u.axis)||typeof u.enabled!="boolean"||typeof u.flip!="boolean"?t("invalid plane"):{enabled:u.enabled,axis:u.axis,position:r(u.position),flip:u.flip,...u.normal!==void 0?{normal:a(u.normal)}:{}}},i=f=>{let u=o(f),m=s(u);if(u.mode!==void 0){if(!["plane","planes","box"].includes(u.mode))return t("invalid mode");m.mode=u.mode}if(u.planes!==void 0){if(!Array.isArray(u.planes)||u.planes.length>6)return t("at most six planes are supported");let d=new Set;m.planes=u.planes.map(p=>{let M=o(p),b=n(M.id);return d.has(b)?t("duplicate plane id"):(d.add(b),{...s(M),id:b,name:n(M.name)})})}if(u.activePlaneId!==void 0&&(m.activePlaneId=n(u.activePlaneId)),u.invertBox!==void 0){if(typeof u.invertBox!="boolean")return t("invalid box inversion");m.invertBox=u.invertBox}if(u.box!==void 0){let d=o(u.box),p=S=>!Array.isArray(S)||S.length!==3?t("invalid box bounds"):S.map(r),M=p(d.min),b=p(d.max);if(M.some((S,A)=>S>=b[A]))return t("box minimum must be below its maximum on every axis");m.box={min:M,max:b}}return m},c=o(e),l=i(c);if(c.presets!==void 0){if(!Array.isArray(c.presets)||c.presets.length>32)return t("at most 32 presets are supported");let f=new Set;l.presets=c.presets.map(u=>{let m=o(u),d=n(m.id);return f.has(d)?t("duplicate preset id"):(f.add(d),{id:d,name:n(m.name),settings:i(m.settings)})})}return l}function Vr(e){let{presets:t,...o}=be(e);return o}function zr(e){try{return be(e)}catch{return Xe}}function Dr(e,t){if(!t||typeof t!="object"||Array.isArray(t))throw new Error("Invalid section: expected an object");let o=["enabled","axis","position","flip"].every(n=>Object.prototype.hasOwnProperty.call(t,n));return be(o?t:{...Xe,...e,...t})}import{Box3 as Pt,Matrix4 as Re,Quaternion as qn,Vector3 as Ie,Euler as Wn}from"three";var $r={version:1,placements:{},gridSize:1};function Ke(e){return e.id??e.url}function he(e){if(!e||typeof e!="object"||Array.isArray(e))throw new Error("Expected an asset transform object.");let t={};for(let o of["position","rotation","scale"]){let n=e[o];if(n!==void 0){if(!Array.isArray(n)||n.length!==3||!n.every(r=>typeof r=="number"&&Number.isFinite(r))||o==="scale"&&n.some(r=>r===0))throw new Error(`Invalid asset ${o}: expected three finite ${o==="scale"?"nonzero ":""}numbers.`);t[o]=[...n]}}return t}function _r(e){if(!e||typeof e!="object"||Array.isArray(e))throw new Error("Invalid scene composition.");let t=e;if(t.version!==1||!Number.isFinite(t.gridSize)||t.gridSize<=0||!t.placements||typeof t.placements!="object"||Array.isArray(t.placements)||Object.keys(t.placements).length>256)throw new Error("Invalid scene composition version, grid size or placements (maximum 256).");let o={};for(let[n,r]of Object.entries(t.placements)){if(!n||["__proto__","constructor","prototype"].includes(n))throw new Error("Invalid asset instance ID.");let a=he(r);if(r.label!==void 0&&(typeof r.label!="string"||r.label.length>512))throw new Error("Invalid asset label.");for(let s of["visible","deleted"])if(r[s]!==void 0&&typeof r[s]!="boolean")throw new Error(`Invalid asset ${s}.`);o[n]={...a,...r.label!==void 0?{label:r.label}:{},...r.visible!==void 0?{visible:r.visible}:{},...r.deleted!==void 0?{deleted:r.deleted}:{}}}return{version:1,gridSize:t.gridSize,placements:o}}function Fr(e,t){if(!Number.isFinite(t)||t<=0)throw new Error("Grid size must be positive.");let o=he(e),[n,r,a]=o.position??[0,0,0];return{...o,position:[Math.round(n/t)*t,r,Math.round(a/t)*t]}}function qr(e,t){let o=he(e),n=o.position??[0,0,0],r=new Re().compose(new Ie(...n),new qn().setFromEuler(new Wn(...o.rotation??[0,0,0])),new Ie(...o.scale??[1,1,1])),a=new Pt(new Ie(...t.min),new Ie(...t.max)).applyMatrix4(r);if(!Number.isFinite(a.min.y))throw new Error("Cannot place an asset with empty bounds.");return{...o,position:[n[0],n[1]-a.min.y,n[2]]}}function Wr(e){e.updateWorldMatrix(!0,!0);let t=new Re().copy(e.parent?.parent?.matrixWorld??new Re).invert(),o=new Pt;return e.traverse(n=>{let r=n;r.geometry&&(r.geometry.computeBoundingBox(),r.geometry.boundingBox&&o.union(r.geometry.boundingBox.clone().applyMatrix4(new Re().multiplyMatrices(t,r.matrixWorld))))}),o.isEmpty()||![...o.min.toArray(),...o.max.toArray()].every(Number.isFinite)?null:{min:o.min.toArray(),max:o.max.toArray()}}import{BufferGeometry as Gn,Float32BufferAttribute as Hn,Matrix4 as Vt,Mesh as Ze,ShapeUtils as Xn,Vector2 as zt,Vector3 as H,Vector4 as Kn}from"three";function Dt(e){if(e.length!==3)return null;let t=new H(...e[0]).sub(new H(...e[1])),o=new H(...e[2]).sub(new H(...e[1]));return t.lengthSq()===0||o.lengthSq()===0?null:Math.acos(Math.max(-1,Math.min(1,t.normalize().dot(o.normalize()))))*180/Math.PI}function Lt(e,t){if(!e.normal)return null;let o=new H(...e.normal);if(o.lengthSq()===0)return null;o.normalize();let n=new H(...t),r=n.clone().sub(new H(...e.position)).dot(o);return{distance:Math.abs(r),projection:n.addScaledVector(o,-r).toArray()}}function Ut(e){if(e.length<3)return{error:"Pick at least three points to finish the area."};let t=new H(...e[0]),o=e.map(b=>new H(...b).sub(t)),n=Math.max(...o.map(b=>b.length()));if(n===0)return{error:"Area points must be distinct."};let r=new H;for(let b=1;b<o.length-1;b+=1){let S=o[b].clone().cross(o[b+1]);S.lengthSq()>r.lengthSq()&&r.copy(S)}if(r.length()<=n*n*1e-10)return{error:"Area points must not lie on one straight line."};r.normalize();let a=Math.max(n*1e-5,Number.EPSILON*Math.max(...e.flat().map(Math.abs))*32);if(o.some(b=>Math.abs(b.dot(r))>a))return{error:"Area points must lie on one plane."};let s=o.find(b=>b.length()>n*1e-10).clone().normalize(),i=r.clone().cross(s).normalize(),c=o.map(b=>new zt(b.dot(s),b.dot(i))),l=(b,S,A)=>(S.x-b.x)*(A.y-b.y)-(S.y-b.y)*(A.x-b.x),f=n*n*1e-10,u=(b,S,A)=>Math.abs(l(b,S,A))<=f&&A.x>=Math.min(b.x,S.x)-n*1e-10&&A.x<=Math.max(b.x,S.x)+n*1e-10&&A.y>=Math.min(b.y,S.y)-n*1e-10&&A.y<=Math.max(b.y,S.y)+n*1e-10;for(let b=0;b<c.length;b+=1){let S=c[b],A=c[(b+1)%c.length];if(S.distanceTo(A)<=n*1e-10)return{error:"Area points must be distinct."};for(let g=b+1;g<c.length;g+=1){if(g===b+1||b===0&&g===c.length-1)continue;let w=c[g],v=c[(g+1)%c.length],P=l(S,A,w),T=l(S,A,v),N=l(w,v,S),O=l(w,v,A);if(P*T<0&&N*O<0||u(S,A,w)||u(S,A,v)||u(w,v,S)||u(w,v,A))return{error:"Area edges must not cross or touch each other."}}}let m=0,d=0,p=0;for(let b=0;b<c.length;b+=1){let S=c[b],A=c[(b+1)%c.length],g=S.x*A.y-A.x*S.y;m+=g,d+=(S.x+A.x)*g,p+=(S.y+A.y)*g}if(Math.abs(m)<=f)return{error:"The polygon has no measurable area."};let M=t.clone().addScaledVector(s,d/(3*m)).addScaledVector(i,p/(3*m));return{area:Math.abs(m)/2,center:M.toArray(),triangles:Xn.triangulateShape(c,[])}}function Ye(e,t){if(e.length<2)return 0;let o=0;for(let n=1;n<e.length;n+=1)o+=new H(...e[n]).distanceTo(new H(...e[n-1]));return t&&(o+=new H(...e[e.length-1]).distanceTo(new H(...e[0]))),o}var Zn=1e-5;function Yn(e,t){let o=e.getAttribute("position"),n=e.getIndex(),r=o.count,a=Math.max(t,1e-9),s=(p,M,b)=>`${Math.round(p/a)}_${Math.round(M/a)}_${Math.round(b/a)}`,i=new Int32Array(r),c=[],l=new Map;for(let p=0;p<r;p+=1){let M=o.getX(p),b=o.getY(p),S=o.getZ(p),A=s(M,b,S),g=l.get(A);g===void 0&&(g=c.length,c.push(new H(M,b,S)),l.set(A,g)),i[p]=g}let f=c.map(()=>new Map),u=(p,M)=>{if(p===M)return;let b=c[p].distanceTo(c[M]);f[p].has(M)||f[p].set(M,b),f[M].has(p)||f[M].set(p,b)},m=(n?n.count:r)/3,d=p=>n?n.getX(p):p;for(let p=0;p<m;p+=1)u(i[d(p*3)],i[d(p*3+1)]),u(i[d(p*3+1)],i[d(p*3+2)]),u(i[d(p*3+2)],i[d(p*3)]);return{weldedId:i,weldedPosition:c,neighbors:f}}function Jn(e,t,o){let n=new Map([[t,0]]),r=[t];for(let a=0;a<o&&r.length>0;a+=1){let s=[];for(let i of r){let c=n.get(i)??0;for(let[l,f]of e[i]??[])n.has(l)||(n.set(l,c+f),s.push(l))}r=s}return n}function Qn(e){let o=(Math.abs(e.y)<.9?new H(0,1,0):new H(1,0,0)).clone().cross(e).normalize(),n=e.clone().cross(o).normalize();return[o,n]}function eo(e,t,o){let[n,r]=Qn(t),a=0,s=0,i=0;for(let M of o){let b=M.clone().sub(e),S=b.dot(n),A=b.dot(r);a+=S*S,s+=S*A,i+=A*A}let c=a+i,l=a*i-s*s,f=Math.sqrt(Math.max(0,c*c/4-l)),u=c/2+f,m=1,d=0;Math.abs(s)>1e-12?(m=u-i,d=s):i>a&&(m=0,d=1);let p=Math.hypot(m,d)||1;return n.clone().multiplyScalar(m/p).add(r.clone().multiplyScalar(d/p)).normalize()}function to(e,t,o,n){let r=e.getAttribute("position"),a=e.getIndex(),s=r.count,i=(a?a.count:s)/3,c=m=>a?a.getX(m):m,l=m=>new H(r.getX(m),r.getY(m),r.getZ(m)).applyMatrix4(t),f=m=>m.clone().sub(o).dot(n),u=[];for(let m=0;m<i;m+=1){let d=l(c(m*3)),p=l(c(m*3+1)),M=l(c(m*3+2)),b=f(d),S=f(p),A=f(M),g=[],w=(v,P,T,N)=>{P>0!=N>0&&g.push(v.clone().lerp(T,P/(P-N)))};w(d,b,p,S),w(p,S,M,A),w(M,A,d,b),g.length===2&&u.push([g[0],g[1]])}return u}function no(e,t){let o=Math.max(t,1e-9),n=m=>`${Math.round(m.x/o)}_${Math.round(m.y/o)}_${Math.round(m.z/o)}`,r=new Map,a=[],s=m=>{let d=n(m),p=r.get(d);return p===void 0&&(p=a.length,a.push(m),r.set(d,p)),p},i=[],c=m=>{for(;i.length<=m;)i.push(new Map)};for(let[m,d]of e){let p=s(m),M=s(d);p!==M&&(c(p),c(M),i[p].set(M,(i[p].get(M)??0)+1),i[M].set(p,(i[M].get(p)??0)+1))}let l=(m,d)=>m<d?`${m}_${d}`:`${d}_${m}`,f=new Set,u=[];for(let m=0;m<i.length;m+=1)for(let d of i[m]?.keys()??[]){if(f.has(l(m,d)))continue;let p=[m],M=m,b=d;f.add(l(M,b));let S=0;for(;b!==m&&b>=0&&S<i.length+4;){p.push(b);let A=[...i[b].keys()].filter(w=>w!==M),g;if(A.length<=1)g=A[0];else{let w=a[b].clone().sub(a[M]).normalize(),v=-1/0;for(let P of A){let T=a[P].clone().sub(a[b]).normalize(),N=w.dot(T);N>v&&(v=N,g=P)}}if(g===void 0){b=-1;break}f.add(l(b,g)),M=b,b=g,S+=1}b===m&&p.length>=3&&u.push(p.map(A=>a[A]))}return u}function Nt(e,t){let o=1/0;for(let n of e)o=Math.min(o,n.distanceTo(t));return o}function oo(e,t){let o=0,n=1/0;return e.forEach((r,a)=>{let s=r.distanceTo(t);s<n&&(n=s,o=a)}),[...e.slice(o),...e.slice(0,o)]}function $t(e,t,o,n,r){let a=to(e,t,n,r);if(a.length===0)return{error:"Couldn't trace a loop around this point."};let s=no(a,o*t.getMaxScaleOnAxis());if(s.length===0)return{error:"The surface here doesn't form a closed loop around this point (it may be near an open edge)."};let i=s[0],c=Nt(i,n);for(let f of s.slice(1)){let u=Nt(f,n);u<c&&(c=u,i=f)}let l=oo(i,n).map(f=>f.toArray());return{points:l,length:Ye(l,!0)}}function _t(e){if(!(e.object instanceof Ze)||!e.face)return null;let t=e.object,o=t.geometry;if(t.isSkinnedMesh||t.morphTargetInfluences?.some(a=>a!==0)){let a=o.getAttribute("position"),s=new Hn(new Float32Array(a.count*3),3),i=new H;for(let c=0;c<a.count;c++)t.getVertexPosition(c,i),s.setXYZ(c,i.x,i.y,i.z);o=new Gn().setAttribute("position",s).setIndex(o.getIndex())}let n=t.matrixWorld.clone();if(e.instanceId!==void 0&&"getMatrixAt"in t){let a=new Vt;t.getMatrixAt(e.instanceId,a),n.multiply(a)}o.computeBoundingSphere();let r=o.boundingSphere&&o.boundingSphere.radius>0?o.boundingSphere.radius:1;return{face:e.face,geometry:o,matrix:n,weldTolerance:r*Zn}}function Xr(e,t=6){let o=_t(e);if(!o)return{error:"Pick a point on the mesh surface to trace a loop around it."};let{face:n,geometry:r,matrix:a,weldTolerance:s}=o,i=Ft(e);if(!i)return{error:"Pick a point on the mesh surface to trace a loop around it."};let c=i[1].clone().sub(i[0]).cross(i[2].clone().sub(i[0]));if(c.lengthSq()===0)return{error:"Couldn't determine the surface direction at this point."};c.normalize();let{weldedId:l,weldedPosition:f,neighbors:u}=Yn(r,s),m=r.getAttribute("position"),d=e.point.clone().applyMatrix4(a.clone().invert()),p=[n.a,n.b,n.c],M=p[0],b=1/0;for(let P of p){let N=new H(m.getX(P),m.getY(P),m.getZ(P)).distanceTo(d);N<b&&(b=N,M=P)}let S=l[M],A=f[S].clone().applyMatrix4(a),g=Jn(u,S,t),w=[];for(let P of g.keys())w.push(f[P].clone().applyMatrix4(a));if(w.length<6)return{error:"Not enough surface detail near this point to trace a loop. Try a different spot."};let v=eo(A,c,w);return $t(r,a,s,e.point.clone(),v)}function Kr(e,t=new H(0,1,0)){let o=_t(e);if(!o)return{error:"Pick a point on the mesh surface to trace a loop around it."};let{geometry:n,matrix:r,weldTolerance:a}=o,s=t.clone().normalize();return s.lengthSq()===0?{error:"Couldn't determine a horizontal direction."}:$t(n,r,a,e.point.clone(),s)}function Ft(e){if(!(e.object instanceof Ze)||!e.face)return null;let t=e.object,o=t.matrixWorld.clone();if(e.instanceId!==void 0&&"getMatrixAt"in t){let n=new Vt;t.getMatrixAt(e.instanceId,n),o.multiply(n)}return[e.face.a,e.face.b,e.face.c].map(n=>t.getVertexPosition(n,new H).applyMatrix4(o))}function Zr(e){if(!(e.object instanceof Ze))return!1;for(let o=e.object;o;o=o.parent)if(!o.visible||o.userData.riEditorGizmo||o.userData.riDecal)return!1;return(Array.isArray(e.object.material)?e.object.material:[e.object.material])[e.face?.materialIndex??0]?.visible!==!1}function Yr(e,t,o,n,r,a=12){let s=Ft(e),i=s?s[1].clone().sub(s[0]).cross(s[2].clone().sub(s[0])).normalize():null,c={position:e.point.toArray(),...i&&i.lengthSq()>0?{normal:i.toArray()}:{},...s?{faceVertices:s.map(m=>m.toArray())}:{}};if(!s||r==="none")return c;let l=m=>{let d=new Kn(m.x,m.y,m.z,1).applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix);return d.w<=0||d.z/d.w<-1||d.z/d.w>1?null:{screen:new zt((d.x/d.w+1)*n.width/2,(1-d.y/d.w)*n.height/2),w:d.w}},f=s.map(l),u=a;if((r==="vertex"||r==="auto")&&(f.forEach((m,d)=>{let p=m?.screen.distanceTo(o)??1/0;p<=u&&(u=p,c.position=s[d].toArray(),c.snapped="vertex")}),c.snapped))return c;if(r==="edge"||r==="auto")for(let m=0;m<3;m+=1){let d=(m+1)%3,p=f[m],M=f[d];if(!p||!M)continue;let b=M.screen.clone().sub(p.screen);if(b.lengthSq()===0)continue;let S=Math.max(0,Math.min(1,o.clone().sub(p.screen).dot(b)/b.lengthSq())),A=p.screen.clone().addScaledVector(b,S).distanceTo(o);if(A<=u){u=A;let g=S*p.w/((1-S)*M.w+S*p.w);c.position=s[m].clone().lerp(s[d],g).toArray(),c.snapped="edge"}}return c}var ro=["m","cm","mm","in","ft"],Je={m:1,cm:.01,mm:.001,in:.0254,ft:.3048},io=["distance","angle","area","pointToPlane","wrap","wrapHorizontal"];function Qe(e){return ro.includes(e)}function ao(e={},t="m"){let o=e.displayUnit??t,n=e.metersPerUnit??Je[e.sourceUnit??"m"];if(!Number.isFinite(n)||n<=0)throw new Error("Measurement scale must be a positive finite number.");return{displayUnit:o,metersPerUnit:n,factor:Qe(o)?n/Je[o]:1}}function ei(e){try{return new URL(e,typeof window<"u"?window.location?.href:void 0).href}catch{return e}}function ti(e,t,o,n={}){if(!Qe(o)||!Number.isFinite(e)||e<=0||!Number.isFinite(t)||t<=0)throw new Error("Calibration needs two distinct points and a positive known distance.");let r=t*Je[o]/e;if(!Number.isFinite(r)||r<=0)throw new Error("Calibration scale is outside the supported range.");return{...n,metersPerUnit:r}}function qt(e,t){let o=t.map(n=>n.position);if(e==="angle"){let n=Dt(o);return n===null?null:{value:n,dimension:0}}if(e==="area"){let n=Ut(o);return"error"in n?null:{value:n.area,dimension:2}}if(e==="pointToPlane"){let n=t.length===2?Lt(t[0],t[1].position):null;return n?{value:n.distance,dimension:1}:null}return t.length<(e==="distance"?2:3)?null:{value:Ye(o,e!=="distance"),dimension:1}}function so(e,t={},o="m",n=e.points,r=e.approximate?"approximate":"ready"){let a=qt(e.tool,n),{factor:s,displayUnit:i}=ao(t,o),c=r==="ready"||r==="approximate",l=c&&a?a.value*s**a.dimension:null;return{id:e.id,status:c?a&&l!==null&&Number.isFinite(l)?r:"invalid":r,rawValue:c&&a&&Number.isFinite(a.value)?a.value:null,value:l!==null&&Number.isFinite(l)?l:null,unit:e.tool==="angle"?"\xB0":e.tool==="area"?`${i}\xB2`:i}}function ye(e){function t(){throw new Error("Invalid measurements: expected settings and valid named measurements with finite points.")}let o=i=>!!i&&typeof i=="object"&&!Array.isArray(i),n=i=>Array.isArray(i)&&i.length===3&&i.every(c=>typeof c=="number"&&Number.isFinite(c));typeof e=="string"&&(e.length>5*1024*1024&&t(),e=JSON.parse(e)),(!o(e)||e.version!==void 0&&e.version!==1||!o(e.settings)||!Array.isArray(e.items)||e.items.length>256)&&t();let r={};for(let i of["sourceUnit","displayUnit"])e.settings[i]!==void 0&&(Qe(e.settings[i])||t(),r[i]=e.settings[i]);e.settings.metersPerUnit!==void 0&&((typeof e.settings.metersPerUnit!="number"||!Number.isFinite(e.settings.metersPerUnit)||e.settings.metersPerUnit<=0)&&t(),r.metersPerUnit=e.settings.metersPerUnit);let a=new Set,s=e.items.map(i=>{(!o(i)||typeof i.id!="string"||!i.id||a.has(i.id)||typeof i.name!="string"||!i.name.trim()||typeof i.modelId!="string"||!i.modelId||!io.includes(i.tool)||!Array.isArray(i.points)||i.points.length>8192||typeof i.createdAt!="string"||!Number.isFinite(Date.parse(i.createdAt)))&&t(),a.add(i.id),i.tilesetUrl!==void 0&&i.tilesetUrl!==null&&typeof i.tilesetUrl!="string"&&t(),(i.visible!==void 0&&typeof i.visible!="boolean"||i.approximate!==void 0&&typeof i.approximate!="boolean")&&t();let c=new Set,l=i.points.map(u=>{if((!o(u)||typeof u.id!="number"||!Number.isFinite(u.id)||!n(u.position))&&t(),c.has(u.id)&&t(),c.add(u.id),u.normal!==void 0&&!n(u.normal)&&t(),u.faceVertices!==void 0&&(!Array.isArray(u.faceVertices)||u.faceVertices.length!==3||!u.faceVertices.every(n))&&t(),u.snapped!==void 0&&!["vertex","edge"].includes(u.snapped)&&t(),u.anchor!==void 0){let d=u.anchor;(!o(d)||typeof d.nodeId!="string"||!d.nodeId||!n(d.localPosition)||typeof d.geometrySignature!="string"||typeof d.poseSignature!="string")&&t(),d.localNormal!==void 0&&!n(d.localNormal)&&t(),d.localFaceVertices!==void 0&&(!Array.isArray(d.localFaceVertices)||d.localFaceVertices.length!==3||!d.localFaceVertices.every(n))&&t(),d.instanceId!==void 0&&(!Number.isInteger(d.instanceId)||d.instanceId<0)&&t()}let m=u.anchor;return{id:u.id,position:[...u.position],...u.normal?{normal:[...u.normal]}:{},...u.faceVertices?{faceVertices:u.faceVertices.map(d=>[...d])}:{},...u.snapped?{snapped:u.snapped}:{},...m?{anchor:{nodeId:m.nodeId,localPosition:[...m.localPosition],geometrySignature:m.geometrySignature,poseSignature:m.poseSignature,...m.localNormal?{localNormal:[...m.localNormal]}:{},...m.localFaceVertices?{localFaceVertices:m.localFaceVertices.map(d=>[...d])}:{},...m.instanceId!==void 0?{instanceId:m.instanceId}:{}}}:{}}}),f={id:i.id,name:i.name,modelId:i.modelId,tool:i.tool,points:l,createdAt:i.createdAt,...i.tilesetUrl!==void 0?{tilesetUrl:i.tilesetUrl}:{},...i.visible!==void 0?{visible:i.visible}:{},...i.approximate!==void 0?{approximate:i.approximate}:{}};return qt(f.tool,l)||t(),f});return{settings:r,items:s}}function ni(e){return JSON.stringify({version:1,...ye(e)},null,2)}function oi(e,t,o="m"){let n=ye(e),r=new Map(t?.map(s=>[s.id,s])),a=s=>{let i=String(s??"");return/^[=+@-]/.test(i)&&(i=`'${i}`),`"${i.replace(/"/g,'""')}"`};return[["id","name","modelId","type","status","value","unit","createdAt"],...n.items.map(s=>{let i=r.get(s.id)??so(s,n.settings,o);return[s.id,s.name,s.modelId,s.tool,i.status,i.value,i.unit,s.createdAt]})].map(s=>s.map(a).join(",")).join(`\r
2
- `)}function Wt(e){if(!Array.isArray(e)||e.length>128)throw new Error("Invalid selections: expected up to 128 named selection sets.");let t=new Set;return e.map(o=>{if(!o||typeof o!="object"||typeof o.id!="string"||!o.id||t.has(o.id)||typeof o.name!="string"||!o.name.trim()||o.name.length>200||!Array.isArray(o.objectIds)||o.objectIds.length>1e5||o.objectIds.some(n=>typeof n!="string"||!n))throw new Error("Invalid selections: each set needs a unique id, a name, and model object ids.");return t.add(o.id),{id:o.id,name:o.name.trim(),objectIds:[...new Set(o.objectIds)]}})}var ie=5*1024*1024,co=["activeModelId","modelUrl","modelFormat","tilesetUrl","models","mergeModels","sceneConfig","isolation","multiSelectedKeys","activeAnnotation","annotationCategories","backgroundColor","shadows","cinematic","cameraControllerType","objectTransformSpace","arScaleMode","usdzUrl","measurements","measurementSettings","measurementUnit","measurementModelId"];function R(e,t){throw new Error(`Invalid viewer state at ${e}: ${t}`)}function X(e,t){(!e||typeof e!="object"||Array.isArray(e))&&R(t,"expected an object.")}function Se(e,t){(!Array.isArray(e)||!e.every(o=>typeof o=="string"))&&R(t,"expected strings.")}function ee(e,t,o){(!Array.isArray(e)||e.length!==t||!e.every(n=>typeof n=="number"&&Number.isFinite(n)))&&R(o,`expected ${t} finite numbers.`)}function lo(e){let t=new Set,o=0;function n(r,a,s){if((++o>2e5||s>64)&&R(a,"configuration is too complex."),r===null||typeof r=="string"||typeof r=="boolean"||typeof r=="number"&&Number.isFinite(r))return r;(typeof r!="object"||!r)&&R(a,"expected JSON data (finite numbers, no functions)."),t.has(r)&&R(a,"cyclic data."),!Array.isArray(r)&&Object.getPrototypeOf(r)!==Object.prototype&&Object.getPrototypeOf(r)!==null&&R(a,"expected plain JSON data."),t.add(r);let i=Array.isArray(r)?[]:{};for(let[c,l]of Object.entries(r))["__proto__","constructor","prototype"].includes(c)&&R(`${a}.${c}`,"reserved property."),l!==void 0?i[c]=n(l,`${a}.${c}`,s+1):Array.isArray(r)&&R(a,"undefined array entry.");return t.delete(r),i}return n(e,"state",0)}function te(e,t,o,n,r=!1,a){let s=e[t];if(s==null||s==="")return;typeof s!="string"&&R(o,"expected a URL.");let i=r?je(s)??s:s;if(i.trim().startsWith("blob:")){if(r&&a){a.set(s,{source:i,path:o});return}R(o,r?"this image is temporary. Use getStateAsync() for JSON or createShareUrl() to include it.":"upload this model/environment asset to a durable URL before saving or sharing.")}if(i!==s&&(s=i,e[t]=i),r&&/^data:image\//i.test(s))return;let c;try{c=new URL(s,n??"https://relative.invalid/")}catch{R(o,"invalid asset URL.")}["http:","https:"].includes(c.protocol)||R(o,"use an HTTP(S) asset URL."),n&&(e[t]=c.href)}function mo(e,t){X(e,t),ee(e.position,3,`${t}.position`),ee(e.target,3,`${t}.target`),(typeof e.zoom!="number"||e.zoom<=0)&&R(t,"zoom must be positive."),e.fov!==null&&(typeof e.fov!="number"||e.fov<=0||e.fov>=180)&&R(t,"fov must be null or between 0 and 180.");for(let o of["azimuthAngle","polarAngle"])e[o]!==void 0&&typeof e[o]!="number"&&R(t,`${o} must be a number.`)}function Xt(e,t,o,n){X(e,t),(typeof e.id!="number"||typeof e.title!="string"||typeof e.description!="string")&&R(t,"expected an annotation id, title and description.");for(let r of["worldPosition","localPosition"])ee(e[r],3,`${t}.${r}`);e.images!==void 0&&(Array.isArray(e.images)||R(t,"images must be an array."),e.images.forEach(r=>{X(r,t),te(r,"src",t,o,!0,n)})),e.links!==void 0&&(Array.isArray(e.links)||R(t,"links must be an array."),e.links.forEach(r=>{X(r,t),te(r,"href",t,o,!1,n)}))}function Kt(e,t){X(e,t),e.waypoints!==void 0&&(Array.isArray(e.waypoints)||R(t,"expected waypoints."),e.waypoints.forEach(o=>{X(o,t),ee(o.position,3,t),ee(o.target,3,t)}));for(let o of["enabled","loop","autoPlay"])e[o]!==void 0&&typeof e[o]!="boolean"&&R(t,`${o} must be boolean.`);e.duration!==void 0&&(typeof e.duration!="number"||e.duration<=0)&&R(t,"duration must be positive.")}function et(e,t,o){if(t!==null)if(Array.isArray(t))Array.isArray(e)||R(o,"expected an array."),t.length&&e.forEach(n=>et(n,t[0],o));else if(typeof t=="object"){X(e,o);for(let[n,r]of Object.entries(t))et(e[n],r,`${o}.${n}`)}else typeof e!=typeof t&&R(o,`expected ${typeof t}.`)}function Gt(e,t,o,n){if(et(e,fe,t),e.measurements!==void 0&&(e.measurements=ye(e.measurements)),e.sequences!==void 0&&(e.sequences=Ae(e.sequences)),e.selectionSets!==void 0&&(e.selectionSets=Wt(e.selectionSets)),e.product!==void 0&&(e.product=Mt(e.product),e.product.definition.groups.forEach(r=>r.options.forEach(a=>a.appearance?.forEach(s=>{for(let[i,c]of Object.entries(s.material??{}))c&&typeof c=="object"&&!Array.isArray(c)&&"path"in c&&te(c,"path",`${t}.product.material.${i}.path`,o,!0,n)})))),ee(e.model.rotation,3,`${t}.model.rotation`),e.lighting.lights.forEach(r=>ee(r.position,3,`${t}.lighting.lights`)),e.annotations.forEach(r=>Xt(r,`${t}.annotations`,o,n)),e.animations.autoplayClip!==null&&typeof e.animations.autoplayClip!="string"&&R(t,"invalid autoplay clip."),e.animations.clips.forEach(r=>{X(r,t),(typeof r.sourceName!="string"||typeof r.displayName!="string"||typeof r.hidden!="boolean"||typeof r.speed!="number"||!["repeat","once","ping-pong"].includes(r.loopMode))&&R(t,"invalid animation clip settings.")}),e.cinematic!==void 0&&Kt(e.cinematic,`${t}.cinematic`),e.styleRules!==void 0&&!Array.isArray(e.styleRules)&&R(t,"styleRules must be an array."),te(e.environment,"customEnvironmentUrl",`${t}.environment`,o,!1,n),te(e.background,"imageUrl",`${t}.background`,o,!0,n),e.model.activeVariants!==void 0&&Se(e.model.activeVariants,t),e.section!==void 0)try{e.section=be(e.section)}catch(r){R(`${t}.section`,r.message)}}function Zt(e,t,o,n){X(e,t);for(let[r,a]of Object.entries(e)){let s=`${t}.${r}`;X(a,s),(typeof a.id!="string"||typeof a.modelObjectId!="string")&&R(s,"expected binding id and modelObjectId.");for(let i of["label","group","type","status"])a[i]!==void 0&&typeof a[i]!="string"&&R(s,`${i} must be a string.`);a.tags!==void 0&&Se(a.tags,s),a.metadata!==void 0&&X(a.metadata,`${s}.metadata`),a.metrics!==void 0&&(X(a.metrics,s),Object.values(a.metrics).some(i=>typeof i!="number")&&R(s,"metrics must be numbers.")),a.actions!==void 0&&(Array.isArray(a.actions)||R(s,"actions must be an array."),a.actions.forEach(i=>{X(i,s),(typeof i.id!="string"||typeof i.label!="string"||i.type!=="command"||i.effects!==void 0&&!Array.isArray(i.effects))&&R(s,"invalid action.")}));for(let i of["visible","removed","selectable","hoverable"])a[i]!==void 0&&typeof a[i]!="boolean"&&R(s,`${i} must be boolean.`);if(a.transform!==void 0){X(a.transform,s);for(let i of["position","rotation","scale","shear"])a.transform[i]!==void 0&&ee(a.transform[i],3,`${s}.transform.${i}`);a.transform.pivot!==void 0&&(X(a.transform.pivot,s),ee(a.transform.pivot.point,3,s),ee(a.transform.pivot.offset,3,s))}if(a.style!==void 0&&(X(a.style,s),a.style.material!==void 0)){X(a.style.material,s);for(let[i,c]of Object.entries(a.style.material))c&&typeof c=="object"&&!Array.isArray(c)&&"path"in c&&te(c,"path",`${s}.style.material.${i}.path`,o,!0,n)}a.decals!==void 0&&(Array.isArray(a.decals)||R(s,"decals must be an array."),a.decals.forEach(i=>{X(i,s),(typeof i.id!="string"||typeof i.size!="number"||i.size<=0)&&R(s,"invalid decal."),ee(i.position,3,s),ee(i.normal,3,s),te(i,"image",s,o,!0,n)}))}}function Ht(e,t,o,n){Array.isArray(e)||R(t,"expected merge sources."),e.forEach(r=>{X(r,t),(typeof r.url!="string"||!r.url||typeof r.namePrefix!="string")&&R(t,"expected source URL and prefix."),te(r,"url",t,o,!1,n)})}function uo(e,t,o){X(e,"configuration");let n=Object.fromEntries(co.filter(r=>e[r]!==void 0).map(r=>[r,e[r]]));(typeof n.modelUrl!="string"||!n.modelUrl)&&R("configuration.modelUrl","expected the active model URL.");for(let r of["modelUrl","tilesetUrl","usdzUrl"])te(n,r,`configuration.${r}`,t,!1,o);if(n.sceneConfig!==void 0&&Gt(n.sceneConfig,"configuration.sceneConfig",t,o),n.mergeModels!==void 0&&Ht(n.mergeModels,"configuration.mergeModels",t,o),n.models!==void 0){(!Array.isArray(n.models)||n.models.length===0)&&R("configuration.models","expected model entries.");let r=new Set,a=new Set;n.models.forEach(s=>{X(s,"model"),(typeof s.url!="string"||!s.url)&&R("model.url","expected a URL."),te(s,"url","model.url",t,!1,o),s.id!==void 0&&(typeof s.id!="string"||!s.id.trim())&&R("model.id","expected a nonempty instance ID.");let i=Ke({id:s.id,url:s.url});a.has(i)&&R("configuration.models","instance identities must be unique; assign IDs when reusing a URL."),a.add(i),s.transform!==void 0&&(s.transform=he(s.transform)),s.visible!==void 0&&typeof s.visible!="boolean"&&R("model.visible","expected boolean."),r.add(s.url),Zt(s.objectBindings,"model.objectBindings",t,o),s.sceneConfig!==void 0&&Gt(s.sceneConfig,"model.sceneConfig",t,o),s.mergeModels!==void 0&&Ht(s.mergeModels,"model.mergeModels",t,o)}),n.activeModelId!==void 0&&(typeof n.activeModelId!="string"||!a.has(n.activeModelId))&&R("configuration.activeModelId","active instance is not in models."),n.activeModelId!==void 0&&n.models.find(s=>Ke(s)===n.activeModelId)?.url!==n.modelUrl&&R("configuration.modelUrl","source does not match the active instance."),r.has(n.modelUrl)||R("configuration.modelUrl","active model is not in models.")}if(n.multiSelectedKeys!==void 0&&Se(n.multiSelectedKeys,"configuration.multiSelectedKeys"),n.annotationCategories!==void 0&&n.annotationCategories!==null&&Se(n.annotationCategories,"configuration.annotationCategories"),n.activeAnnotation!==void 0&&n.activeAnnotation!==null&&Xt(n.activeAnnotation,"configuration.activeAnnotation",t,o),n.measurements!==void 0||n.measurementSettings!==void 0){let r=ye({items:n.measurements??[],settings:n.measurementSettings??{}});n.measurements!==void 0&&(n.measurements=r.items),n.measurementSettings!==void 0&&(n.measurementSettings=r.settings)}n.measurementModelId!==void 0&&typeof n.measurementModelId!="string"&&R("configuration.measurementModelId","expected a stable id."),n.measurementUnit!==void 0&&typeof n.measurementUnit!="string"&&R("configuration.measurementUnit","expected a unit label.");for(let r of["backgroundColor"])n[r]!==void 0&&typeof n[r]!="string"&&R(r,"expected a string.");n.shadows!==void 0&&typeof n.shadows!="boolean"&&R("shadows","expected boolean.");for(let[r,a]of Object.entries({modelFormat:["glb","gltf","obj","fbx","usdz","stl","ply"],cameraControllerType:["orbit","pointerLock"],objectTransformSpace:["world","local"],arScaleMode:["normalized","real-world"]}))n[r]!==void 0&&!a.includes(n[r])&&R(r,"unsupported value.");if(n.cinematic!==void 0&&Kt(n.cinematic,"cinematic"),n.isolation!==void 0&&n.isolation!==null){let{target:r,mode:a,ghostOpacity:s}=n.isolation;typeof r=="string"||Array.isArray(r)&&r.every(i=>typeof i=="string")||r&&typeof r=="object"&&["group","tag","type"].some(i=>typeof r[i]=="string")||R("configuration.isolation","invalid target."),a!==void 0&&!["ghost","hide"].includes(a)&&R("configuration.isolation","invalid mode."),s!==void 0&&(typeof s!="number"||s<0||s>1)&&R("configuration.isolation","opacity must be between 0 and 1.")}return n}function Yt(e,t,o,n){if(!(!e||typeof e!="object"))for(let[r,a]of Object.entries(e))r!=="metadata"&&(typeof a=="string"&&["url","modelUrl","tilesetUrl","usdzUrl","path","image","src","href","imageUrl","customEnvironmentUrl"].includes(r)?te(e,r,`${t}.${r}`,o,["path","image","src","imageUrl"].includes(r),n):Yt(a,`${t}.${r}`,o,n))}function Jt(e,t,o){typeof e=="string"&&(new TextEncoder().encode(e).length>ie&&R("state","exceeds the 5 MiB limit."),e=JSON.parse(e));let n=lo(e);X(n,"state"),new TextEncoder().encode(JSON.stringify(n)).length>ie&&R("state","exceeds the 5 MiB limit."),n.version!==void 0&&n.version!==1&&R("version","unsupported version."),n.version===void 0&&(n.objectBindings!==void 0||n.configuration!==void 0)&&R("version","full configurations require version 1.");let r={};return n.version!==void 0&&(r.version=1),n.camera!==void 0&&(mo(n.camera,"camera"),r.camera=n.camera),n.hidden!==void 0&&(Se(n.hidden,"hidden"),r.hidden=n.hidden),n.selected!==void 0&&(n.selected!==null&&typeof n.selected!="string"&&R("selected","expected an object id or null."),r.selected=n.selected),n.objectBindings!==void 0&&(Zt(n.objectBindings,"objectBindings",t,o),r.objectBindings=n.objectBindings),n.configuration!==void 0&&(r.configuration=uo(n.configuration,t,o)),Yt(r,"state",t,o),new TextEncoder().encode(JSON.stringify(r)).length>ie&&R("state","exceeds the 5 MiB limit."),r}function pi(e,t){return JSON.stringify(Te(e,t))}function Te(e,t){return Jt(e,t)}async function Qt(e,t){let o=new Map,n=Jt(e,t,o),r=new Map,a=new Map;for(let[i,{source:c,path:l}]of o){let f=r.get(c);f||(f=(async()=>{let u;try{u=await fetch(c)}catch{R(l,"this temporary image is no longer available. Reload or reselect it before saving.")}u.ok||R(l,"could not read the temporary image. Reload or reselect it before saving.");let m=await u.blob();m.size>ie*3/4&&R(l,"embedded image exceeds the 5 MiB configuration limit. Use a hosted image URL.");let d=new Uint8Array(await m.arrayBuffer()),p=m.type.split(";")[0].toLowerCase(),M=p.startsWith("image/")?p:fo(d);M||R(l,"temporary asset is not a supported image. Use a hosted asset URL.");let b="";for(let S=0;S<d.length;S+=32768)b+=String.fromCharCode(...d.subarray(S,S+32768));return`data:${M};base64,${btoa(b)}`})(),r.set(c,f)),a.set(i,await f)}function s(i){if(!(!i||typeof i!="object"))for(let[c,l]of Object.entries(i))c!=="metadata"&&(["path","image","src","imageUrl"].includes(c)&&typeof l=="string"&&a.has(l)?i[c]=a.get(l):s(l))}return s(n),Te(n,t)}function fo(e){let t=(o,n)=>String.fromCharCode(...e.subarray(o,n));if(e[0]===137&&t(1,4)==="PNG")return"image/png";if(e[0]===255&&e[1]===216&&e[2]===255)return"image/jpeg";if(t(0,3)==="GIF")return"image/gif";if(t(0,4)==="RIFF"&&t(8,12)==="WEBP")return"image/webp";if(t(4,8)==="ftyp"&&["avif","avis"].includes(t(8,12)))return"image/avif";if(/<svg[\s>]/i.test(new TextDecoder().decode(e.subarray(0,1024))))return"image/svg+xml"}import{strFromU8 as po,strToU8 as en,unzlibSync as go,zlibSync as bo}from"fflate";var Ee="ri-ar",Be="ri-ar-id",tn=4096,ho=2200,yo=en(JSON.stringify(fe)).byteLength;function nn(e){return e==="localhost"||e.endsWith(".localhost")||/^127\./.test(e)||e==="[::1]"||e==="0.0.0.0"}function on(e){if(typeof e=="string"&&/^https?:\/\//i.test(e)&&nn(new URL(e).hostname))throw new Error("An asset URL points to this computer. Use model and texture URLs reachable from the phone.");if(e&&typeof e=="object")for(let t of Object.values(e))on(t)}function wi(e){return e&&typeof e=="object"?e:void 0}function xi(e){let t=new URLSearchParams(new URL(e,"https://viewer.invalid/").hash.slice(1));return t.has(Ee)||t.has(Be)}function So(e,t){let o=new URL(e,t);if(!["https:","http:"].includes(o.protocol))throw new Error("AR handoff requires an HTTP(S) URL.");return o.toString()}function Ai(e,t="",o=2048){let n=new Set,r=a=>{if(typeof a=="string")return je(a)??a;if(a===null||typeof a!="object")return a;if(n.has(a))throw new Error("AR configuration cannot contain cycles.");n.add(a);let s=Array.isArray(a)?a.map(r):Object.fromEntries(Object.keys(a).sort().map(i=>[i,r(a[i])]));return n.delete(a),s};return JSON.stringify([t,o,r({...e,camera:void 0})])}function rn(e,t){if(JSON.stringify(e)!==JSON.stringify(t))return e&&t&&typeof e=="object"&&typeof t=="object"&&!Array.isArray(e)&&!Array.isArray(t)?Object.fromEntries(Object.entries(e).map(([o,n])=>[o,rn(n,t[o])]).filter(([,o])=>o!==void 0)):e}function an(e,t,o=0){if(o>64)throw new Error("AR configuration is too deeply nested.");if(e&&t&&typeof e=="object"&&typeof t=="object"&&!Array.isArray(e)&&!Array.isArray(t)){let n=e,r=t;return Object.fromEntries([...new Set([...Object.keys(r),...Object.keys(n)])].map(a=>[a,Object.prototype.hasOwnProperty.call(n,a)?an(n[a],r[a],o+1):r[a]]))}return e}function sn(e,t){let o=structuredClone(e);if(o.configuration){o.configuration.sceneConfig&&(o.configuration.sceneConfig=t(o.configuration.sceneConfig));for(let n of o.configuration.models??[])n.sceneConfig&&(n.sceneConfig=t(n.sceneConfig))}return o}function we(e){e?.throwIfAborted()}async function Mi(e,t,o,n){we(n);let r=new URL(So(t));if(nn(r.hostname))throw new Error("Phone links need a viewer URL reachable from your phone. Download the USDZ for local uploads, or provide a public viewer URL.");let a=await Qt(e,r.toString());we(n),on(a);let s=new URLSearchParams(r.hash.slice(1));if(s.delete(Ee),s.delete(Be),s.delete("view"),s.delete("viewId"),s.delete("view-id"),o){let i=await o.save(a);if(we(n),typeof i!="string"||!i||i.length>512)throw new Error("AR storage returned an invalid configuration ID.");s.set(Be,i)}else{let i=bo(en(JSON.stringify({ar:1,state:sn(a,l=>rn(l,fe)??{})})),{level:9});if(i.byteLength>tn)throw new Error("This configuration needs an AR storage adapter to share on a phone. The USDZ download is still available.");let c="";for(let l of i)c+=String.fromCharCode(l);s.set(Ee,btoa(c).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""))}if(r.hash=s.toString(),r.toString().length>ho)throw new Error("This configuration is too large for a reliable QR code. Use an AR storage adapter or download the USDZ.");return r.toString()}async function Ci(e,t,o){let n=new URL(e),r=new URLSearchParams(n.hash.slice(1)),a=r.get(Be),s=r.get(Ee);if(a!==null&&s!==null)throw new Error("AR link contains conflicting configurations.");if(a===null&&s===null)return null;we(o);let i;if(a!==null){if(!t)throw new Error("This AR link requires the application's configuration storage adapter.");if(!a||a.length>512)throw new Error("Invalid AR configuration ID.");i=await t.load(a)}else{if(!s||s.length>Math.ceil(tn*4/3)||!/^[\w-]+$/.test(s))throw new Error("Invalid or oversized AR link.");let l=atob(s.replace(/-/g,"+").replace(/_/g,"/")),f=Uint8Array.from(l,d=>d.charCodeAt(0)),u=go(f);if(u.byteLength>ie)throw new Error("AR configuration exceeds the 5 MiB limit.");let m=JSON.parse(po(u));if(m?.ar===1&&m.state){let d=m.state.configuration,p=(d?.sceneConfig?1:0)+(Array.isArray(d?.models)?d.models.filter(M=>M?.sceneConfig).length:0);if(u.byteLength+p*yo>ie)throw new Error("Expanded AR configuration exceeds the 5 MiB limit.");i=sn(m.state,M=>an(M,fe))}else i=m}we(o);let c=Te(i,n.toString());if(c.version!==1||!c.configuration)throw new Error("AR handoff requires a complete versioned viewer configuration.");return c}var tt=new WeakMap;function vi(e,t){t?tt.set(e,t):tt.delete(e)}function cn(e){e.traverse(t=>{let o=tt.get(t);if(o)throw new Error(o)})}import{Box3 as $o,BufferAttribute as Pe,BufferGeometry as On,Color as _o,DoubleSide as Fo,FrontSide as dt,Group as In,Matrix4 as qo,Mesh as Wo,Vector3 as Ne}from"three";import{PropertyBinding as nt}from"three";var ot=Symbol("react-immersive.model-node-id");function wo(e,t){Object.defineProperty(e,ot,{value:t,configurable:!0})}function ae(e){let t=new Map;e.traverse(c=>{if(!c.name)return;let l=t.get(c.name);l?l.push(c):t.set(c.name,[c])});let o=Object.create(null),n=new WeakMap,r=new Map,a=new Set(Array.from(t,([c,l])=>l.length===1?c:null).filter(c=>c!==null)),s=new Set,i=(c,l)=>{wo(c,l),o[l]=c,n.set(c,l),s.add(l)};for(let[c,l]of t)l.length===1&&i(l[0],c);for(let[c,l]of t){if(l.length<2)continue;let f=[];l.forEach((u,m)=>{let d=`${c} [${m+1}]`,p=d,M=2;for(;a.has(p)||s.has(p);)p=`${d}.${M++}`;i(u,p),f.push(p)}),r.set(c,f)}return{nodesById:o,idByNode:n,duplicateNames:r}}function xe(e){return e[ot]??e.name??null}function Ii(e,t){let o=t.replace(/\.[^./\\]+$/,"");e.traverse(n=>{n.name&&(n.name=nt.sanitizeNodeName(`${o}_${n.name}`))})}function Ri(e,t){let o=t.replace(/\.[^./\\]+$/,""),n=e.clone();for(let r of n.tracks){let s=nt.parseTrackName(r.name).nodeName??"",i=nt.sanitizeNodeName(`${o}_${s}`);r.name=i+r.name.slice(s.length)}return n}function ln(e,t){let o=null,n=[];return e.traverse(r=>{r[ot]===t&&(o=r),r.name===t&&n.push(r)}),o??(n.length===1?n[0]:null)}import{AnimationClip as Ro,Group as To,Matrix4 as Eo,Vector3 as Bo,PropertyBinding as Cn}from"three";import{clone as Po}from"three/examples/jsm/utils/SkeletonUtils.js";import{strFromU8 as No,strToU8 as mt,unzipSync as Vo,zipSync as zo}from"fflate";import{AnimationMixer as xo,LoopOnce as Ao,LoopPingPong as mn,LoopRepeat as Mo}from"three";function dn(e){let t=e._loopCount;return e.loop===mn&&(t&1)===1}function Co(e){return dn(e)?e.getClip().duration-e.time:e.time}function un({root:e,clips:t,getClipConfig:o,onChange:n}){let r=new xo(e),a=new Map;for(let{clip:h,sourceName:C}of t)a.set(C,r.clipAction(h));let s=new Map,i=new Set,c=new Map,l=1,f=h=>typeof h=="string",u=h=>f(h)?s.has(h)?[h]:[]:[...s.keys()],m=(h,C)=>{let k=jt(o(C));k==="once"?h.setLoop(Ao,1):k==="ping-pong"?h.setLoop(mn,1/0):h.setLoop(Mo,1/0),h.clampWhenFinished=k==="once"},d=h=>{h.action.setEffectiveTimeScale(h.reverse?-h.speed:h.speed)},p=h=>{let C=s.get(h);C&&(C.action.stop(),s.delete(h))},M=(h,C={})=>{let k=a.get(h);if(!k||o(h)?.hidden)return;let E=Number.isFinite(C.fade)&&C.fade>0?C.fade:0,V=C.reverse??!1;if(!C.alongside)for(let[B,q]of[...s])B!==h&&(E>0?(s.delete(B),q.action.fadeOut(E),i.add(q.action)):p(B));i.delete(k)&&k.stop();let y=k.getClip().duration,x=s.get(h),j=()=>{k.reset(),V&&(k.time=y),k.play()};if(!x)j(),E>0&&k.fadeIn(E);else{let B=V?k.time<=0:k.time>=y;x.finished&&B&&j(),k.paused=!1,k.enabled=!0,s.delete(h)}m(k,h),x={action:k,speed:o(h)?.speed??c.get(h)??l,reverse:V,finished:!1},x.speed=ke(x.speed),d(x),s.set(h,x),n()},b=h=>{for(let C of u(h))s.get(C).action.paused=!0;n()},S=h=>{for(let C of u(h))p(C);if(!f(h)){for(let C of i)C.stop();i.clear()}n()},A=(h,C)=>{let k=ke(h);f(C)?c.set(C,k):l=k;for(let E of u(C)){let V=s.get(E);c.set(E,k),V.speed=k,d(V)}n()},g=(h,C)=>{for(let k of u(C)){let E=s.get(k),V=E.action.getClip().duration,y=Math.min(Math.max(h,0),V);E.action.time=dn(E.action)?V-y:y,E.finished&&(E.finished=!1,E.action.paused=!0)}r.update(0),n()},w=()=>{for(let[h,C]of[...s]){let k=o(h);if(k?.hidden){p(h);continue}m(C.action,h),k?.speed!==void 0&&(C.speed=ke(k.speed),d(C))}n()},v=h=>{for(let C of s.values())C.action===h.action&&(C.finished=!0);n()};return r.addEventListener("finished",v),{play:M,pause:b,stop:S,setSpeed:A,seek:g,getState:()=>{let h=[...s].map(([k,E])=>({clip:k,status:E.finished?"finished":E.action.paused?"paused":"playing",time:Co(E.action),duration:E.action.getClip().duration,speed:E.speed,reverse:E.reverse})),C=h[h.length-1];return{currentClip:C?.clip??null,isPlaying:h.some(k=>k.status==="playing"),speed:C?.speed??l,time:C?.time??0,duration:C?.duration??0,active:h}},applyClipConfigs:w,isRunning:()=>{if(i.size>0)return!0;for(let{action:h}of s.values())if(!h.paused&&h.enabled)return!0;return!1},update:h=>{r.update(h);for(let C of i)(!C.enabled||C.getEffectiveWeight()<=0)&&(C.stop(),i.delete(C))},dispose:()=>{r.removeEventListener("finished",v),r.stopAllAction(),r.uncacheRoot(e),s.clear(),i.clear()}}}import{Color as fn}from"three";var rt=e=>e==="baseColor"?"color":e;function pn(e){let t=new Set;return e.traverse(o=>{let n=o;if(n.isMesh)for(let r of Array.isArray(n.material)?n.material:[n.material])r&&t.add(r)}),[...t]}function gn({root:e,controls:t,animations:o,invalidate:n,cameraEnabled:r=()=>!0}){let a=new Map,s=new Map,i=new Map,c=new Set,l=new Map,f=null,u="",m=g=>e()?ln(e(),g):null,d=g=>{if(g.kind==="camera"){let N=t();if(!N)return null;let O=ne(N.camera,N);return{position:O.position,target:O.target,fov:O.fov,zoom:O.zoom}}if(g.kind==="clip"){let N=o();return N?.clips.includes(g.clip)?N.getState?.().active.find(O=>O.clip===g.clip)?.time??0:null}let w=m(g.objectId);if(!w)return null;let v=g.property;if(v==="position"||v==="rotation"||v==="scale")return[w[v].x,w[v].y,w[v].z];if(v==="visible")return w.visible;let P=pn(w).find(N=>N[rt(v)]!==void 0),T=P?P[rt(v)]:void 0;return T?.isColor?`#${T.getHexString()}`:typeof T=="number"?T:null},p=g=>{if(!r())return;let w=t();w&&(w.stop(),w.setLookAt(...g.position,...g.target,!1),g.fov!==null&&"fov"in w.camera&&(w.camera.fov=g.fov,w.camera.updateProjectionMatrix()),w.zoomTo(g.zoom,!1),w.update(0))},M=g=>{if(a.has(g))return;g.updateWorldMatrix(!0,!0);let w=g.matrixAutoUpdate?void 0:xt(g.matrix,g.scale,g.quaternion).shear;a.set(g,{position:g.position.toArray(),rotation:[g.rotation.x,g.rotation.y,g.rotation.z],scale:g.scale.toArray(),matrix:g.matrix.clone(),auto:g.matrixAutoUpdate,shear:w});for(let v of bt(g))ht(v)||(Me(v,v.matrixWorld),c.add(v))},b=(g,w)=>{let v=o();v?.stop(g),w&&v&&(v.play(g,{alongside:!0,reverse:w.reverse}),v.setSpeed(w.speed,g),v.seek?.(w.time,g),w.status!=="playing"&&v.pause(g))};return{capture:d,restore:()=>{for(let[g,w]of l)b(g,w);l.clear();for(let[g,w]of a)g.position.fromArray(w.position),g.rotation.set(...w.rotation),g.scale.fromArray(w.scale),g.matrix.copy(w.matrix),g.matrixAutoUpdate=w.auto,g.matrixWorldNeedsUpdate=!0;a.clear(),s.forEach((g,w)=>w.visible=g),s.clear(),i.forEach((g,w)=>{g.forEach((v,P)=>{v instanceof fn?w[P].copy(v):w[P]=v}),w.needsUpdate=!0}),i.clear(),c.forEach(St),c.clear(),f&&p(f),f=null,u="",e()?.updateWorldMatrix(!0,!0),n()},inspect:g=>g.tracks.filter(w=>!w.muted&&w.keyframes.length&&(w.target.kind!=="camera"||r())&&d(w.target)===null).map(w=>`Unavailable target: ${w.name}.`),invalidate:n,apply:({sequence:g,time:w,playing:v})=>{let P=g.tracks.filter(O=>O.target.kind!=="camera"||r()).map(O=>({track:O,value:ut(O,w)})).filter(O=>O.value!==null);for(let[O,h]of l)P.some(({track:C})=>C.target.kind==="clip"&&C.target.clip===O)||(b(O,h),l.delete(O));for(let{track:O}of P)if(O.target.kind==="object"&&["position","rotation","scale"].includes(O.target.property)){let h=m(O.target.objectId);h&&M(h)}let T=new Map([...i.keys()].map(O=>[O,O.transparent]));s.forEach((O,h)=>h.visible=O),a.forEach((O,h)=>{h.position.fromArray(O.position),h.rotation.set(...O.rotation),h.scale.fromArray(O.scale),Le(h,O.shear)}),i.forEach((O,h)=>O.forEach((C,k)=>{C instanceof fn?h[k].copy(C):h[k]=C}));let N=o();for(let{track:O,value:h}of P){if(O.target.kind!=="clip"||!N?.seek||!N.clips.includes(O.target.clip))continue;let C=O.target.clip;l.has(C)||(l.set(C,N.getState?.().active.find(k=>k.clip===C)),N.play(C,{alongside:!0}),N.pause(C)),N.seek(h,C)}for(let{track:O,value:h}of P){let C=O.target;if(C.kind==="clip")continue;if(C.kind==="camera"){f||(f=d(C));let V=JSON.stringify(h);(v||V!==u)&&(p(h),u=V);continue}let k=m(C.objectId);if(!k)continue;let E=C.property;if(E==="visible")s.has(k)||s.set(k,k.visible),k.visible=h;else if(E==="position"||E==="rotation"||E==="scale")E==="rotation"?k.rotation.set(...h):k[E].fromArray(h),Le(k,a.get(k)?.shear);else for(let V of pn(k)){let y=rt(E),x=V[y];if(x===void 0)continue;let j=i.get(V);if(j||(j=new Map,i.set(V,j)),T.has(V)||T.set(V,V.transparent),j.has(y)||j.set(y,x?.isColor?x.clone():x),x?.isColor?x.set(h):V[y]=h,E==="opacity"){j.has("transparent")||j.set("transparent",V.transparent);let B=h<1||j.get("transparent")===!0;V.transparent=B}}}f&&!P.some(({track:O})=>O.target.kind==="camera")&&(p(f),u=""),T.forEach((O,h)=>{O!==h.transparent&&(h.needsUpdate=!0)}),e()?.updateWorldMatrix(!0,!0)}}}function bn(e){let t=new Map;return e.map((o,n)=>{let a=o.name.trim()||`Animation ${n+1}`,s=t.get(a)??0;return t.set(a,s+1),{clip:o,sourceName:s===0?a:`${a} (${s+1})`,duration:o.duration}})}import{Box3 as it,Group as jo,BufferAttribute as vo,Matrix4 as hn,Mesh as ko,Quaternion as Oo,Vector3 as pe}from"three";function Io(e){let t=e.getAttribute("arSourceVertex"),o=e.getAttribute("arNormalSign");if(!t)return;let n=new Map,r=[],a=[];for(let i=0;i<t.count;i++){let c=`${t.getX(i)}:${o?.getX(i)??1}`,l=n.get(c);l===void 0&&(l=r.length,r.push(i),n.set(c,l)),a.push(l)}let s=e.index?Array.from(e.index.array,i=>a[i]):a;for(let[i,c]of Object.entries(e.attributes)){let l=new Float32Array(r.length*c.itemSize);r.forEach((f,u)=>{for(let m=0;m<c.itemSize;m++)l[u*c.itemSize+m]=c.getComponent(f,m)}),e.setAttribute(i,new vo(l,c.itemSize))}e.setIndex(s)}function yn(e,t,o,n){let r=[],a=[],s=new Map;for(let i of e){let c=i.source;if(!c.isSkinnedMesh)continue;let l=t.get(c),f=c.skeleton,u=JSON.stringify(f.bones.map((O,h)=>[O.uuid,f.boneInverses[h].elements])),m=s.get(u);if(!m){let O=new Map(f.bones.map((x,j)=>[x,j])),h=f.bones.map(x=>{for(let j=x.parent;j;j=j.parent)if(O.has(j))return O.get(j);return-1}),C=[],k=x=>{C.includes(x)||(h[x]>=0&&k(h[x]),C.push(x))};f.bones.forEach((x,j)=>k(j));let E=C.map(x=>C.indexOf(h[x])),V=[];C.forEach((x,j)=>V.push(`${E[j]<0?"":V[E[j]]+"/"}J_${x}`));let y={name:`${n}_${r.length}`,joints:V,parents:E,bones:C.map(x=>t.get(f.bones[x])),bindTransforms:C.map(x=>f.boneInverses[x].clone().invert()),restTransforms:[],worlds:C.map(()=>new hn),referenceInverse:o.clone().invert(),frames:[]};if(y.bones.some(x=>!x))throw new Error("The AR skeleton has joints outside the exported scene.");m={rig:y,order:C},s.set(u,m),r.push(y)}Io(i.exported.geometry);let d=i.exported.geometry.getAttribute("arSourceVertex"),p=c.geometry.getAttribute("skinIndex"),M=c.geometry.getAttribute("skinWeight");if(!d||!p||!M||p.itemSize!==4||M.itemSize!==4)throw new Error("AR skeletal animation needs four joint indices and weights per vertex.");let b={target:i,node:l,rig:m.rig,reference:o,geomBind:c.bindMatrix.clone(),jointIndices:[],jointWeights:[],jointBounds:m.order.map(()=>new it),extent:new it},S=i.exported.geometry.getAttribute("position"),A=i.exported.geometry.getAttribute("normal"),g=c.geometry.getAttribute("normal"),w=i.exported.geometry.getAttribute("arNormalSign"),v=new pe,P=new pe,T=new Map(m.order.map((O,h)=>[O,h])),N=b.rig.bindTransforms.map(O=>O.clone().invert().multiply(c.bindMatrix));for(let O=0;O<d.count;O++){let h=d.getX(O);if(ko.prototype.getVertexPosition.call(c,h,v),S.setXYZ(O,v.x,v.y,v.z),g&&A){P.fromBufferAttribute(g,h);let k=P.clone();c.geometry.morphAttributes.normal?.forEach((E,V)=>{let y=c.morphTargetInfluences?.[V]??0;y&&P.addScaledVector(new pe().fromBufferAttribute(E,h).sub(c.geometry.morphTargetsRelative?new pe:k),y)}),P.normalize().multiplyScalar(w?.getX(O)??1),A.setXYZ(O,P.x,P.y,P.z)}let C=[0,1,2,3].reduce((k,E)=>k+M.getComponent(h,E),0);if(!Number.isFinite(C)||C<=0)throw new Error("The AR skin has a vertex without valid joint weights.");for(let k=0;k<4;k++){let E=M.getComponent(h,k)/C,V=E?T.get(p.getComponent(h,k))??-1:0;if(V<0||!Number.isFinite(E)||E<0)throw new Error("The AR skin has invalid joint indices or weights.");b.jointIndices.push(V),b.jointWeights.push(E),E&&b.jointBounds[V].expandByPoint(v.clone().applyMatrix4(N[V]))}}S.needsUpdate=!0,A?A.needsUpdate=!0:i.exported.geometry.computeVertexNormals(),i.exported.geometry.computeBoundingBox(),i.exported.matrixAutoUpdate=!1,i.exported.matrix.copy(ct(b)),a.push(b)}return{rigs:r,skins:a}}function ct(e){return e.node.matrixWorld.clone().multiply(e.node.bindMatrixInverse).multiply(e.reference)}function Sn(e,t,o){let n=new pe,r=new Oo,a=new pe,s=new hn;for(let i of e){let c={time:o,translations:[],rotations:[],scales:[]};i.bones.forEach((l,f)=>i.worlds[f].multiplyMatrices(i.referenceInverse,l.matrixWorld)),i.worlds.forEach((l,f)=>{let u=i.parents[f],m=u<0?l.clone():i.worlds[u].clone().invert().multiply(l);m.decompose(n,r,a),r.normalize(),s.compose(n,r,a);let d=1e-5*Math.max(1,...m.elements.map(Math.abs));if(!m.elements.every(Number.isFinite)||m.elements.some((p,M)=>Math.abs(p-s.elements[M])>d)||Math.abs(m.determinant())<1e-15)throw new Error("The AR skeleton contains a sheared or zero-scale joint that Quick Look cannot preserve. Use arHandoff.createUSDZ for this rig.");c.translations.push(...n.toArray()),c.rotations.push(r.w,r.x,r.y,r.z),c.scales.push(...a.toArray()),i.frames.length||i.restTransforms.push(m)}),i.frames.push(c)}for(let i of t)i.jointBounds.forEach((c,l)=>{c.isEmpty()||i.extent.union(c.clone().applyMatrix4(i.rig.worlds[l]))})}var lt=e=>String(Number(e.toPrecision(9))),at=e=>{let t=Array.isArray(e)?e:e.elements;return`(${[0,4,8,12].map(o=>`(${t.slice(o,o+4).map(lt).join(", ")})`).join(", ")})`},st=(e,t)=>Array.from({length:e.length/t},(o,n)=>`(${e.slice(n*t,(n+1)*t).map(lt).join(", ")})`).join(", ");function wn(e){let t=(s,i,c=1e-7)=>Math.abs(s-i)>c*Math.max(1,Math.abs(s),Math.abs(i)),o=[["translations",3,"float3"],["rotations",4,"quatf"],["scales",3,"half3"]],n=e.frames[0],r=e.joints.map((s,i)=>i).filter(s=>o.some(([i,c])=>e.frames.some(l=>l[i].slice(s*c,(s+1)*c).some((f,u)=>t(f,n[i][s*c+u])))));r.length||(r=e.joints.map((s,i)=>i));let a=o.map(([s,i,c])=>{let l=e.frames.map(u=>r.flatMap(m=>u[s].slice(m*i,(m+1)*i)));return l.some(u=>u.some((m,d)=>t(m,l[0][d],c==="half3"?1e-4:1e-7)))?`${c}[] ${s}.timeSamples = {${e.frames.map((u,m)=>`${u.time}: [${st(l[m],i)}]`).join(`,
3
- `)}}`:`${c}[] ${s} = [${st(l[0],i)}]`}).join(`
4
- `);return`#usda 1.0
5
- (
6
- defaultPrim = "Skeleton"
7
- metersPerUnit = 1
8
- upAxis = "Y"
9
- timeCodesPerSecond = 30
10
- framesPerSecond = 30
11
- )
12
- def Skeleton "Skeleton" (prepend apiSchemas = ["SkelBindingAPI"]) {
13
- uniform token[] joints = ${JSON.stringify(e.joints)}
14
- uniform matrix4d[] bindTransforms = [${e.bindTransforms.map(at).join(", ")}]
15
- uniform matrix4d[] restTransforms = [${e.restTransforms.map(at).join(", ")}]
16
- rel skel:animationSource = <Animation>
17
- def SkelAnimation "Animation" {
18
- uniform token[] joints = ${JSON.stringify(r.map(s=>e.joints[s]))}
19
- ${a}
20
- }
21
- }
22
- `}function xn(e,t){let o=new Map;for(let n of e){let r=n.target.exported,a=t.get(r.name),s=l=>Math.round(l*1e7)/1e7,i=JSON.stringify([n.rig.name,a?.map(l=>l.matrix.map(s))??r.matrix.elements.map(s)]),c=o.get(i);if(!c){let l=new jo;l.name=`AR_Rig_${o.size}`,l.matrixAutoUpdate=!1,l.matrix.copy(r.matrix),r.parent.add(l),c={node:l,rig:n.rig,skins:[],extent:new it},o.set(i,c),a&&t.set(l.name,a)}c.node.add(r),r.matrix.identity(),t.delete(r.name),c.skins.push(n),c.extent.union(n.extent)}return[...o.values()]}function An(e){return`
23
- rel skel:skeleton = <Skeleton>
24
- rel skel:animationSource = <Skeleton/Animation>
25
- float3[] extent = [${st([...e.extent.min.toArray(),...e.extent.max.toArray()],3)}]
26
- def Skeleton "Skeleton" (prepend references = @./rigs/${e.rig.name}.usda@</Skeleton>) {}
27
- `}function Mn(e){return`
28
- over "Geometry" (prepend apiSchemas = ["SkelBindingAPI"]) {
29
- rel skel:skeleton = <../../Skeleton>
30
- uniform token[] skel:joints = ${JSON.stringify(e.rig.joints)}
31
- uniform token primvars:skel:skinningMethod = "classicLinear"
32
- matrix4d primvars:skel:geomBindTransform = ${at(e.geomBind)}
33
- int[] primvars:skel:jointIndices = [${e.jointIndices.join(", ")}] (
34
- interpolation = "vertex"
35
- elementSize = 4
36
- )
37
- float[] primvars:skel:jointWeights = [${e.jointWeights.map(lt).join(", ")}] (
38
- interpolation = "vertex"
39
- elementSize = 4
40
- )
41
- }
42
- `}var se=30,Do=12e4,Lo=1e6,jn=new Set(["position","quaternion","rotation","scale"]);function Uo(e){let t=Ae(e.sceneConfig?.sequences??[]).find(l=>l.autoPlay),o=e.sceneConfig?.animations.autoplayClip,n=bn(e.scene.animations),r=n.find(l=>l.sourceName===o),a=e.sceneConfig?.animations.clips.find(l=>l.sourceName===o),s=a?.speed??1,i=Number.isFinite(s)&&s>0?s:1,c=r&&!a?.hidden?r.duration*(a?.loopMode==="ping-pong"?2:1)/i:0;return{sequence:t,autoplay:o,clips:n,duration:Math.max(c,t?.duration??0)}}function vn(e,t,o){let n=new Set,r=new Map,a=0,s=0,i=0,c=[],l=[],f=e.map(Uo),u=Math.max(0,...f.map(m=>m.duration));for(let[m,d]of e.entries()){o?.throwIfAborted();let{sequence:p,autoplay:M}=f[m];if(!p&&!M)continue;let b=Po(d.scene),S=[],A=[];d.scene.traverse(I=>S.push(I)),b.traverse(I=>A.push(I));let g=new Map;S.forEach((I,U)=>{A[U].uuid=I.uuid,g.set(I,A[U]);let L=Ce(I);L&&I.isSkinnedMesh&&(delete A[U].userData.reactImmersiveSkinFreeze,Me(A[U],L.clone().invert(),yt(I)??void 0))});let w=ae(b),v=new To;v.matrixAutoUpdate=!1,v.matrix.copy(d.scene.parent?.matrixWorld??new Eo),v.add(b),v.updateMatrixWorld(!0);let P=t.filter(I=>I.sourceIndex===m),T=P.some(I=>I.source.isSkinnedMesh),N=new Set(p?.tracks.filter(I=>!I.muted&&I.target.kind==="clip").map(I=>I.target.kind==="clip"?I.target.clip:"")??[]);M&&N.add(M);let O=f[m].clips.map(I=>{if(!N.has(I.sourceName))return I;let U=I.clip.tracks.filter(L=>{let F=Cn.parseTrackName(L.name),Q=Cn.findNode(b,F.nodeName),D=!!Q&&jn.has(F.propertyName)&&(Q?.type!=="Bone"||T)&&!F.objectName;return D||n.add(Q?.type==="Bone"?"Skeletal tracks without an exported skinned mesh are omitted.":"Quick Look exports object and skeletal motion. Morph and other unsupported clip tracks keep their captured pose."),D});return{...I,clip:new Ro(I.clip.name,I.duration,U)}}),h=I=>d.sceneConfig?.animations.clips.find(U=>U.sourceName===I),C=un({root:b,clips:O,getClipConfig:h,onChange(){}}),k={...C,clips:O.map(I=>I.sourceName)},E=gn({root:()=>b,controls:()=>null,animations:()=>k,invalidate(){},cameraEnabled:()=>!1}),V=p?.tracks.filter(I=>{if(!T&&I.target.kind==="object"&&w.nodesById[I.target.objectId]?.type==="Bone")return I.muted||n.add("Quick Look keeps skeletal deformation at its captured pose."),!1;let U=I.target.kind==="clip"||I.target.kind==="object"&&jn.has(I.target.property);return!U&&!I.muted&&n.add("Quick Look exports sequence object motion. Camera, visibility and appearance tracks stay in WebXR."),U}),y=p?{...p,tracks:V??[]}:void 0;y&&E.inspect(y).forEach(I=>n.add(I));let x=O.some(I=>N.has(I.sourceName)&&I.clip.tracks.length&&!h(I.sourceName)?.hidden),j=V?.some(I=>!I.muted&&I.keyframes.length&&I.target.kind==="object");if(!x&&!j){C.dispose();continue}let B=yn(P,g,v.matrix,`Skin_${m}`),q=new Map(B.skins.map(I=>[I.target,I])),W=u,K=Math.ceil(W*se);if(s+=(K+1)*P.length,i+=(K+1)*B.rigs.reduce((I,U)=>I+U.joints.length,0),!Number.isFinite(W)||s>Do||i>Lo)throw C.dispose(),new Error("This animation is too large for browser USDZ conversion. Use arHandoff.createUSDZ for this model.");let J=Object.entries(d.objectBindings??{}).flatMap(([I,U])=>{if(!U.transform)return[];let L=w.nodesById[U.modelObjectId??I];return L?[{node:L,matrix:L.matrix.clone(),position:L.position.clone(),quaternion:L.quaternion.clone(),scale:L.scale.clone()}]:[]}),_=P.map(I=>({target:I,node:g.get(I.source),inverse:I.bakedMatrix.clone().invert(),frames:[]}));try{M&&C.play(M);let I=0;for(let U=0;U<=K;U++){o?.throwIfAborted();let L=Math.min(U/se,W);C.update(L-I),I=L;for(let F of J)F.node.position.copy(F.position),F.node.quaternion.copy(F.quaternion),F.node.scale.copy(F.scale),F.node.matrix.copy(F.matrix);if(y){let F=y.loop&&L>y.duration?L%y.duration:Math.min(L,y.duration);E.apply({sequence:y,time:F,playing:!1})}v.updateMatrixWorld(!0),Sn(B.rigs,B.skins,L*se);for(let F of _){let Q=q.get(F.target),D=Q?ct(Q):F.node.matrixWorld.clone().multiply(F.target.instanceMatrix).multiply(F.inverse);if(!D.elements.every(Number.isFinite)||D.determinant()<=0)throw new Error("Quick Look animation cannot preserve a reflected or zero-scale transform. Use arHandoff.createUSDZ.");F.frames.push({time:L*se,matrix:D.toArray()})}}for(let U of _){let L=U.frames[0]?.matrix;L&&U.frames.some(F=>F.matrix.some((Q,D)=>Math.abs(Q-L[D])>1e-8))&&(r.set(U.target.exported.name,U.frames),a=Math.max(a,W))}if(B.skins.length){for(let U of B.skins)U.extent.expandByScalar(Math.max(1e-6,U.extent.getSize(new Bo).length()*.001));c.push(...B.rigs),l.push(...B.skins),a=Math.max(a,W)}}finally{E.restore(),C.dispose()}}return{samples:r,rigs:c,skins:l,duration:a,warnings:[...n]}}function kn(e,t,o){if(!t.samples.size&&!t.skins.length)return e;let n=Vo(e),r=No(n["model.usda"]);r=r.replace(" metersPerUnit = 1",` startTimeCode = 0
43
- endTimeCode = ${t.duration*se}
44
- timeCodesPerSecond = ${se}
45
- framesPerSecond = ${se}
46
- autoPlay = true
47
- metersPerUnit = 1`);for(let[i,c]of t.samples){let l=new RegExp(`(def Xform "${i}"[\\s\\S]*?\\n[\\t ]*)matrix4d xformOp:transform = [^\\n]+`);if(!l.test(r))throw new Error("The USDZ exporter produced an unsupported animation layout.");let f=c.map(u=>{let m=[0,4,8,12].map(d=>`(${u.matrix.slice(d,d+4).join(", ")})`);return`${u.time}: (${m.join(", ")})`}).join(`,
48
- `);r=r.replace(l,(u,m)=>`${m}matrix4d xformOp:transform.timeSamples = {
49
- ${f}
50
- }`)}for(let i of t.rigs)n[`rigs/${i.name}.usda`]=mt(wn(i));for(let i of o){let c=new RegExp(`def Xform "${i.node.name}"(\\s*\\{)`);if(!c.test(r))throw new Error("The USDZ exporter produced an unsupported skeleton root layout.");r=r.replace(c,`def SkelRoot "${i.node.name}" (prepend apiSchemas = ["SkelBindingAPI"]) $1${An(i)}`)}for(let i of t.skins){let c=new RegExp(`def Xform "${i.target.exported.name}"(\\s*\\([\\s\\S]*?\\)\\s*\\{)`);if(!c.test(r))throw new Error("The USDZ exporter produced an unsupported skeleton layout.");r=r.replace(c,(l,f)=>`def Xform "${i.target.exported.name}"${f}${Mn(i)}`)}n["model.usda"]=mt(r);let a={},s=0;for(let[i,c]of Object.entries(n)){s+=34+mt(i).length;let l=s&63;a[i]=l===4?c:[c,{extra:{12345:new Uint8Array(64-l)}}],s=c.length}return zo(a,{level:0})}function Go(e,t={}){t.signal?.throwIfAborted();let o=new In,n=new In;o.add(n);let r=new Set,a=[],s=[],i=[],c=new Map,l=[],f=0,u=0,m=()=>{a.forEach(d=>d.dispose()),s.forEach(d=>d.dispose()),i.forEach(d=>d.dispose())};try{for(let[S,{scene:A,objectBindings:g={},materialOverrides:w={}}]of e.entries()){cn(A),A.updateWorldMatrix(!0,!0);let v=new Map(Object.entries(g).map(([P,T])=>[T.modelObjectId??P,P]));A.traverse(P=>{let T=P;if(!T.isMesh||!T.geometry)return;for(let E=P;E;E=E.parent){let V=xe(E)??E.name??E.uuid;if(!E.visible||g[v.get(V)??V]?.visible===!1||g[v.get(V)??V]?.removed)return}let N=xe(T)??T.name??T.uuid,O=w[v.get(N)??N]??T.material;if(!O)throw new Error(`Material for ${N} is not ready. Wait for the model to finish loading.`);let h=Array.isArray(O)?O:[O],C=T.isInstancedMesh?T.count:1;if(T.userData.riDecal&&ge(T)&&T.parent){let E=Ce(T.parent);E&&T.bindMatrixInverse.copy(E)}let k=ge(T)?wt(T):T.geometry.clone();try{if(!ge(T)&&T.morphTargetInfluences?.some(y=>y!==0)){let y=k.getAttribute("position"),x=new Ne;for(let j=0;j<y.count;j++)T.getVertexPosition(j,x),y.setXYZ(j,x.x,x.y,x.z);k.morphAttributes={},k.computeVertexNormals()}if(!k.getAttribute("position"))throw new Error(`Mesh ${N} has no positions.`);let E=k.index?.count??k.getAttribute("position").count,V=Array.isArray(O)?k.groups:[{start:0,count:E,materialIndex:0}];if(!V.length)throw new Error(`Mesh ${N} has multiple materials without geometry groups.`);for(let y=0;y<C;y++){let x=T.matrixWorld.clone(),j=new qo;T.isInstancedMesh&&(T.getMatrixAt(y,j),x.multiply(j));for(let B of V){let q=h[B.materialIndex??0];if(!q)throw new Error(`A material group on ${N} is missing its material.`);if(!q.visible)continue;let W=q;if(!W.isMeshStandardMaterial||W.wireframe||W.vertexColors)throw new Error(`AR snapshot cannot preserve ${q.type}${W.wireframe?" wireframe":W.vertexColors?" vertex colors":""} on ${N}. Use a PBR material or provide arHandoff.createUSDZ.`);let K=Math.max(B.start,k.drawRange.start),J=Math.min(E,B.start+B.count,k.drawRange.start+k.drawRange.count);if(J<=K)continue;if(K%3||(J-K)%3)throw new Error(`Mesh ${N} has an incomplete triangle range.`);let _=new On;a.push(_);let I=Array.from({length:J-K},(D,$)=>k.index?k.index.getX(K+$):K+$);if(x.determinant()<0)for(let D=0;D<I.length;D+=3)[I[D+1],I[D+2]]=[I[D+2],I[D+1]];for(let[D,$]of Object.entries(k.attributes)){let G=new Float32Array(I.length*$.itemSize);for(let z=0;z<I.length;z++)for(let Y=0;Y<$.itemSize;Y++)G[z*$.itemSize+Y]=$.getComponent(I[z],Y);_.setAttribute(D,new Pe(G,$.itemSize))}ge(T)&&(_.setAttribute("arSourceVertex",new Pe(new Float32Array(I),1)),_.setAttribute("arNormalSign",new Pe(new Float32Array(I.length).fill(1),1))),_.setIndex(I.map((D,$)=>$)),_.applyMatrix4(x);let U=_.getAttribute("position");for(let D=0;D<U.count;D++)if(![U.getX(D),U.getY(D),U.getZ(D)].every(Number.isFinite))throw new Error(`Mesh ${N} contains invalid coordinates.`);_.getAttribute("normal")||_.computeVertexNormals();let L=W.clone();s.push(L);let F=W.userData.reactImmersiveConfiguredEmissive;if(F?.isColor&&L.emissive.copy(F),L.side===Fo){let D=_.toNonIndexed();a.push(D);let $=D.getAttribute("position").count,G=new On;a.push(G);for(let[z,Y]of Object.entries(D.attributes)){let De=new Float32Array($*Y.itemSize*2);for(let oe=0;oe<$;oe++)for(let le=0;le<Y.itemSize;le++){De[oe*Y.itemSize+le]=Y.getComponent(oe,le);let Dn=Math.floor(oe/3)*3+(2-oe%3);De[($+oe)*Y.itemSize+le]=Y.getComponent(Dn,le)*(z==="normal"||z==="arNormalSign"?-1:1)}G.setAttribute(z,new Pe(De,Y.itemSize))}L.side=dt,_.copy(G)}else if(L.side!==dt){let D=_.getIndex();for(let z=0;z<D.count;z+=3){let Y=D.getX(z+1);D.setX(z+1,D.getX(z+2)),D.setX(z+2,Y)}let $=_.getAttribute("normal");for(let z=0;z<$.count;z++)$.setXYZ(z,-$.getX(z),-$.getY(z),-$.getZ(z));let G=_.getAttribute("arNormalSign");if(G)for(let z=0;z<G.count;z++)G.setX(z,-G.getX(z));L.side=dt}if(T.isInstancedMesh&&T.instanceColor){let D=new _o;T.getColorAt(y,D),L.color.multiply(D)}for(let[D,$]of Object.entries(L)){if(!$?.isTexture)continue;let G=$;if(At(G)||!G.image||G.image.complete===!1)throw new Error(`Texture on ${N} is not ready. Wait for image loading or replace failed textures before preparing AR.`);let z=c.get(G);if(z||(z=G.clone(),c.set(G,z),i.push(z)),L[D]=z,!_.getAttribute(z.channel?`uv${z.channel}`:"uv"))throw new Error(`Texture on ${N} needs UV coordinates missing from this geometry.`)}if(T.userData.riDecal){_.computeBoundingBox();let D=Math.max(1e-6,_.boundingBox.getSize(new Ne).length()*1e-4),$=_.getAttribute("position"),G=_.getAttribute("normal");for(let z=0;z<$.count;z++)$.setXYZ(z,$.getX(z)+G.getX(z)*D,$.getY(z)+G.getY(z)*D,$.getZ(z)+G.getZ(z)*D)}let Q=new Wo(_,L);Q.name=`AR_${f++}`,n.add(Q),l.push({sourceIndex:S,source:T,exported:Q,bakedMatrix:x.clone(),instanceMatrix:j}),u+=(_.index?.count??_.getAttribute("position").count)/3,(L.clearcoat||L.transmission||L.iridescence||L.anisotropy)&&r.add("Advanced PBR effects may look different in Quick Look.")}}}finally{k.dispose()}})}if(!f||!u)throw new Error("There is no visible model geometry to send to AR.");let d=new $o().setFromObject(n),p=d.getSize(new Ne),M=d.getCenter(new Ne),b=t.scaleMode==="real-world"?1:1/Math.max(p.x,p.y,p.z,1e-9);return n.position.set(-M.x*b,-d.min.y*b,-M.z*b),n.scale.setScalar(b),o.updateMatrixWorld(!0),r.add("Viewer lighting, background, post-processing, annotations and measurement overlays stay in the web viewer."),{root:o,meshCount:f,triangleCount:u,scale:b,warnings:[...r],textures:i,motionMeshes:l,dispose:m}}catch(d){throw m(),d}}async function ga(e,t={}){let o=t.maxTextureSize??2048;if(!Number.isInteger(o)||o<256||o>4096)throw new Error("AR maxTextureSize must be an integer from 256 to 4096.");let n=Go(e,t),r=[];try{let a=vn(e,n.motionMeshes,t.signal),s=xn(a.skins,a.samples);n.root.updateMatrixWorld(!0);let{USDZExporter:i}=await import("three/examples/jsm/exporters/USDZExporter.js");t.signal?.throwIfAborted();for(let f of n.textures){if(!f.isCompressedTexture)continue;let{decompress:u}=await import("three/examples/jsm/utils/WebGLTextureUtils.js"),m=u(f,o);r.push(m),n.root.traverse(d=>{let p=d.material;if(p)for(let M of Object.keys(p))p[M]===f&&(p[M]=m)})}let c=await new i().parseAsync(n.root,{onlyVisible:!0,quickLookCompatible:!0,maxTextureSize:o});t.signal?.throwIfAborted();let l=kn(c,a,s);return{blob:new Blob([new Uint8Array(l)],{type:"model/vnd.usdz+zip"}),meshCount:n.meshCount,triangleCount:n.triangleCount,scale:n.scale,warnings:[...n.warnings,...a.warnings]}}catch(a){if(t.signal?.aborted)throw a;let s=a instanceof Error&&a.name==="SecurityError"?" Textures must allow cross-origin canvas access.":"";throw new Error(`Could not prepare the configured USDZ: ${a instanceof Error?a.message:"export failed"}${s}`)}finally{n.dispose(),r.forEach(a=>a.dispose())}}var Ve=Object.freeze([{id:"change-color",label:"Change Color",handling:"viewer",description:"Opens a color picker docked under the action and commits the result to style.material.baseColor."},{id:"change-material",label:"Change Material",handling:"viewer",description:"Opens the material picker so the viewer can swap the object's texture."},{id:"add-text",label:"Add Text",handling:"viewer",description:"Opens a text box docked under the action; the viewer's user types, clicks the object to place it, and can resize, turn, move, or remove it. Saved to the binding's decals."},{id:"add-image",label:"Add Image",handling:"viewer",description:"Lets the viewer's user choose an image, click the object to place it, and resize, turn, move, or remove it. Saved to the binding's decals."},{id:"toggle-visibility",label:"Toggle Visibility",handling:"viewer",description:"Flips the binding's visible flag."},{id:"toggle-light",label:"Toggle Light",handling:"viewer",description:"Turns the scene lights attached to this object on or off, or the object's own glow when none is attached."},{id:"change-light-color",label:"Change Light Color",handling:"viewer",description:"Opens a color picker docked under the action for the scene lights attached to this object, or the object's own glow."},{id:"set-brightness",label:"Set Brightness",handling:"viewer",description:"Opens a brightness slider docked under the action for the scene lights attached to this object, or the object's own glow."}]),ha="__custom__";function Ho(e){return Ve.find(t=>t.id===e)}var Tn=Ve.filter(e=>e.handling==="viewer").map(e=>e.id),Xo=new Set(["","New Action",...Ve.map(e=>e.label)]);function ya(e){return Xo.has(e.trim())}function Rn(e,t){let o=Array.from({length:t.length+1},(n,r)=>r);for(let n=1;n<=e.length;n+=1){let r=[n];for(let a=1;a<=t.length;a+=1){let s=o[a-1]+(e[n-1]===t[a-1]?0:1);r[a]=Math.min(r[a-1]+1,o[a]+1,s)}o=r}return o[t.length]}function Sa(e){if(Ho(e))return null;let t=e.trim().toLowerCase();if(!t)return null;let o=t.replace(/[^a-z0-9]/g,""),n=null;for(let r of Ve){let a=Math.min(Rn(t,r.id),Rn(o,r.id.replace(/[^a-z0-9]/g,"")));(!n||a<n.distance)&&(n={id:r.id,distance:a})}return n&&n.distance<=2?n.id:null}var Ko=.12,En=new Set;function Zo(e,t){return t?new Set(ve(e,t.target)):En}function Aa(e,t){let o=Zo(e.bindings,t);if(!t||o.size===0)return{...e,setAside:En};let n=Math.min(Math.max(t.ghostOpacity??Ko,0),1),r={...e.bindings},a=new WeakMap,s=new Set;for(let[i,c]of Object.entries(e.bindings)){if(o.has(i))continue;s.add(i);let l=t.mode==="hide"?{...c,visible:!1}:{...c,style:{...c.style,material:{...c.style?.material,opacity:Math.min(c.style?.material?.opacity??1,n)}}};r[i]=l,a.set(l,e.sourceOf(c))}return{bindings:r,pulses:e.pulses,sourceOf:i=>a.get(i)??e.sourceOf(i),setAside:s}}function Yo(e){return e.trim().replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").replace(/[^a-zA-Z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"").toLowerCase()}function Jo(e){return e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,t=>t.toUpperCase())}function Qo(e){let t=e.toLowerCase();return t.includes("light")?"light":t.includes("wheel")||t.includes("rim")||t.includes("tire")?"wheel":t.includes("glass")||t.includes("window")||t.includes("windshield")||t.includes("sunroof")?"glass":t.includes("seat")||t.includes("dashboard")||t.includes("console")||t.includes("doorpanel")?"interior":t.includes("floor")?"floor":t.includes("wall")?"wall":t.includes("door")?"door":t.includes("chair")||t.includes("table")||t.includes("sofa")||t.includes("bed")?"furniture":"other"}function Bn(e,t=!0){return e==="light"||e.endsWith("light")?[{id:"toggle-light",label:"Toggle Light",type:"command"},{id:"change-light-color",label:"Change Light Color",type:"command"},{id:"set-brightness",label:"Set Brightness",type:"command"}]:[{id:"change-color",label:"Change Color",type:"command"},...t?[{id:"change-material",label:"Change Material",type:"command"}]:[],{id:"toggle-visibility",label:"Toggle Visibility",type:"command"}]}function Pn(e,t=!0){let o=Qo(e);return{id:Yo(e),modelObjectId:e,type:o,label:Jo(e),status:"normal",selectable:!0,hoverable:!0,visible:!0,style:{},actions:Bn(o,t),metrics:{},metadata:{}}}function ka(e,t){return Object.fromEntries(e.map(o=>[o,Pn(o,!t?.has(o))]))}function Oa(e,t){let o=new Set,n={};for(let r of e){let a=Pn(r,!t?.has(r)),s=a.id||"object",i=s;for(let l=2;o.has(i);l++)i=`${s}-${l}`;o.add(i),a.id=i;let c=(a.actions??[]).filter(l=>Tn.includes(l.id));a.actions=c.length>0?c:Bn("other",!t?.has(r)),n[r]=a}return n}function Ia(e){let t=new Set;for(let[o,n]of Object.entries(ae(e).nodesById))Ct(n)||t.add(o);return t}function Ra(e){let{nodesById:t}=ae(e),o=[];for(let[n,r]of Object.entries(t)){let a=r;a.isMesh&&a.geometry&&r.name&&o.push(n)}return o.sort((n,r)=>n.localeCompare(r))}var zn={id:"identity",modelObjectId:"identity",label:"identity",type:"identity",group:"identity",tags:"identity",style:"appearance",decals:"appearance",transform:"transform",visible:"visibility",removed:"visibility",status:"visibility",selectable:"behavior",hoverable:"behavior",actions:"behavior",cameraState:"behavior",metadata:"data",metrics:"data"},er=Object.keys(zn),tr=new Set(["__proto__","prototype","constructor"]);function ce(e,t=new Set){if(e==null||typeof e=="string"||typeof e=="boolean")return e;if(typeof e=="number"){if(!Number.isFinite(e))throw new Error("Comparison values must be finite JSON data");return e}if(typeof e!="object"||t.has(e))throw new Error("Comparison values must be acyclic JSON data");t.add(e);let o=Array.isArray(e)?e.map(n=>ce(n,t)):Object.fromEntries(Object.entries(e).filter(([n,r])=>!tr.has(n)&&r!==void 0).map(([n,r])=>[n,ce(r,t)]));return t.delete(e),o}var Nn=e=>e&&typeof e=="object"&&!Array.isArray(e)&&!Object.keys(e).length;function Vn(e,t){let o=ce(e);o.visible=e.visible??!0,o.selectable=e.selectable??!0,o.hoverable=e.hoverable??!0,o.status=e.status??"normal",o.type=e.type??"other",o.tags=[...new Set(e.tags??[])].sort(),Nn(o.transform)&&delete o.transform,o.metadata=Object.fromEntries(Object.entries(e.metadata??{}).filter(([n])=>!t.includes(n)));for(let n of["metrics","style","metadata"])Nn(o[n])&&delete o[n];for(let n of["actions","decals"])Array.isArray(o[n])&&!o[n].length&&delete o[n];return o}function ze(e,t,o,n,r,a){let s=c=>c===void 0||Array.isArray(c)&&c.length===0;if(Object.is(e,t)||s(e)&&s(t)||typeof e=="number"&&typeof t=="number"&&Math.abs(e-t)<=r)return;let i=c=>!!c&&typeof c=="object"&&!Array.isArray(c);if(i(e)&&i(t)){for(let c of[...new Set([...Object.keys(e),...Object.keys(t)])].sort())ze(e[c],t[c],`${o}.${c}`,n,r,a);return}if(Array.isArray(e)&&Array.isArray(t)&&e.length===t.length){for(let c=0;c<e.length;c++)ze(e[c],t[c],`${o}[${c}]`,n,r,a);return}a.push({path:o,category:n,...e!==void 0?{before:ce(e)}:{},...t!==void 0?{after:ce(t)}:{}})}function Ea(e,t,o={}){let n=o.tolerance??1e-6;if(!Number.isFinite(n)||n<0)throw new Error("Comparison tolerance must be finite and nonnegative");let r=Object.entries(e.objectBindings).filter(([,S])=>!S.removed),a=Object.entries(t.objectBindings).filter(([,S])=>!S.removed),s=new Map(r),i=new Map(a),c=new Set,l=new Set,f=[],u=S=>{let A=o.matchBy??"modelObjectId",g=typeof A=="object"?S.metadata?.[A.metadataKey]:S[A];return typeof g=="string"&&g.length>0||typeof g=="number"?`${typeof g}:${g}`:null};function m(S,A,g){let w=S===void 0?void 0:s.get(S),v=A===void 0?void 0:i.get(A),P=[];if(w||v){let N=w?Vn(w,o.ignoreMetadataKeys??[]):{},O=v?Vn(v,o.ignoreMetadataKeys??[]):{};for(let h of er)ze(N[h],O[h],h,zn[h],n,P)}let T=w?v?P.length?"modified":"unchanged":"removed":"added";f.push({id:JSON.stringify([S??null,A??null]),identity:g,label:v?.label??w?.label??v?.modelObjectId??w?.modelObjectId??g,status:T,beforeKey:S,afterKey:A,beforeObjectId:w?.modelObjectId,afterObjectId:v?.modelObjectId,changes:P}),S!==void 0&&c.add(S),A!==void 0&&l.add(A)}let d=new Set;for(let[S,A]of Object.entries(o.mapping??{})){if(!s.has(S)||!i.has(A)||d.has(A))throw new Error("Comparison mapping must reference existing, unique binding keys");d.add(A),m(S,A,`mapped:${S}`)}let p=new Map;for(let[S,A,g]of[[r,c,"a"],[a,l,"b"]])for(let[w,v]of S){if(A.has(w))continue;let P=u(v);if(P===null){f.push({id:JSON.stringify([g,w]),identity:"",label:v.label??v.modelObjectId,status:"ambiguous",...g==="a"?{beforeKey:w,beforeObjectId:v.modelObjectId}:{afterKey:w,afterObjectId:v.modelObjectId},changes:[],message:"Missing match identity. Supply an explicit mapping or another match field."});continue}let T=p.get(P)??{a:[],b:[]};T[g].push(w),p.set(P,T)}for(let[S,A]of p){if(A.a.length<=1&&A.b.length<=1){m(A.a[0],A.b[0],S);continue}for(let g of["a","b"])for(let w of A[g]){let v=(g==="a"?s:i).get(w);f.push({id:JSON.stringify([g,w]),identity:S,label:v.label??v.modelObjectId,status:"ambiguous",...g==="a"?{beforeKey:w,beforeObjectId:v.modelObjectId}:{afterKey:w,afterObjectId:v.modelObjectId},changes:[],message:"Duplicate match identity. Supply an explicit one-to-one mapping."})}}f.sort((S,A)=>S.label.localeCompare(A.label)||S.id.localeCompare(A.id));let M=[];ze(ce(e.sceneConfig??{}),ce(t.sceneConfig??{}),"sceneConfig","scene",n,M);let b={added:0,removed:0,modified:0,unchanged:0,ambiguous:0};for(let S of f)b[S.status]++;return{version:1,objects:f,counts:b,sceneChanges:M}}function Ba(e,t,o){let n={added:"#22c55e",removed:"#f87171",modified:"#fbbf24",unchanged:"#94a3b8",ambiguous:"#c084fc"};return e.objects.flatMap(r=>{let a=t==="before"?r.beforeObjectId:r.afterObjectId;return a&&(r.status!=="unchanged"||r.id===o)?[{objectId:a,color:r.id===o?"#22d3ee":n[r.status]}]:[]})}var Na=["front","back","double"],Va=["normal","additive"];function La(e){ae(e);let t=[],o=[{node:e,path:"0",parentId:null}];for(;o.length;){let{node:r,path:a,parentId:s}=o.pop(),i=`node:${a}`,c=r.isMesh&&r.name?xe(r):null;t.push({id:i,parentId:s,name:r.name||r.type||"Group",...c?{objectId:c}:{}});for(let l=r.children.length-1;l>=0;l--)o.push({node:r.children[l],path:`${a}/${l}`,parentId:i})}let n=new Set;for(let r=t.length-1;r>=0;r--){let a=t[r];(a.objectId||n.has(a.id))&&(n.add(a.id),a.parentId&&n.add(a.parentId))}return t.filter(r=>n.has(r.id))}function _a(e){return structuredClone(e.style??{})}function Fa(e,t,o){let n=ve(e,t).filter(a=>!e[a].removed);if(!n.length)return e;let r={...e};for(let a of n)r[a]={...e[a],style:structuredClone(o)};return r}export{ae as a,xe as b,Ii as c,Ri as d,ln as e,nr as f,ir as g,sr as h,lr as i,Ot as j,fr as k,Tt as l,ne as m,jr as n,gn as o,kr as p,Or as q,Ir as r,Rr as s,Tr as t,Er as u,Br as v,Xe as w,fe as x,be as y,Vr as z,zr as A,Dr as B,$r as C,Ke as D,he as E,_r as F,Fr as G,qr as H,Wr as I,Dt as J,Lt as K,Ut as L,Ye as M,Xr as N,Kr as O,Zr as P,Yr as Q,ro as R,Qe as S,ao as T,ei as U,ti as V,qt as W,so as X,ye as Y,ni as Z,oi as _,Wt as $,ie as aa,pi as ba,Te as ca,Qt as da,wi as ea,xi as fa,So as ga,Ai as ha,Mi as ia,Ci as ja,vi as ka,cn as la,un as ma,bn as na,ga as oa,Ve as pa,ha as qa,Ho as ra,Tn as sa,ya as ta,Sa as ua,Zo as va,Aa as wa,Qo as xa,Pn as ya,ka as za,Oa as Aa,Ia as Ba,Ra as Ca,Ea as Da,Ba as Ea,Na as Fa,Va as Ga,La as Ha,_a as Ia,Fa as Ja};