@liveroom-tech/react-immersive 6.0.2 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -0
- package/dist/AnimationsTab-NUJTEMZ5.mjs +1 -0
- package/dist/AnnotationsTab-OHRVWRKI.mjs +1 -0
- package/dist/CinematicTab-IJAY2BS6.mjs +1 -0
- package/dist/ConfigureTab-UQRRATCY.mjs +6 -0
- package/dist/RulesTab-YVBZGJZX.mjs +1 -0
- package/dist/SequencesTab-IC5LWQ6N.css +1 -0
- package/dist/SequencesTab-RPJAG26Z.mjs +1 -0
- package/dist/binding-builder.css +1 -1
- package/dist/binding-builder.d.mts +3 -3
- package/dist/binding-builder.d.ts +3 -3
- package/dist/binding-builder.js +76 -23
- package/dist/binding-builder.mjs +1 -1
- package/dist/chunk-2DV2UCQH.mjs +1 -0
- package/dist/chunk-37YITTIK.mjs +1 -0
- package/dist/chunk-5FLX45O5.mjs +2 -0
- package/dist/chunk-6CTCV2Q5.mjs +1 -0
- package/dist/chunk-7JCFNZJM.mjs +1 -0
- package/dist/chunk-7OWHW66D.mjs +1 -0
- package/dist/chunk-AL6UIGWP.mjs +1 -0
- package/dist/chunk-BNKTI3CY.mjs +1 -0
- package/dist/chunk-CCBFMNAU.mjs +1 -0
- package/dist/chunk-E24EFHB5.mjs +1 -0
- package/dist/chunk-EV6THDXD.mjs +1 -0
- package/dist/chunk-F5QSXMME.mjs +1 -0
- package/dist/chunk-FGAJ2UT7.mjs +1 -0
- package/dist/chunk-FXV4CLAK.mjs +1 -0
- package/dist/chunk-GV4ZRXL6.mjs +1 -0
- package/dist/chunk-KHN55ZM7.mjs +3 -0
- package/dist/chunk-LX3GXQNU.mjs +1 -0
- package/dist/chunk-OPZJDP7T.mjs +1 -0
- package/dist/chunk-OREKYGO3.mjs +83 -0
- package/dist/chunk-PBVBZYOG.mjs +47 -0
- package/dist/chunk-T6AYLPCC.mjs +1 -0
- package/dist/hosted.css +1 -1
- package/dist/hosted.d.mts +22 -6
- package/dist/hosted.d.ts +22 -6
- package/dist/hosted.js +75 -22
- package/dist/hosted.mjs +1 -1
- package/dist/index.css +1 -1
- package/dist/index.d.mts +66 -6
- package/dist/index.d.ts +66 -6
- package/dist/index.js +69 -21
- package/dist/index.mjs +1 -1
- package/dist/{modelFileResolver-Co7j1tdQ.d.mts → modelFileResolver-BEW_95id.d.mts} +52 -7
- package/dist/{modelFileResolver-Co7j1tdQ.d.ts → modelFileResolver-BEW_95id.d.ts} +52 -7
- package/dist/{modelViewerProps-BibuMND7.d.ts → modelViewerProps-C7saa0i2.d.mts} +173 -3
- package/dist/{modelViewerProps-Ce4-wb57.d.mts → modelViewerProps-CbK_4uZj.d.ts} +173 -3
- package/dist/{publicProps-BaJHCDa_.d.mts → publicProps-NKTiohZO.d.mts} +1 -1
- package/dist/{publicProps-CP18d_mt.d.ts → publicProps-z7cJhUH8.d.ts} +1 -1
- package/dist/simple-model-viewer.css +1 -1
- package/dist/simple-model-viewer.d.mts +25 -3
- package/dist/simple-model-viewer.d.ts +25 -3
- package/dist/simple-model-viewer.js +49 -3
- package/dist/simple-model-viewer.mjs +1 -1
- package/dist/utils.d.mts +47 -4
- package/dist/utils.d.ts +47 -4
- package/dist/utils.js +2 -2
- package/dist/utils.mjs +1 -1
- package/package.json +5 -1
- package/dist/chunk-33SUWPXC.mjs +0 -3
- package/dist/chunk-4JMJALRO.mjs +0 -2
- package/dist/chunk-EIBW7ZJE.mjs +0 -81
- package/dist/chunk-KFTJMFYF.mjs +0 -1
- package/dist/chunk-OTSCPJWF.mjs +0 -1
- package/dist/chunk-P2JZ5Z7I.mjs +0 -1
- package/dist/chunk-V7WZUWJ5.mjs +0 -1
package/dist/chunk-4JMJALRO.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{a as pe,e as Je,h as Ze,s as Qe}from"./chunk-V7WZUWJ5.mjs";import{Color as en}from"three";var Xn=["position","rotation","scale","visible","baseColor","emissive","opacity","roughness","metalness","emissiveIntensity"],Jn=["linear","ease-in","ease-out","ease-in-out","step"],Zn=new Set(["position","rotation","scale"]),Qn=new Set(["baseColor","emissive"]),W=e=>typeof e=="string"&&e.length>0&&e.length<=256,K=e=>typeof e=="number"&&Number.isFinite(e),ke=e=>Array.isArray(e)&&e.length===3&&e.every(K);function oe(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function H(e){throw new Error(`Invalid sequences: ${e}`)}function et(e){return e.kind==="object"?JSON.stringify([e.kind,e.objectId,e.property]):e.kind==="clip"?JSON.stringify([e.kind,e.clip]):"camera"}function nt(e,n){if(n.kind==="camera")return oe(e)&&ke(e.position)&&ke(e.target)&&(e.fov===null||K(e.fov)&&e.fov>0&&e.fov<180)&&K(e.zoom)&&e.zoom>0;if(n.kind==="clip")return K(e)&&e>=0;let t=n.property;return Zn.has(t)?ke(e)&&(t!=="scale"||e.every(r=>r!==0)):Qn.has(t)?typeof e=="string"&&/^#[\da-f]{6}$/i.test(e):t==="visible"?typeof e=="boolean":K(e)&&e>=0&&(t==="emissiveIntensity"||e<=1)}function nn(e){(!Array.isArray(e)||e.length>64)&&H("expected up to 64 sequences.");let n=new Set,t=0;return e.map(r=>{(!oe(r)||!W(r.id)||n.has(r.id)||!(typeof r.name=="string"&&W(r.name.trim()))||!K(r.duration)||r.duration<.1||r.duration>3600||typeof r.loop!="boolean"||typeof r.autoPlay!="boolean"||!Array.isArray(r.tracks)||r.tracks.length>128)&&H("each sequence needs a unique id, name, 0.1\u20133600 second duration, loop/autoplay flags and up to 128 tracks."),n.add(r.id);let o=new Set,i=new Set,a=r.tracks.map(s=>{(!oe(s)||!W(s.id)||o.has(s.id)||!(typeof s.name=="string"&&W(s.name.trim()))||!oe(s.target)||!Array.isArray(s.keyframes)||s.keyframes.length>2048||s.muted!==void 0&&typeof s.muted!="boolean")&&H("invalid or duplicate track."),o.add(s.id);let c;s.target.kind==="camera"?c={kind:"camera"}:s.target.kind==="clip"&&W(s.target.clip)?c={kind:"clip",clip:s.target.clip}:s.target.kind==="object"&&W(s.target.objectId)&&Xn.includes(s.target.property)?c={kind:"object",objectId:s.target.objectId,property:s.target.property}:H("unknown track target or property.");let l=et(c);i.has(l)&&H("only one track may own each target property in a sequence."),i.add(l);let f=new Set,m=new Set,d=s.keyframes.map(u=>{++t>2e4&&H("too many keyframes."),(!oe(u)||!W(u.id)||f.has(u.id)||!K(u.time)||u.time<0||u.time>r.duration||m.has(u.time)||u.easing!==void 0&&!Jn.includes(u.easing)||!nt(u.value,c))&&H("keyframes need unique ids/times, valid values and times inside the sequence."),f.add(u.id),m.add(u.time);let g=u.value,h=c.kind==="camera"?{position:[...g.position],target:[...g.target],fov:g.fov,zoom:g.zoom}:Array.isArray(u.value)?[...u.value]:u.value;return{id:u.id,time:u.time,value:h,...u.easing?{easing:u.easing}:{}}}).sort((u,g)=>u.time-g.time);return{id:s.id,name:s.name.trim(),target:c,keyframes:d,...s.muted!==void 0?{muted:s.muted}:{}}});return{id:r.id,name:r.name.trim(),duration:r.duration,loop:r.loop,autoPlay:r.autoPlay,tracks:a}})}function tt(e,n="ease-in-out"){let t=Math.max(0,Math.min(1,e));return n==="step"?0:n==="ease-in"?t*t:n==="ease-out"?1-(1-t)**2:n==="ease-in-out"?t*t*(3-2*t):t}var be=(e,n,t)=>e+(n-e)*t,Be=(e,n,t)=>e.map((r,o)=>be(r,n[o],t));function dr(e,n){if(e.muted||!e.keyframes.length||!Number.isFinite(n))return null;let t=e.keyframes;if(n<t[0].time)return null;let r=t[0],o;for(let c of t)if(c.time<=n)r=c;else{o=c;break}if(!o||typeof r.value=="boolean")return structuredClone(r.value);let i=tt((n-r.time)/(o.time-r.time),r.easing);if(typeof r.value=="number"&&typeof o.value=="number")return be(r.value,o.value,i);if(typeof r.value=="string"&&typeof o.value=="string")return`#${new en(r.value).lerp(new en(o.value),i).getHexString()}`;if(Array.isArray(r.value)&&Array.isArray(o.value))return Be(r.value,o.value,i);let a=r.value,s=o.value;return{position:Be(a.position,s.position,i),target:Be(a.target,s.target,i),fov:a.fov!==null&&s.fov!==null?be(a.fov,s.fov,i):a.fov,zoom:be(a.zoom,s.zoom,i)}}function ur(e,n){return{...e,keyframes:[...e.keyframes.filter(t=>t.id!==n.id&&Math.abs(t.time-n.time)>1e-6),n].sort((t,r)=>t.time-r.time)}}function fr(e){let n=e.trim();return n?/\.(hdr|exr|jpg|jpeg|png|webp)(?:[?#].*)?$/i.test(n):!1}var gr=["none","directional","point","spot","hemisphere"],pr=["pbr","matcap","uv-checker"],br=["apartment","city","dawn","forest","lobby","night","park","studio","sunset","warehouse"];var yr=["sporadic","constantMild","constantWild"],hr=["linear","radial","mirroredLinear"],Sr=["verySmall","small","medium","large","veryLarge","huge"];var Ee={enabled:!1,axis:"y",position:.5,flip:!1},rt={clips:[],autoplayClip:null},ot={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}},ne={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:[6,12,6],attachedToCamera:!1,castShadow:!0,shadowBias:-5e-4,visible:!0},{id:"light-fill",type:"directional",color:"#ffffff",intensity:0,position:[-6,8,-6],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:"apartment",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:ot,animations:rt,annotations:[]};function ie(e){let n=f=>{throw new Error(`Invalid section: ${f}`)},t=f=>f&&typeof f=="object"&&!Array.isArray(f)?f:n("expected an object"),r=f=>typeof f=="string"&&f.trim().length>0&&f.length<=200?f:n("expected a nonempty name or id (up to 200 characters)"),o=f=>typeof f=="number"&&Number.isFinite(f)&&f>=0&&f<=1?f:n("position must be between 0 and 1"),i=f=>!Array.isArray(f)||f.length!==3||!f.every(m=>typeof m=="number"&&Number.isFinite(m))||Math.hypot(...f)<1e-8?n("normal must be a finite, nonzero vector"):[...f],a=f=>{let m=t(f);return!["x","y","z"].includes(m.axis)||typeof m.enabled!="boolean"||typeof m.flip!="boolean"?n("invalid plane"):{enabled:m.enabled,axis:m.axis,position:o(m.position),flip:m.flip,...m.normal!==void 0?{normal:i(m.normal)}:{}}},s=f=>{let m=t(f),d=a(m);if(m.mode!==void 0){if(!["plane","planes","box"].includes(m.mode))return n("invalid mode");d.mode=m.mode}if(m.planes!==void 0){if(!Array.isArray(m.planes)||m.planes.length>6)return n("at most six planes are supported");let u=new Set;d.planes=m.planes.map(g=>{let h=t(g),p=r(h.id);return u.has(p)?n("duplicate plane id"):(u.add(p),{...a(h),id:p,name:r(h.name)})})}if(m.activePlaneId!==void 0&&(d.activePlaneId=r(m.activePlaneId)),m.invertBox!==void 0){if(typeof m.invertBox!="boolean")return n("invalid box inversion");d.invertBox=m.invertBox}if(m.box!==void 0){let u=t(m.box),g=b=>!Array.isArray(b)||b.length!==3?n("invalid box bounds"):b.map(o),h=g(u.min),p=g(u.max);if(h.some((b,y)=>b>=p[y]))return n("box minimum must be below its maximum on every axis");d.box={min:h,max:p}}return d},c=t(e),l=s(c);if(c.presets!==void 0){if(!Array.isArray(c.presets)||c.presets.length>32)return n("at most 32 presets are supported");let f=new Set;l.presets=c.presets.map(m=>{let d=t(m),u=r(d.id);return f.has(u)?n("duplicate preset id"):(f.add(u),{id:u,name:r(d.name),settings:s(d.settings)})})}return l}function Or(e){let{presets:n,...t}=ie(e);return t}function Ar(e){try{return ie(e)}catch{return Ee}}function Mr(e,n){if(!n||typeof n!="object"||Array.isArray(n))throw new Error("Invalid section: expected an object");let t=["enabled","axis","position","flip"].every(r=>Object.prototype.hasOwnProperty.call(n,r));return ie(t?n:{...Ee,...e,...n})}import{Box3 as tn,Matrix4 as he,Quaternion as it,Vector3 as ye,Euler as st}from"three";var vr={version:1,placements:{},gridSize:1};function Re(e){return e.id??e.url}function se(e){if(!e||typeof e!="object"||Array.isArray(e))throw new Error("Expected an asset transform object.");let n={};for(let t of["position","rotation","scale"]){let r=e[t];if(r!==void 0){if(!Array.isArray(r)||r.length!==3||!r.every(o=>typeof o=="number"&&Number.isFinite(o))||t==="scale"&&r.some(o=>o===0))throw new Error(`Invalid asset ${t}: expected three finite ${t==="scale"?"nonzero ":""}numbers.`);n[t]=[...r]}}return n}function Ir(e){if(!e||typeof e!="object"||Array.isArray(e))throw new Error("Invalid scene composition.");let n=e;if(n.version!==1||!Number.isFinite(n.gridSize)||n.gridSize<=0||!n.placements||typeof n.placements!="object"||Array.isArray(n.placements)||Object.keys(n.placements).length>256)throw new Error("Invalid scene composition version, grid size or placements (maximum 256).");let t={};for(let[r,o]of Object.entries(n.placements)){if(!r||["__proto__","constructor","prototype"].includes(r))throw new Error("Invalid asset instance ID.");let i=se(o);if(o.label!==void 0&&(typeof o.label!="string"||o.label.length>512))throw new Error("Invalid asset label.");for(let a of["visible","deleted"])if(o[a]!==void 0&&typeof o[a]!="boolean")throw new Error(`Invalid asset ${a}.`);t[r]={...i,...o.label!==void 0?{label:o.label}:{},...o.visible!==void 0?{visible:o.visible}:{},...o.deleted!==void 0?{deleted:o.deleted}:{}}}return{version:1,gridSize:n.gridSize,placements:t}}function Tr(e,n){if(!Number.isFinite(n)||n<=0)throw new Error("Grid size must be positive.");let t=se(e),[r,o,i]=t.position??[0,0,0];return{...t,position:[Math.round(r/n)*n,o,Math.round(i/n)*n]}}function kr(e,n){let t=se(e),r=t.position??[0,0,0],o=new he().compose(new ye(...r),new it().setFromEuler(new st(...t.rotation??[0,0,0])),new ye(...t.scale??[1,1,1])),i=new tn(new ye(...n.min),new ye(...n.max)).applyMatrix4(o);if(!Number.isFinite(i.min.y))throw new Error("Cannot place an asset with empty bounds.");return{...t,position:[r[0],r[1]-i.min.y,r[2]]}}function Br(e){e.updateWorldMatrix(!0,!0);let n=new he().copy(e.parent?.parent?.matrixWorld??new he).invert(),t=new tn;return e.traverse(r=>{let o=r;o.geometry&&(o.geometry.computeBoundingBox(),o.geometry.boundingBox&&t.union(o.geometry.boundingBox.clone().applyMatrix4(new he().multiplyMatrices(n,o.matrixWorld))))}),t.isEmpty()||![...t.min.toArray(),...t.max.toArray()].every(Number.isFinite)?null:{min:t.min.toArray(),max:t.max.toArray()}}import{BufferGeometry as at,Float32BufferAttribute as ct,Matrix4 as on,Mesh as Ne,ShapeUtils as lt,Vector2 as sn,Vector3 as I,Vector4 as dt}from"three";function an(e){if(e.length!==3)return null;let n=new I(...e[0]).sub(new I(...e[1])),t=new I(...e[2]).sub(new I(...e[1]));return n.lengthSq()===0||t.lengthSq()===0?null:Math.acos(Math.max(-1,Math.min(1,n.normalize().dot(t.normalize()))))*180/Math.PI}function cn(e,n){if(!e.normal)return null;let t=new I(...e.normal);if(t.lengthSq()===0)return null;t.normalize();let r=new I(...n),o=r.clone().sub(new I(...e.position)).dot(t);return{distance:Math.abs(o),projection:r.addScaledVector(t,-o).toArray()}}function ln(e){if(e.length<3)return{error:"Pick at least three points to finish the area."};let n=new I(...e[0]),t=e.map(p=>new I(...p).sub(n)),r=Math.max(...t.map(p=>p.length()));if(r===0)return{error:"Area points must be distinct."};let o=new I;for(let p=1;p<t.length-1;p+=1){let b=t[p].clone().cross(t[p+1]);b.lengthSq()>o.lengthSq()&&o.copy(b)}if(o.length()<=r*r*1e-10)return{error:"Area points must not lie on one straight line."};o.normalize();let i=Math.max(r*1e-5,Number.EPSILON*Math.max(...e.flat().map(Math.abs))*32);if(t.some(p=>Math.abs(p.dot(o))>i))return{error:"Area points must lie on one plane."};let a=t.find(p=>p.length()>r*1e-10).clone().normalize(),s=o.clone().cross(a).normalize(),c=t.map(p=>new sn(p.dot(a),p.dot(s))),l=(p,b,y)=>(b.x-p.x)*(y.y-p.y)-(b.y-p.y)*(y.x-p.x),f=r*r*1e-10,m=(p,b,y)=>Math.abs(l(p,b,y))<=f&&y.x>=Math.min(p.x,b.x)-r*1e-10&&y.x<=Math.max(p.x,b.x)+r*1e-10&&y.y>=Math.min(p.y,b.y)-r*1e-10&&y.y<=Math.max(p.y,b.y)+r*1e-10;for(let p=0;p<c.length;p+=1){let b=c[p],y=c[(p+1)%c.length];if(b.distanceTo(y)<=r*1e-10)return{error:"Area points must be distinct."};for(let w=p+1;w<c.length;w+=1){if(w===p+1||p===0&&w===c.length-1)continue;let O=c[w],x=c[(w+1)%c.length],A=l(b,y,O),E=l(b,y,x),R=l(O,x,b),re=l(O,x,y);if(A*E<0&&R*re<0||m(b,y,O)||m(b,y,x)||m(O,x,b)||m(O,x,y))return{error:"Area edges must not cross or touch each other."}}}let d=0,u=0,g=0;for(let p=0;p<c.length;p+=1){let b=c[p],y=c[(p+1)%c.length],w=b.x*y.y-y.x*b.y;d+=w,u+=(b.x+y.x)*w,g+=(b.y+y.y)*w}if(Math.abs(d)<=f)return{error:"The polygon has no measurable area."};let h=n.clone().addScaledVector(a,u/(3*d)).addScaledVector(s,g/(3*d));return{area:Math.abs(d)/2,center:h.toArray(),triangles:lt.triangulateShape(c,[])}}function Pe(e,n){if(e.length<2)return 0;let t=0;for(let r=1;r<e.length;r+=1)t+=new I(...e[r]).distanceTo(new I(...e[r-1]));return n&&(t+=new I(...e[e.length-1]).distanceTo(new I(...e[0]))),t}var ut=1e-5;function mt(e,n){let t=e.getAttribute("position"),r=e.getIndex(),o=t.count,i=Math.max(n,1e-9),a=(g,h,p)=>`${Math.round(g/i)}_${Math.round(h/i)}_${Math.round(p/i)}`,s=new Int32Array(o),c=[],l=new Map;for(let g=0;g<o;g+=1){let h=t.getX(g),p=t.getY(g),b=t.getZ(g),y=a(h,p,b),w=l.get(y);w===void 0&&(w=c.length,c.push(new I(h,p,b)),l.set(y,w)),s[g]=w}let f=c.map(()=>new Map),m=(g,h)=>{if(g===h)return;let p=c[g].distanceTo(c[h]);f[g].has(h)||f[g].set(h,p),f[h].has(g)||f[h].set(g,p)},d=(r?r.count:o)/3,u=g=>r?r.getX(g):g;for(let g=0;g<d;g+=1)m(s[u(g*3)],s[u(g*3+1)]),m(s[u(g*3+1)],s[u(g*3+2)]),m(s[u(g*3+2)],s[u(g*3)]);return{weldedId:s,weldedPosition:c,neighbors:f}}function ft(e,n,t){let r=new Map([[n,0]]),o=[n];for(let i=0;i<t&&o.length>0;i+=1){let a=[];for(let s of o){let c=r.get(s)??0;for(let[l,f]of e[s]??[])r.has(l)||(r.set(l,c+f),a.push(l))}o=a}return r}function gt(e){let t=(Math.abs(e.y)<.9?new I(0,1,0):new I(1,0,0)).clone().cross(e).normalize(),r=e.clone().cross(t).normalize();return[t,r]}function pt(e,n,t){let[r,o]=gt(n),i=0,a=0,s=0;for(let h of t){let p=h.clone().sub(e),b=p.dot(r),y=p.dot(o);i+=b*b,a+=b*y,s+=y*y}let c=i+s,l=i*s-a*a,f=Math.sqrt(Math.max(0,c*c/4-l)),m=c/2+f,d=1,u=0;Math.abs(a)>1e-12?(d=m-s,u=a):s>i&&(d=0,u=1);let g=Math.hypot(d,u)||1;return r.clone().multiplyScalar(d/g).add(o.clone().multiplyScalar(u/g)).normalize()}function bt(e,n,t,r){let o=e.getAttribute("position"),i=e.getIndex(),a=o.count,s=(i?i.count:a)/3,c=d=>i?i.getX(d):d,l=d=>new I(o.getX(d),o.getY(d),o.getZ(d)).applyMatrix4(n),f=d=>d.clone().sub(t).dot(r),m=[];for(let d=0;d<s;d+=1){let u=l(c(d*3)),g=l(c(d*3+1)),h=l(c(d*3+2)),p=f(u),b=f(g),y=f(h),w=[],O=(x,A,E,R)=>{A>0!=R>0&&w.push(x.clone().lerp(E,A/(A-R)))};O(u,p,g,b),O(g,b,h,y),O(h,y,u,p),w.length===2&&m.push([w[0],w[1]])}return m}function yt(e,n){let t=Math.max(n,1e-9),r=d=>`${Math.round(d.x/t)}_${Math.round(d.y/t)}_${Math.round(d.z/t)}`,o=new Map,i=[],a=d=>{let u=r(d),g=o.get(u);return g===void 0&&(g=i.length,i.push(d),o.set(u,g)),g},s=[],c=d=>{for(;s.length<=d;)s.push(new Map)};for(let[d,u]of e){let g=a(d),h=a(u);g!==h&&(c(g),c(h),s[g].set(h,(s[g].get(h)??0)+1),s[h].set(g,(s[h].get(g)??0)+1))}let l=(d,u)=>d<u?`${d}_${u}`:`${u}_${d}`,f=new Set,m=[];for(let d=0;d<s.length;d+=1)for(let u of s[d]?.keys()??[]){if(f.has(l(d,u)))continue;let g=[d],h=d,p=u;f.add(l(h,p));let b=0;for(;p!==d&&p>=0&&b<s.length+4;){g.push(p);let y=[...s[p].keys()].filter(O=>O!==h),w;if(y.length<=1)w=y[0];else{let O=i[p].clone().sub(i[h]).normalize(),x=-1/0;for(let A of y){let E=i[A].clone().sub(i[p]).normalize(),R=O.dot(E);R>x&&(x=R,w=A)}}if(w===void 0){p=-1;break}f.add(l(p,w)),h=p,p=w,b+=1}p===d&&g.length>=3&&m.push(g.map(y=>i[y]))}return m}function rn(e,n){let t=1/0;for(let r of e)t=Math.min(t,r.distanceTo(n));return t}function ht(e,n){let t=0,r=1/0;return e.forEach((o,i)=>{let a=o.distanceTo(n);a<r&&(r=a,t=i)}),[...e.slice(t),...e.slice(0,t)]}function dn(e,n,t,r,o){let i=bt(e,n,r,o);if(i.length===0)return{error:"Couldn't trace a loop around this point."};let a=yt(i,t*n.getMaxScaleOnAxis());if(a.length===0)return{error:"The surface here doesn't form a closed loop around this point (it may be near an open edge)."};let s=a[0],c=rn(s,r);for(let f of a.slice(1)){let m=rn(f,r);m<c&&(c=m,s=f)}let l=ht(s,r).map(f=>f.toArray());return{points:l,length:Pe(l,!0)}}function un(e){if(!(e.object instanceof Ne)||!e.face)return null;let n=e.object,t=n.geometry;if(n.isSkinnedMesh||n.morphTargetInfluences?.some(i=>i!==0)){let i=t.getAttribute("position"),a=new ct(new Float32Array(i.count*3),3),s=new I;for(let c=0;c<i.count;c++)n.getVertexPosition(c,s),a.setXYZ(c,s.x,s.y,s.z);t=new at().setAttribute("position",a).setIndex(t.getIndex())}let r=n.matrixWorld.clone();if(e.instanceId!==void 0&&"getMatrixAt"in n){let i=new on;n.getMatrixAt(e.instanceId,i),r.multiply(i)}t.computeBoundingSphere();let o=t.boundingSphere&&t.boundingSphere.radius>0?t.boundingSphere.radius:1;return{face:e.face,geometry:t,matrix:r,weldTolerance:o*ut}}function Nr(e,n=6){let t=un(e);if(!t)return{error:"Pick a point on the mesh surface to trace a loop around it."};let{face:r,geometry:o,matrix:i,weldTolerance:a}=t,s=mn(e);if(!s)return{error:"Pick a point on the mesh surface to trace a loop around it."};let c=s[1].clone().sub(s[0]).cross(s[2].clone().sub(s[0]));if(c.lengthSq()===0)return{error:"Couldn't determine the surface direction at this point."};c.normalize();let{weldedId:l,weldedPosition:f,neighbors:m}=mt(o,a),d=o.getAttribute("position"),u=e.point.clone().applyMatrix4(i.clone().invert()),g=[r.a,r.b,r.c],h=g[0],p=1/0;for(let A of g){let R=new I(d.getX(A),d.getY(A),d.getZ(A)).distanceTo(u);R<p&&(p=R,h=A)}let b=l[h],y=f[b].clone().applyMatrix4(i),w=ft(m,b,n),O=[];for(let A of w.keys())O.push(f[A].clone().applyMatrix4(i));if(O.length<6)return{error:"Not enough surface detail near this point to trace a loop. Try a different spot."};let x=pt(y,c,O);return dn(o,i,a,e.point.clone(),x)}function Pr(e,n=new I(0,1,0)){let t=un(e);if(!t)return{error:"Pick a point on the mesh surface to trace a loop around it."};let{geometry:r,matrix:o,weldTolerance:i}=t,a=n.clone().normalize();return a.lengthSq()===0?{error:"Couldn't determine a horizontal direction."}:dn(r,o,i,e.point.clone(),a)}function mn(e){if(!(e.object instanceof Ne)||!e.face)return null;let n=e.object,t=n.matrixWorld.clone();if(e.instanceId!==void 0&&"getMatrixAt"in n){let r=new on;n.getMatrixAt(e.instanceId,r),t.multiply(r)}return[e.face.a,e.face.b,e.face.c].map(r=>n.getVertexPosition(r,new I).applyMatrix4(t))}function Vr(e){if(!(e.object instanceof Ne))return!1;for(let t=e.object;t;t=t.parent)if(!t.visible||t.userData.riEditorGizmo||t.userData.riDecal)return!1;return(Array.isArray(e.object.material)?e.object.material:[e.object.material])[e.face?.materialIndex??0]?.visible!==!1}function Lr(e,n,t,r,o,i=12){let a=mn(e),s=a?a[1].clone().sub(a[0]).cross(a[2].clone().sub(a[0])).normalize():null,c={position:e.point.toArray(),...s&&s.lengthSq()>0?{normal:s.toArray()}:{},...a?{faceVertices:a.map(d=>d.toArray())}:{}};if(!a||o==="none")return c;let l=d=>{let u=new dt(d.x,d.y,d.z,1).applyMatrix4(n.matrixWorldInverse).applyMatrix4(n.projectionMatrix);return u.w<=0||u.z/u.w<-1||u.z/u.w>1?null:{screen:new sn((u.x/u.w+1)*r.width/2,(1-u.y/u.w)*r.height/2),w:u.w}},f=a.map(l),m=i;if((o==="vertex"||o==="auto")&&(f.forEach((d,u)=>{let g=d?.screen.distanceTo(t)??1/0;g<=m&&(m=g,c.position=a[u].toArray(),c.snapped="vertex")}),c.snapped))return c;if(o==="edge"||o==="auto")for(let d=0;d<3;d+=1){let u=(d+1)%3,g=f[d],h=f[u];if(!g||!h)continue;let p=h.screen.clone().sub(g.screen);if(p.lengthSq()===0)continue;let b=Math.max(0,Math.min(1,t.clone().sub(g.screen).dot(p)/p.lengthSq())),y=g.screen.clone().addScaledVector(p,b).distanceTo(t);if(y<=m){m=y;let w=b*g.w/((1-b)*h.w+b*g.w);c.position=a[d].clone().lerp(a[u],w).toArray(),c.snapped="edge"}}return c}var St=["m","cm","mm","in","ft"],Ve={m:1,cm:.01,mm:.001,in:.0254,ft:.3048},xt=["distance","angle","area","pointToPlane","wrap","wrapHorizontal"];function Le(e){return St.includes(e)}function wt(e={},n="m"){let t=e.displayUnit??n,r=e.metersPerUnit??Ve[e.sourceUnit??"m"];if(!Number.isFinite(r)||r<=0)throw new Error("Measurement scale must be a positive finite number.");return{displayUnit:t,metersPerUnit:r,factor:Le(t)?r/Ve[t]:1}}function Ur(e){try{return new URL(e,typeof window<"u"?window.location?.href:void 0).href}catch{return e}}function Dr(e,n,t,r={}){if(!Le(t)||!Number.isFinite(e)||e<=0||!Number.isFinite(n)||n<=0)throw new Error("Calibration needs two distinct points and a positive known distance.");let o=n*Ve[t]/e;if(!Number.isFinite(o)||o<=0)throw new Error("Calibration scale is outside the supported range.");return{...r,metersPerUnit:o}}function fn(e,n){let t=n.map(r=>r.position);if(e==="angle"){let r=an(t);return r===null?null:{value:r,dimension:0}}if(e==="area"){let r=ln(t);return"error"in r?null:{value:r.area,dimension:2}}if(e==="pointToPlane"){let r=n.length===2?cn(n[0],n[1].position):null;return r?{value:r.distance,dimension:1}:null}return n.length<(e==="distance"?2:3)?null:{value:Pe(t,e!=="distance"),dimension:1}}function Ot(e,n={},t="m",r=e.points,o=e.approximate?"approximate":"ready"){let i=fn(e.tool,r),{factor:a,displayUnit:s}=wt(n,t),c=o==="ready"||o==="approximate",l=c&&i?i.value*a**i.dimension:null;return{id:e.id,status:c?i&&l!==null&&Number.isFinite(l)?o:"invalid":o,rawValue:c&&i&&Number.isFinite(i.value)?i.value:null,value:l!==null&&Number.isFinite(l)?l:null,unit:e.tool==="angle"?"\xB0":e.tool==="area"?`${s}\xB2`:s}}function ae(e){function n(){throw new Error("Invalid measurements: expected settings and valid named measurements with finite points.")}let t=s=>!!s&&typeof s=="object"&&!Array.isArray(s),r=s=>Array.isArray(s)&&s.length===3&&s.every(c=>typeof c=="number"&&Number.isFinite(c));typeof e=="string"&&(e.length>5*1024*1024&&n(),e=JSON.parse(e)),(!t(e)||e.version!==void 0&&e.version!==1||!t(e.settings)||!Array.isArray(e.items)||e.items.length>256)&&n();let o={};for(let s of["sourceUnit","displayUnit"])e.settings[s]!==void 0&&(Le(e.settings[s])||n(),o[s]=e.settings[s]);e.settings.metersPerUnit!==void 0&&((typeof e.settings.metersPerUnit!="number"||!Number.isFinite(e.settings.metersPerUnit)||e.settings.metersPerUnit<=0)&&n(),o.metersPerUnit=e.settings.metersPerUnit);let i=new Set,a=e.items.map(s=>{(!t(s)||typeof s.id!="string"||!s.id||i.has(s.id)||typeof s.name!="string"||!s.name.trim()||typeof s.modelId!="string"||!s.modelId||!xt.includes(s.tool)||!Array.isArray(s.points)||s.points.length>8192||typeof s.createdAt!="string"||!Number.isFinite(Date.parse(s.createdAt)))&&n(),i.add(s.id),s.tilesetUrl!==void 0&&s.tilesetUrl!==null&&typeof s.tilesetUrl!="string"&&n(),(s.visible!==void 0&&typeof s.visible!="boolean"||s.approximate!==void 0&&typeof s.approximate!="boolean")&&n();let c=new Set,l=s.points.map(m=>{if((!t(m)||typeof m.id!="number"||!Number.isFinite(m.id)||!r(m.position))&&n(),c.has(m.id)&&n(),c.add(m.id),m.normal!==void 0&&!r(m.normal)&&n(),m.faceVertices!==void 0&&(!Array.isArray(m.faceVertices)||m.faceVertices.length!==3||!m.faceVertices.every(r))&&n(),m.snapped!==void 0&&!["vertex","edge"].includes(m.snapped)&&n(),m.anchor!==void 0){let u=m.anchor;(!t(u)||typeof u.nodeId!="string"||!u.nodeId||!r(u.localPosition)||typeof u.geometrySignature!="string"||typeof u.poseSignature!="string")&&n(),u.localNormal!==void 0&&!r(u.localNormal)&&n(),u.localFaceVertices!==void 0&&(!Array.isArray(u.localFaceVertices)||u.localFaceVertices.length!==3||!u.localFaceVertices.every(r))&&n(),u.instanceId!==void 0&&(!Number.isInteger(u.instanceId)||u.instanceId<0)&&n()}let d=m.anchor;return{id:m.id,position:[...m.position],...m.normal?{normal:[...m.normal]}:{},...m.faceVertices?{faceVertices:m.faceVertices.map(u=>[...u])}:{},...m.snapped?{snapped:m.snapped}:{},...d?{anchor:{nodeId:d.nodeId,localPosition:[...d.localPosition],geometrySignature:d.geometrySignature,poseSignature:d.poseSignature,...d.localNormal?{localNormal:[...d.localNormal]}:{},...d.localFaceVertices?{localFaceVertices:d.localFaceVertices.map(u=>[...u])}:{},...d.instanceId!==void 0?{instanceId:d.instanceId}:{}}}:{}}}),f={id:s.id,name:s.name,modelId:s.modelId,tool:s.tool,points:l,createdAt:s.createdAt,...s.tilesetUrl!==void 0?{tilesetUrl:s.tilesetUrl}:{},...s.visible!==void 0?{visible:s.visible}:{},...s.approximate!==void 0?{approximate:s.approximate}:{}};return fn(f.tool,l)||n(),f});return{settings:o,items:a}}function $r(e){return JSON.stringify({version:1,...ae(e)},null,2)}function Fr(e,n,t="m"){let r=ae(e),o=new Map(n?.map(a=>[a.id,a])),i=a=>{let s=String(a??"");return/^[=+@-]/.test(s)&&(s=`'${s}`),`"${s.replace(/"/g,'""')}"`};return[["id","name","modelId","type","status","value","unit","createdAt"],...r.items.map(a=>{let s=o.get(a.id)??Ot(a,r.settings,t);return[a.id,a.name,a.modelId,a.tool,s.status,s.value,s.unit,a.createdAt]})].map(a=>a.map(i).join(",")).join(`\r
|
|
2
|
-
`)}function gn(e){if(!Array.isArray(e)||e.length>128)throw new Error("Invalid selections: expected up to 128 named selection sets.");let n=new Set;return e.map(t=>{if(!t||typeof t!="object"||typeof t.id!="string"||!t.id||n.has(t.id)||typeof t.name!="string"||!t.name.trim()||t.name.length>200||!Array.isArray(t.objectIds)||t.objectIds.length>1e5||t.objectIds.some(r=>typeof r!="string"||!r))throw new Error("Invalid selections: each set needs a unique id, a name, and model object ids.");return n.add(t.id),{id:t.id,name:t.name.trim(),objectIds:[...new Set(t.objectIds)]}})}import{CanvasTexture as pn,Color as bn,ImageLoader as At,NoColorSpace as xe,RepeatWrapping as Se,SRGBColorSpace as $e,Texture as Mt}from"three";var Y=new Map,Ue={color:"#93c5fd",intensity:.07},Hr=new bn(Ue.color).multiplyScalar(Ue.intensity),Kr=new bn(Ue.color),Yr=.28,te=new Map,De=new Map;function jt(e){return`${e.name}|${e.size}|${e.lastModified}`}function Xr(e){let n=jt(e),t=e.name.lastIndexOf("."),r=t>0?e.name.slice(0,t):e.name,o=t>0?e.name.slice(t):"",i=`materials/${e.name}`,a=2;for(;;){let s=De.get(i);if(s===void 0||s===n)return De.set(i,n),i;i=`materials/${r}-${a}${o}`,a+=1}}function we(e){return te.get(e)}function yn(e,n){let t=++e.loadGeneration;e.loaded=!1,e.failed=!1;let r=()=>{if(e.loadGeneration!==t)return;e.loaded=!0;let o=e.pending;e.pending=[];for(let i of o)i()};new At().load(n,o=>{e.loadGeneration===t&&(e.texture.image=o,e.texture.needsUpdate=!0,r())},void 0,()=>{e.loadGeneration===t&&(e.failed=!0,console.warn(`Failed to load texture: ${n}`),r())})}function hn(e,n){for(let t of[$e,xe]){let r=Y.get(ce(e,t));r&&yn(r,n)}}function Jr(e,n){let t=te.get(e);t&&t!==n&&t.startsWith("blob:")&&URL.revokeObjectURL(t),te.set(e,n),hn(e,n)}function Zr(e){let n=te.get(e);n&&(n.startsWith("blob:")&&URL.revokeObjectURL(n),te.delete(e),De.delete(e),hn(e,e))}function ce(e,n){return`${n}|${e}`}function Ct(e,n=xe,t){let r=ce(e,n),o=Y.get(r);if(o)return t&&!o.loaded&&o.pending.push(t),o.texture;let i=te.get(e)??e,a={texture:new Mt,refCount:0,loaded:!1,pending:t?[t]:[],loadGeneration:0};return a.texture.flipY=!1,a.texture.colorSpace=n,Y.set(r,a),yn(a,i),a.texture}function Qr(e,n=xe,t){let r=Ct(e,n,t);return Y.get(ce(e,n)).refCount+=1,r}function eo(e,n=xe){let t=Y.get(ce(e,n));t&&(t.refCount-=1,t.refCount<=0&&(t.loadGeneration+=1,t.pending=[],t.texture.dispose(),Y.delete(ce(e,n))))}function no(e,n,t,r,o,i=1,a=0){let s=e.offsetTextures??(e.offsetTextures={}),c=s[n],l=c;if(!l||l.sourcePath!==r||l.base!==t){c?.texture.dispose();let m=t.clone();m.wrapS=Se,m.wrapT=Se,m.center.set(.5,.5),m.needsUpdate=!0,l={texture:m,sourcePath:r,base:t},s[n]=l}let f=i>0?i:1;return l.texture.offset.set(o[0],o[1]),l.texture.repeat.set(1/f,1/f),l.texture.rotation=a,l.texture}function to(e,n){let t=e.offsetTextures,r=t?.[n];r&&(r.texture.dispose(),delete t[n])}function ro(e){let n=e.offsetTextures;if(n){for(let t of Object.values(n))t.texture.dispose();delete e.offsetTextures}}var _e=null;function oo(){if(_e)return _e;let e=256,n=document.createElement("canvas");n.width=e,n.height=e;let t=n.getContext("2d"),r=t.createRadialGradient(e*.35,e*.35,e*.02,e*.5,e*.5,e*.55);r.addColorStop(0,"#ffffff"),r.addColorStop(.4,"#b5b5b5"),r.addColorStop(1,"#3a3a3a"),t.fillStyle=r,t.fillRect(0,0,e,e);let o=new pn(n);return o.colorSpace=$e,_e=o,o}var ze=null;function io(){if(ze)return ze;let e=1024,n=8,t=e/n,r=["#ef4444","#f59e0b","#22c55e","#6366f1"],o=document.createElement("canvas");o.width=e,o.height=e;let i=o.getContext("2d");i.textAlign="center",i.textBaseline="middle";for(let s=0;s<n;s+=1)for(let c=0;c<n;c+=1){let l=c*t,f=s*t,m=(Math.floor(c/2)+Math.floor(s/2))%4;i.fillStyle=r[m],i.fillRect(l,f,t,t),i.strokeStyle="rgba(0, 0, 0, 0.28)",i.lineWidth=2;for(let y=1;y<4;y+=1){let w=y*t/4;i.beginPath(),i.moveTo(l+w,f),i.lineTo(l+w,f+t),i.moveTo(l,f+w),i.lineTo(l+t,f+w),i.stroke()}i.strokeStyle="#09090b",i.lineWidth=7,i.strokeRect(l,f,t,t);let d=l+t*.23,u=f+t*.72,g=l+t*.72,h=f+t*.23;i.lineCap="round",i.lineJoin="round",i.beginPath(),i.moveTo(d,u),i.lineTo(g,h),i.lineTo(g-t*.2,h),i.moveTo(g,h),i.lineTo(g,h+t*.2),i.stroke();let p=s*n+c+1;i.font=`700 ${Math.round(t*.2)}px ui-monospace, SFMono-Regular, Menlo, monospace`,i.fillStyle="#ffffff",i.strokeStyle="rgba(0, 0, 0, 0.85)",i.lineWidth=6;let b=String(p).padStart(2,"0");i.strokeText(b,l+t/2,f+t*.82),i.fillText(b,l+t/2,f+t*.82)}let a=new pn(o);return a.colorSpace=$e,a.wrapS=Se,a.wrapT=Se,a.flipY=!1,a.anisotropy=8,a.needsUpdate=!0,ze=a,a}function Sn(e){for(let n of Y.values())if(n.texture.source===e.source&&(!n.loaded||n.failed))return!0;return!1}var X=5*1024*1024,vt=["activeModelId","modelUrl","modelFormat","tilesetUrl","models","mergeModels","sceneConfig","isolation","multiSelectedKeys","activeAnnotation","annotationCategories","backgroundColor","shadows","cinematic","cameraControllerType","objectTransformSpace","arScaleMode","usdzUrl","measurements","measurementSettings","measurementUnit","measurementModelId"];function S(e,n){throw new Error(`Invalid viewer state at ${e}: ${n}`)}function T(e,n){(!e||typeof e!="object"||Array.isArray(e))&&S(n,"expected an object.")}function le(e,n){(!Array.isArray(e)||!e.every(t=>typeof t=="string"))&&S(n,"expected strings.")}function _(e,n,t){(!Array.isArray(e)||e.length!==n||!e.every(r=>typeof r=="number"&&Number.isFinite(r)))&&S(t,`expected ${n} finite numbers.`)}function It(e){let n=new Set,t=0;function r(o,i,a){if((++t>2e5||a>64)&&S(i,"configuration is too complex."),o===null||typeof o=="string"||typeof o=="boolean"||typeof o=="number"&&Number.isFinite(o))return o;(typeof o!="object"||!o)&&S(i,"expected JSON data (finite numbers, no functions)."),n.has(o)&&S(i,"cyclic data."),!Array.isArray(o)&&Object.getPrototypeOf(o)!==Object.prototype&&Object.getPrototypeOf(o)!==null&&S(i,"expected plain JSON data."),n.add(o);let s=Array.isArray(o)?[]:{};for(let[c,l]of Object.entries(o))["__proto__","constructor","prototype"].includes(c)&&S(`${i}.${c}`,"reserved property."),l!==void 0?s[c]=r(l,`${i}.${c}`,a+1):Array.isArray(o)&&S(i,"undefined array entry.");return n.delete(o),s}return r(e,"state",0)}function z(e,n,t,r,o=!1,i){let a=e[n];if(a==null||a==="")return;typeof a!="string"&&S(t,"expected a URL.");let s=o?we(a)??a:a;if(s.trim().startsWith("blob:")){if(o&&i){i.set(a,{source:s,path:t});return}S(t,o?"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(s!==a&&(a=s,e[n]=s),o&&/^data:image\//i.test(a))return;let c;try{c=new URL(a,r??"https://relative.invalid/")}catch{S(t,"invalid asset URL.")}["http:","https:"].includes(c.protocol)||S(t,"use an HTTP(S) asset URL."),r&&(e[n]=c.href)}function Tt(e,n){T(e,n),_(e.position,3,`${n}.position`),_(e.target,3,`${n}.target`),(typeof e.zoom!="number"||e.zoom<=0)&&S(n,"zoom must be positive."),e.fov!==null&&(typeof e.fov!="number"||e.fov<=0||e.fov>=180)&&S(n,"fov must be null or between 0 and 180.");for(let t of["azimuthAngle","polarAngle"])e[t]!==void 0&&typeof e[t]!="number"&&S(n,`${t} must be a number.`)}function On(e,n,t,r){T(e,n),(typeof e.id!="number"||typeof e.title!="string"||typeof e.description!="string")&&S(n,"expected an annotation id, title and description.");for(let o of["worldPosition","localPosition"])_(e[o],3,`${n}.${o}`);e.images!==void 0&&(Array.isArray(e.images)||S(n,"images must be an array."),e.images.forEach(o=>{T(o,n),z(o,"src",n,t,!0,r)})),e.links!==void 0&&(Array.isArray(e.links)||S(n,"links must be an array."),e.links.forEach(o=>{T(o,n),z(o,"href",n,t,!1,r)}))}function An(e,n){T(e,n),e.waypoints!==void 0&&(Array.isArray(e.waypoints)||S(n,"expected waypoints."),e.waypoints.forEach(t=>{T(t,n),_(t.position,3,n),_(t.target,3,n)}));for(let t of["enabled","loop","autoPlay"])e[t]!==void 0&&typeof e[t]!="boolean"&&S(n,`${t} must be boolean.`);e.duration!==void 0&&(typeof e.duration!="number"||e.duration<=0)&&S(n,"duration must be positive.")}function Fe(e,n,t){if(n!==null)if(Array.isArray(n))Array.isArray(e)||S(t,"expected an array."),n.length&&e.forEach(r=>Fe(r,n[0],t));else if(typeof n=="object"){T(e,t);for(let[r,o]of Object.entries(n))Fe(e[r],o,`${t}.${r}`)}else typeof e!=typeof n&&S(t,`expected ${typeof n}.`)}function xn(e,n,t,r){if(Fe(e,ne,n),e.measurements!==void 0&&(e.measurements=ae(e.measurements)),e.sequences!==void 0&&(e.sequences=nn(e.sequences)),e.selectionSets!==void 0&&(e.selectionSets=gn(e.selectionSets)),_(e.model.rotation,3,`${n}.model.rotation`),e.lighting.lights.forEach(o=>_(o.position,3,`${n}.lighting.lights`)),e.annotations.forEach(o=>On(o,`${n}.annotations`,t,r)),e.animations.autoplayClip!==null&&typeof e.animations.autoplayClip!="string"&&S(n,"invalid autoplay clip."),e.animations.clips.forEach(o=>{T(o,n),(typeof o.sourceName!="string"||typeof o.displayName!="string"||typeof o.hidden!="boolean"||typeof o.speed!="number"||!["repeat","once","ping-pong"].includes(o.loopMode))&&S(n,"invalid animation clip settings.")}),e.cinematic!==void 0&&An(e.cinematic,`${n}.cinematic`),e.styleRules!==void 0&&!Array.isArray(e.styleRules)&&S(n,"styleRules must be an array."),z(e.environment,"customEnvironmentUrl",`${n}.environment`,t,!1,r),z(e.background,"imageUrl",`${n}.background`,t,!0,r),e.model.activeVariants!==void 0&&le(e.model.activeVariants,n),e.section!==void 0)try{e.section=ie(e.section)}catch(o){S(`${n}.section`,o.message)}}function Mn(e,n,t,r){T(e,n);for(let[o,i]of Object.entries(e)){let a=`${n}.${o}`;T(i,a),(typeof i.id!="string"||typeof i.modelObjectId!="string")&&S(a,"expected binding id and modelObjectId.");for(let s of["label","group","type","status"])i[s]!==void 0&&typeof i[s]!="string"&&S(a,`${s} must be a string.`);i.tags!==void 0&&le(i.tags,a),i.metadata!==void 0&&T(i.metadata,`${a}.metadata`),i.metrics!==void 0&&(T(i.metrics,a),Object.values(i.metrics).some(s=>typeof s!="number")&&S(a,"metrics must be numbers.")),i.actions!==void 0&&(Array.isArray(i.actions)||S(a,"actions must be an array."),i.actions.forEach(s=>{T(s,a),(typeof s.id!="string"||typeof s.label!="string"||s.type!=="command"||s.effects!==void 0&&!Array.isArray(s.effects))&&S(a,"invalid action.")}));for(let s of["visible","removed","selectable","hoverable"])i[s]!==void 0&&typeof i[s]!="boolean"&&S(a,`${s} must be boolean.`);if(i.transform!==void 0){T(i.transform,a);for(let s of["position","rotation","scale","shear"])i.transform[s]!==void 0&&_(i.transform[s],3,`${a}.transform.${s}`);i.transform.pivot!==void 0&&(T(i.transform.pivot,a),_(i.transform.pivot.point,3,a),_(i.transform.pivot.offset,3,a))}if(i.style!==void 0&&(T(i.style,a),i.style.material!==void 0)){T(i.style.material,a);for(let[s,c]of Object.entries(i.style.material))c&&typeof c=="object"&&!Array.isArray(c)&&"path"in c&&z(c,"path",`${a}.style.material.${s}.path`,t,!0,r)}i.decals!==void 0&&(Array.isArray(i.decals)||S(a,"decals must be an array."),i.decals.forEach(s=>{T(s,a),(typeof s.id!="string"||typeof s.size!="number"||s.size<=0)&&S(a,"invalid decal."),_(s.position,3,a),_(s.normal,3,a),z(s,"image",a,t,!0,r)}))}}function wn(e,n,t,r){Array.isArray(e)||S(n,"expected merge sources."),e.forEach(o=>{T(o,n),(typeof o.url!="string"||!o.url||typeof o.namePrefix!="string")&&S(n,"expected source URL and prefix."),z(o,"url",n,t,!1,r)})}function kt(e,n,t){T(e,"configuration");let r=Object.fromEntries(vt.filter(o=>e[o]!==void 0).map(o=>[o,e[o]]));(typeof r.modelUrl!="string"||!r.modelUrl)&&S("configuration.modelUrl","expected the active model URL.");for(let o of["modelUrl","tilesetUrl","usdzUrl"])z(r,o,`configuration.${o}`,n,!1,t);if(r.sceneConfig!==void 0&&xn(r.sceneConfig,"configuration.sceneConfig",n,t),r.mergeModels!==void 0&&wn(r.mergeModels,"configuration.mergeModels",n,t),r.models!==void 0){(!Array.isArray(r.models)||r.models.length===0)&&S("configuration.models","expected model entries.");let o=new Set,i=new Set;r.models.forEach(a=>{T(a,"model"),(typeof a.url!="string"||!a.url)&&S("model.url","expected a URL."),z(a,"url","model.url",n,!1,t),a.id!==void 0&&(typeof a.id!="string"||!a.id.trim())&&S("model.id","expected a nonempty instance ID.");let s=Re({id:a.id,url:a.url});i.has(s)&&S("configuration.models","instance identities must be unique; assign IDs when reusing a URL."),i.add(s),a.transform!==void 0&&(a.transform=se(a.transform)),a.visible!==void 0&&typeof a.visible!="boolean"&&S("model.visible","expected boolean."),o.add(a.url),Mn(a.objectBindings,"model.objectBindings",n,t),a.sceneConfig!==void 0&&xn(a.sceneConfig,"model.sceneConfig",n,t),a.mergeModels!==void 0&&wn(a.mergeModels,"model.mergeModels",n,t)}),r.activeModelId!==void 0&&(typeof r.activeModelId!="string"||!i.has(r.activeModelId))&&S("configuration.activeModelId","active instance is not in models."),r.activeModelId!==void 0&&r.models.find(a=>Re(a)===r.activeModelId)?.url!==r.modelUrl&&S("configuration.modelUrl","source does not match the active instance."),o.has(r.modelUrl)||S("configuration.modelUrl","active model is not in models.")}if(r.multiSelectedKeys!==void 0&&le(r.multiSelectedKeys,"configuration.multiSelectedKeys"),r.annotationCategories!==void 0&&r.annotationCategories!==null&&le(r.annotationCategories,"configuration.annotationCategories"),r.activeAnnotation!==void 0&&r.activeAnnotation!==null&&On(r.activeAnnotation,"configuration.activeAnnotation",n,t),r.measurements!==void 0||r.measurementSettings!==void 0){let o=ae({items:r.measurements??[],settings:r.measurementSettings??{}});r.measurements!==void 0&&(r.measurements=o.items),r.measurementSettings!==void 0&&(r.measurementSettings=o.settings)}r.measurementModelId!==void 0&&typeof r.measurementModelId!="string"&&S("configuration.measurementModelId","expected a stable id."),r.measurementUnit!==void 0&&typeof r.measurementUnit!="string"&&S("configuration.measurementUnit","expected a unit label.");for(let o of["backgroundColor"])r[o]!==void 0&&typeof r[o]!="string"&&S(o,"expected a string.");r.shadows!==void 0&&typeof r.shadows!="boolean"&&S("shadows","expected boolean.");for(let[o,i]of Object.entries({modelFormat:["glb","gltf","obj","fbx","usdz","stl","ply"],cameraControllerType:["orbit","pointerLock"],objectTransformSpace:["world","local"],arScaleMode:["normalized","real-world"]}))r[o]!==void 0&&!i.includes(r[o])&&S(o,"unsupported value.");if(r.cinematic!==void 0&&An(r.cinematic,"cinematic"),r.isolation!==void 0&&r.isolation!==null){let{target:o,mode:i,ghostOpacity:a}=r.isolation;typeof o=="string"||Array.isArray(o)&&o.every(s=>typeof s=="string")||o&&typeof o=="object"&&["group","tag","type"].some(s=>typeof o[s]=="string")||S("configuration.isolation","invalid target."),i!==void 0&&!["ghost","hide"].includes(i)&&S("configuration.isolation","invalid mode."),a!==void 0&&(typeof a!="number"||a<0||a>1)&&S("configuration.isolation","opacity must be between 0 and 1.")}return r}function jn(e,n,t,r){if(!(!e||typeof e!="object"))for(let[o,i]of Object.entries(e))o!=="metadata"&&(typeof i=="string"&&["url","modelUrl","tilesetUrl","usdzUrl","path","image","src","href","imageUrl","customEnvironmentUrl"].includes(o)?z(e,o,`${n}.${o}`,t,["path","image","src","imageUrl"].includes(o),r):jn(i,`${n}.${o}`,t,r))}function Cn(e,n,t){typeof e=="string"&&(new TextEncoder().encode(e).length>X&&S("state","exceeds the 5 MiB limit."),e=JSON.parse(e));let r=It(e);T(r,"state"),new TextEncoder().encode(JSON.stringify(r)).length>X&&S("state","exceeds the 5 MiB limit."),r.version!==void 0&&r.version!==1&&S("version","unsupported version."),r.version===void 0&&(r.objectBindings!==void 0||r.configuration!==void 0)&&S("version","full configurations require version 1.");let o={};return r.version!==void 0&&(o.version=1),r.camera!==void 0&&(Tt(r.camera,"camera"),o.camera=r.camera),r.hidden!==void 0&&(le(r.hidden,"hidden"),o.hidden=r.hidden),r.selected!==void 0&&(r.selected!==null&&typeof r.selected!="string"&&S("selected","expected an object id or null."),o.selected=r.selected),r.objectBindings!==void 0&&(Mn(r.objectBindings,"objectBindings",n,t),o.objectBindings=r.objectBindings),r.configuration!==void 0&&(o.configuration=kt(r.configuration,n,t)),jn(o,"state",n,t),new TextEncoder().encode(JSON.stringify(o)).length>X&&S("state","exceeds the 5 MiB limit."),o}function po(e,n){return JSON.stringify(Oe(e,n))}function Oe(e,n){return Cn(e,n)}async function vn(e,n){let t=new Map,r=Cn(e,n,t),o=new Map,i=new Map;for(let[s,{source:c,path:l}]of t){let f=o.get(c);f||(f=(async()=>{let m;try{m=await fetch(c)}catch{S(l,"this temporary image is no longer available. Reload or reselect it before saving.")}m.ok||S(l,"could not read the temporary image. Reload or reselect it before saving.");let d=await m.blob();d.size>X*3/4&&S(l,"embedded image exceeds the 5 MiB configuration limit. Use a hosted image URL.");let u=new Uint8Array(await d.arrayBuffer()),g=d.type.split(";")[0].toLowerCase(),h=g.startsWith("image/")?g:Bt(u);h||S(l,"temporary asset is not a supported image. Use a hosted asset URL.");let p="";for(let b=0;b<u.length;b+=32768)p+=String.fromCharCode(...u.subarray(b,b+32768));return`data:${h};base64,${btoa(p)}`})(),o.set(c,f)),i.set(s,await f)}function a(s){if(!(!s||typeof s!="object"))for(let[c,l]of Object.entries(s))c!=="metadata"&&(["path","image","src","imageUrl"].includes(c)&&typeof l=="string"&&i.has(l)?s[c]=i.get(l):a(l))}return a(r),Oe(r,n)}function Bt(e){let n=(t,r)=>String.fromCharCode(...e.subarray(t,r));if(e[0]===137&&n(1,4)==="PNG")return"image/png";if(e[0]===255&&e[1]===216&&e[2]===255)return"image/jpeg";if(n(0,3)==="GIF")return"image/gif";if(n(0,4)==="RIFF"&&n(8,12)==="WEBP")return"image/webp";if(n(4,8)==="ftyp"&&["avif","avis"].includes(n(8,12)))return"image/avif";if(/<svg[\s>]/i.test(new TextDecoder().decode(e.subarray(0,1024))))return"image/svg+xml"}import{strFromU8 as Et,strToU8 as In,unzlibSync as Rt,zlibSync as Nt}from"fflate";var Ae="ri-ar",Me="ri-ar-id",Tn=4096,Pt=2200,Vt=In(JSON.stringify(ne)).byteLength;function kn(e){return e==="localhost"||e.endsWith(".localhost")||/^127\./.test(e)||e==="[::1]"||e==="0.0.0.0"}function Bn(e){if(typeof e=="string"&&/^https?:\/\//i.test(e)&&kn(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 n of Object.values(e))Bn(n)}function wo(e){return e&&typeof e=="object"?e:void 0}function Oo(e){let n=new URLSearchParams(new URL(e,"https://viewer.invalid/").hash.slice(1));return n.has(Ae)||n.has(Me)}function Lt(e,n){let t=new URL(e,n);if(!["https:","http:"].includes(t.protocol))throw new Error("AR handoff requires an HTTP(S) URL.");return t.toString()}function Ao(e,n="",t=2048){let r=new Set,o=i=>{if(typeof i=="string")return we(i)??i;if(i===null||typeof i!="object")return i;if(r.has(i))throw new Error("AR configuration cannot contain cycles.");r.add(i);let a=Array.isArray(i)?i.map(o):Object.fromEntries(Object.keys(i).sort().map(s=>[s,o(i[s])]));return r.delete(i),a};return JSON.stringify([n,t,o({...e,camera:void 0})])}function En(e,n){if(JSON.stringify(e)!==JSON.stringify(n))return e&&n&&typeof e=="object"&&typeof n=="object"&&!Array.isArray(e)&&!Array.isArray(n)?Object.fromEntries(Object.entries(e).map(([t,r])=>[t,En(r,n[t])]).filter(([,t])=>t!==void 0)):e}function Rn(e,n,t=0){if(t>64)throw new Error("AR configuration is too deeply nested.");if(e&&n&&typeof e=="object"&&typeof n=="object"&&!Array.isArray(e)&&!Array.isArray(n)){let r=e,o=n;return Object.fromEntries([...new Set([...Object.keys(o),...Object.keys(r)])].map(i=>[i,Object.prototype.hasOwnProperty.call(r,i)?Rn(r[i],o[i],t+1):o[i]]))}return e}function Nn(e,n){let t=structuredClone(e);if(t.configuration){t.configuration.sceneConfig&&(t.configuration.sceneConfig=n(t.configuration.sceneConfig));for(let r of t.configuration.models??[])r.sceneConfig&&(r.sceneConfig=n(r.sceneConfig))}return t}function de(e){e?.throwIfAborted()}async function Mo(e,n,t,r){de(r);let o=new URL(Lt(n));if(kn(o.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 i=await vn(e,o.toString());de(r),Bn(i);let a=new URLSearchParams(o.hash.slice(1));if(a.delete(Ae),a.delete(Me),a.delete("view"),a.delete("viewId"),a.delete("view-id"),t){let s=await t.save(i);if(de(r),typeof s!="string"||!s||s.length>512)throw new Error("AR storage returned an invalid configuration ID.");a.set(Me,s)}else{let s=Nt(In(JSON.stringify({ar:1,state:Nn(i,l=>En(l,ne)??{})})),{level:9});if(s.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 s)c+=String.fromCharCode(l);a.set(Ae,btoa(c).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""))}if(o.hash=a.toString(),o.toString().length>Pt)throw new Error("This configuration is too large for a reliable QR code. Use an AR storage adapter or download the USDZ.");return o.toString()}async function jo(e,n,t){let r=new URL(e),o=new URLSearchParams(r.hash.slice(1)),i=o.get(Me),a=o.get(Ae);if(i!==null&&a!==null)throw new Error("AR link contains conflicting configurations.");if(i===null&&a===null)return null;de(t);let s;if(i!==null){if(!n)throw new Error("This AR link requires the application's configuration storage adapter.");if(!i||i.length>512)throw new Error("Invalid AR configuration ID.");s=await n.load(i)}else{if(!a||a.length>Math.ceil(Tn*4/3)||!/^[\w-]+$/.test(a))throw new Error("Invalid or oversized AR link.");let l=atob(a.replace(/-/g,"+").replace(/_/g,"/")),f=Uint8Array.from(l,u=>u.charCodeAt(0)),m=Rt(f);if(m.byteLength>X)throw new Error("AR configuration exceeds the 5 MiB limit.");let d=JSON.parse(Et(m));if(d?.ar===1&&d.state){let u=d.state.configuration,g=(u?.sceneConfig?1:0)+(Array.isArray(u?.models)?u.models.filter(h=>h?.sceneConfig).length:0);if(m.byteLength+g*Vt>X)throw new Error("Expanded AR configuration exceeds the 5 MiB limit.");s=Nn(d.state,h=>Rn(h,ne))}else s=d}de(t);let c=Oe(s,r.toString());if(c.version!==1||!c.configuration)throw new Error("AR handoff requires a complete versioned viewer configuration.");return c}var Ge=new WeakMap;function vo(e,n){n?Ge.set(e,n):Ge.delete(e)}function Pn(e){e.traverse(n=>{let t=Ge.get(n);if(t)throw new Error(t)})}import{Box3 as zt,BufferAttribute as Vn,BufferGeometry as Ln,Color as Ut,DoubleSide as Dt,FrontSide as He,Group as _n,Matrix4 as $t,Mesh as Ft,Vector3 as je}from"three";import{PropertyBinding as qe}from"three";var We=Symbol("react-immersive.model-node-id");function _t(e,n){Object.defineProperty(e,We,{value:n,configurable:!0})}function ue(e){let n=new Map;e.traverse(c=>{if(!c.name)return;let l=n.get(c.name);l?l.push(c):n.set(c.name,[c])});let t=Object.create(null),r=new WeakMap,o=new Map,i=new Set(Array.from(n,([c,l])=>l.length===1?c:null).filter(c=>c!==null)),a=new Set,s=(c,l)=>{_t(c,l),t[l]=c,r.set(c,l),a.add(l)};for(let[c,l]of n)l.length===1&&s(l[0],c);for(let[c,l]of n){if(l.length<2)continue;let f=[];l.forEach((m,d)=>{let u=`${c} [${d+1}]`,g=u,h=2;for(;i.has(g)||a.has(g);)g=`${u}.${h++}`;s(m,g),f.push(g)}),o.set(c,f)}return{nodesById:t,idByNode:r,duplicateNames:o}}function me(e){return e[We]??e.name??null}function ko(e,n){let t=n.replace(/\.[^./\\]+$/,"");e.traverse(r=>{r.name&&(r.name=qe.sanitizeNodeName(`${t}_${r.name}`))})}function Bo(e,n){let t=n.replace(/\.[^./\\]+$/,""),r=e.clone();for(let o of r.tracks){let a=qe.parseTrackName(o.name).nodeName??"",s=qe.sanitizeNodeName(`${t}_${a}`);o.name=s+o.name.slice(a.length)}return r}function Eo(e,n){let t=null,r=[];return e.traverse(o=>{o[We]===n&&(t=o),o.name===n&&r.push(o)}),t??(r.length===1?r[0]:null)}function Gt(e,n={}){n.signal?.throwIfAborted();let t=new _n,r=new _n;t.add(r);let o=new Set,i=[],a=[],s=[],c=new Map,l=0,f=0,m=()=>{i.forEach(d=>d.dispose()),a.forEach(d=>d.dispose()),s.forEach(d=>d.dispose())};try{for(let{scene:p,objectBindings:b={},materialOverrides:y={}}of e){Pn(p),p.updateWorldMatrix(!0,!0);let w=new Map(Object.entries(b).map(([O,x])=>[x.modelObjectId??O,O]));p.traverse(O=>{let x=O;if(!x.isMesh||!x.geometry)return;for(let P=O;P;P=P.parent){let F=me(P)??P.name??P.uuid;if(!P.visible||b[w.get(F)??F]?.visible===!1||b[w.get(F)??F]?.removed)return}let A=me(x)??x.name??x.uuid,E=y[w.get(A)??A]??x.material;if(!E)throw new Error(`Material for ${A} is not ready. Wait for the model to finish loading.`);let R=Array.isArray(E)?E:[E],re=x.isInstancedMesh?x.count:1;if(x.userData.riDecal&&pe(x)&&x.parent){let P=Je(x.parent);P&&x.bindMatrixInverse.copy(P)}let k=pe(x)?Ze(x):x.geometry.clone();try{if(!pe(x)&&x.morphTargetInfluences?.some(U=>U!==0)){let U=k.getAttribute("position"),$=new je;for(let V=0;V<U.count;V++)x.getVertexPosition(V,$),U.setXYZ(V,$.x,$.y,$.z);k.morphAttributes={},k.computeVertexNormals()}if(!k.getAttribute("position"))throw new Error(`Mesh ${A} has no positions.`);let P=k.index?.count??k.getAttribute("position").count,F=Array.isArray(E)?k.groups:[{start:0,count:P,materialIndex:0}];if(!F.length)throw new Error(`Mesh ${A} has multiple materials without geometry groups.`);for(let U=0;U<re;U++){let $=x.matrixWorld.clone();if(x.isInstancedMesh){let V=new $t;x.getMatrixAt(U,V),$.multiply(V)}for(let V of F){let fe=R[V.materialIndex??0];if(!fe)throw new Error(`A material group on ${A} is missing its material.`);if(!fe.visible)continue;let G=fe;if(!G.isMeshStandardMaterial||G.wireframe||G.vertexColors)throw new Error(`AR snapshot cannot preserve ${fe.type}${G.wireframe?" wireframe":G.vertexColors?" vertex colors":""} on ${A}. Use a PBR material or provide arHandoff.createUSDZ.`);let Q=Math.max(V.start,k.drawRange.start),Ie=Math.min(P,V.start+V.count,k.drawRange.start+k.drawRange.count);if(Ie<=Q)continue;if(Q%3||(Ie-Q)%3)throw new Error(`Mesh ${A} has an incomplete triangle range.`);let B=new Ln;i.push(B);let D=Array.from({length:Ie-Q},(M,C)=>k.index?k.index.getX(Q+C):Q+C);if($.determinant()<0)for(let M=0;M<D.length;M+=3)[D[M+1],D[M+2]]=[D[M+2],D[M+1]];for(let[M,C]of Object.entries(k.attributes)){let j=new Float32Array(D.length*C.itemSize);for(let v=0;v<D.length;v++)for(let L=0;L<C.itemSize;L++)j[v*C.itemSize+L]=C.getComponent(D[v],L);B.setAttribute(M,new Vn(j,C.itemSize))}B.setIndex(D.map((M,C)=>C)),B.applyMatrix4($);let ge=B.getAttribute("position");for(let M=0;M<ge.count;M++)if(![ge.getX(M),ge.getY(M),ge.getZ(M)].every(Number.isFinite))throw new Error(`Mesh ${A} contains invalid coordinates.`);B.getAttribute("normal")||B.computeVertexNormals();let N=G.clone();a.push(N);let Ye=G.userData.reactImmersiveConfiguredEmissive;if(Ye?.isColor&&N.emissive.copy(Ye),N.side===Dt){let M=B.toNonIndexed();i.push(M);let C=M.getAttribute("position").count,j=new Ln;i.push(j);for(let[v,L]of Object.entries(M.attributes)){let Te=new Float32Array(C*L.itemSize*2);for(let q=0;q<C;q++)for(let ee=0;ee<L.itemSize;ee++){Te[q*L.itemSize+ee]=L.getComponent(q,ee);let Yn=Math.floor(q/3)*3+(2-q%3);Te[(C+q)*L.itemSize+ee]=L.getComponent(Yn,ee)*(v==="normal"?-1:1)}j.setAttribute(v,new Vn(Te,L.itemSize))}N.side=He,B.copy(j)}else if(N.side!==He){let M=B.getIndex();for(let j=0;j<M.count;j+=3){let v=M.getX(j+1);M.setX(j+1,M.getX(j+2)),M.setX(j+2,v)}let C=B.getAttribute("normal");for(let j=0;j<C.count;j++)C.setXYZ(j,-C.getX(j),-C.getY(j),-C.getZ(j));N.side=He}if(x.isInstancedMesh&&x.instanceColor){let M=new Ut;x.getColorAt(U,M),N.color.multiply(M)}for(let[M,C]of Object.entries(N)){if(!C?.isTexture)continue;let j=C;if(Sn(j)||!j.image||j.image.complete===!1)throw new Error(`Texture on ${A} is not ready. Wait for image loading or replace failed textures before preparing AR.`);let v=c.get(j);if(v||(v=j.clone(),c.set(j,v),s.push(v)),N[M]=v,!B.getAttribute(v.channel?`uv${v.channel}`:"uv"))throw new Error(`Texture on ${A} needs UV coordinates missing from this geometry.`)}if(x.userData.riDecal){B.computeBoundingBox();let M=Math.max(1e-6,B.boundingBox.getSize(new je).length()*1e-4),C=B.getAttribute("position"),j=B.getAttribute("normal");for(let v=0;v<C.count;v++)C.setXYZ(v,C.getX(v)+j.getX(v)*M,C.getY(v)+j.getY(v)*M,C.getZ(v)+j.getZ(v)*M)}let Xe=new Ft(B,N);Xe.name=`AR_${l++}`,r.add(Xe),f+=(B.index?.count??B.getAttribute("position").count)/3,(N.clearcoat||N.transmission||N.iridescence||N.anisotropy)&&o.add("Advanced PBR effects may look different in Quick Look.")}}}finally{k.dispose()}})}if(!l||!f)throw new Error("There is no visible model geometry to send to AR.");let d=new zt().setFromObject(r),u=d.getSize(new je),g=d.getCenter(new je),h=n.scaleMode==="real-world"?1:1/Math.max(u.x,u.y,u.z,1e-9);return r.position.set(-g.x*h,-d.min.y*h,-g.z*h),r.scale.setScalar(h),t.updateMatrixWorld(!0),o.add("USDZ is a static snapshot. Viewer lighting, background, post-processing, annotations and measurement overlays stay in the web viewer."),{root:t,meshCount:l,triangleCount:f,scale:h,warnings:[...o],textures:s,dispose:m}}catch(d){throw m(),d}}async function $o(e,n={}){let t=n.maxTextureSize??2048;if(!Number.isInteger(t)||t<256||t>4096)throw new Error("AR maxTextureSize must be an integer from 256 to 4096.");let r=Gt(e,n),o=[];try{let{USDZExporter:i}=await import("three/examples/jsm/exporters/USDZExporter.js");n.signal?.throwIfAborted();for(let s of r.textures){if(!s.isCompressedTexture)continue;let{decompress:c}=await import("three/examples/jsm/utils/WebGLTextureUtils.js"),l=c(s,t);o.push(l),r.root.traverse(f=>{let m=f.material;if(m)for(let d of Object.keys(m))m[d]===s&&(m[d]=l)})}let a=await new i().parseAsync(r.root,{onlyVisible:!0,quickLookCompatible:!0,maxTextureSize:t});return n.signal?.throwIfAborted(),{blob:new Blob([new Uint8Array(a)],{type:"model/vnd.usdz+zip"}),meshCount:r.meshCount,triangleCount:r.triangleCount,scale:r.scale,warnings:r.warnings}}catch(i){throw n.signal?.aborted?i:new Error(`Could not prepare the configured USDZ: ${i instanceof Error?i.message:"export failed"}. Textures must allow cross-origin canvas access.`)}finally{r.dispose(),o.forEach(i=>i.dispose())}}var Ce=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."}]),Go="__custom__";function qt(e){return Ce.find(n=>n.id===e)}var Un=Ce.filter(e=>e.handling==="viewer").map(e=>e.id),Wt=new Set(["","New Action",...Ce.map(e=>e.label)]);function qo(e){return Wt.has(e.trim())}function zn(e,n){let t=Array.from({length:n.length+1},(r,o)=>o);for(let r=1;r<=e.length;r+=1){let o=[r];for(let i=1;i<=n.length;i+=1){let a=t[i-1]+(e[r-1]===n[i-1]?0:1);o[i]=Math.min(o[i-1]+1,t[i]+1,a)}t=o}return t[n.length]}function Wo(e){if(qt(e))return null;let n=e.trim().toLowerCase();if(!n)return null;let t=n.replace(/[^a-z0-9]/g,""),r=null;for(let o of Ce){let i=Math.min(zn(n,o.id),zn(t,o.id.replace(/[^a-z0-9]/g,"")));(!r||i<r.distance)&&(r={id:o.id,distance:i})}return r&&r.distance<=2?r.id:null}function Dn(e,n){if(e[n])return n;let t=Object.entries(e).find(([,o])=>o.id===n)?.[0];return t||(Object.entries(e).find(([,o])=>o.modelObjectId===n)?.[0]??null)}function Ht(e){return typeof e=="object"&&!Array.isArray(e)}function Kt(e,n){return"group"in n?e.group===n.group:"tag"in n?e.tags?.includes(n.tag)??!1:(e.type??"other")===n.type}function J(e,n){if(Ht(n))return Object.entries(e).filter(([,o])=>Kt(o,n)).map(([o])=>o);let r=(typeof n=="string"?[n]:n).map(o=>Dn(e,o)).filter(o=>o!==null);return[...new Set(r)]}function Xo(e,n){return J(e,n).map(t=>e[t]).filter(t=>t!==void 0)}var Yt="#ff3b30",Xt=Object.freeze({}),$n=e=>e;function Jt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Zt(e,n){let t=e.metadata;for(let r of n.split(".")){if(!Jt(t))return;t=t[r]}return t}function Qt(e,n){if("metric"in n){let t=e.metrics?.[n.metric];return!(typeof t!="number"||!Number.isFinite(t)||n.above!==void 0&&!(t>n.above)||n.below!==void 0&&!(t<n.below))}if("status"in n){let t=e.status??"normal";return Array.isArray(n.status)?n.status.includes(t):n.status===t}return Zt(e,n.metadata)===n.equals}function er(e){let n=e.trim().replace(/^#/,""),t=n.length===3?n.split("").map(r=>r+r).join(""):n;return/^[0-9a-f]{6}$/i.test(t)?[0,2,4].map(r=>parseInt(t.slice(r,r+2),16)):null}var Ke=e=>`#${e.map(n=>Math.round(n).toString(16).padStart(2,"0")).join("")}`;function nr(e,n){let t=e.map(([c,l])=>({at:c,rgb:er(l)})).filter(c=>Number.isFinite(c.at)&&c.rgb!==null).sort((c,l)=>c.at-l.at);if(t.length===0||!Number.isFinite(n))return null;if(n<=t[0].at)return Ke(t[0].rgb);let r=t[t.length-1];if(n>=r.at)return Ke(r.rgb);let o=t.findIndex(c=>c.at>=n),i=t[o-1],a=t[o],s=a.at===i.at?1:(n-i.at)/(a.at-i.at);return Ke(i.rgb.map((c,l)=>c+(a.rgb[l]-c)*s))}function Qo(e,n){if(!n?.length)return{bindings:e,pulses:Xt,sourceOf:$n};let t=new Map,r={};for(let a of n){let s=a.target?J(e,a.target):Object.keys(e),c=a.when?Array.isArray(a.when)?a.when:[a.when]:[];for(let l of s){let f=e[l];if(!c.every(d=>Qt(f,d)))continue;let m={...a.material};if(a.colorScale){let d=f.metrics?.[a.colorScale.metric],u=typeof d=="number"?nr(a.colorScale.stops,d):null;u&&(m={...m,[a.colorScale.channel??"baseColor"]:u})}if(a.pulse){let d=a.pulse===!0?{}:a.pulse;r[l]={color:d.color??Yt,speed:d.speed!==void 0&&d.speed>0?d.speed:1};let u=m.emissiveIntensity??t.get(l)?.emissiveIntensity??f.style?.material?.emissiveIntensity;u!==void 0&&u>0||(m.emissiveIntensity=1)}Object.keys(m).length>0&&t.set(l,{...t.get(l),...m})}}if(t.size===0)return{bindings:e,pulses:r,sourceOf:$n};let o={...e},i=new WeakMap;for(let[a,s]of t){let c=e[a],l={...c,style:{...c.style,material:{...c.style?.material,...s}}};o[a]=l,i.set(l,c)}return{bindings:o,pulses:r,sourceOf:a=>i.get(a)??a}}var tr=.12,Fn=new Set;function rr(e,n){return n?new Set(J(e,n.target)):Fn}function ti(e,n){let t=rr(e.bindings,n);if(!n||t.size===0)return{...e,setAside:Fn};let r=Math.min(Math.max(n.ghostOpacity??tr,0),1),o={...e.bindings},i=new WeakMap,a=new Set;for(let[s,c]of Object.entries(e.bindings)){if(t.has(s))continue;a.add(s);let l=n.mode==="hide"?{...c,visible:!1}:{...c,style:{...c.style,material:{...c.style?.material,opacity:Math.min(c.style?.material?.opacity??1,r)}}};o[s]=l,i.set(l,e.sourceOf(c))}return{bindings:o,pulses:e.pulses,sourceOf:s=>i.get(s)??e.sourceOf(s),setAside:a}}function or(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 ir(e){return e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,n=>n.toUpperCase())}function sr(e){let n=e.toLowerCase();return n.includes("light")?"light":n.includes("wheel")||n.includes("rim")||n.includes("tire")?"wheel":n.includes("glass")||n.includes("window")||n.includes("windshield")||n.includes("sunroof")?"glass":n.includes("seat")||n.includes("dashboard")||n.includes("console")||n.includes("doorpanel")?"interior":n.includes("floor")?"floor":n.includes("wall")?"wall":n.includes("door")?"door":n.includes("chair")||n.includes("table")||n.includes("sofa")||n.includes("bed")?"furniture":"other"}function Gn(e,n=!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"},...n?[{id:"change-material",label:"Change Material",type:"command"}]:[],{id:"toggle-visibility",label:"Toggle Visibility",type:"command"}]}function qn(e,n=!0){let t=sr(e);return{id:or(e),modelObjectId:e,type:t,label:ir(e),status:"normal",selectable:!0,hoverable:!0,visible:!0,style:{},actions:Gn(t,n),metrics:{},metadata:{}}}function ai(e,n){return Object.fromEntries(e.map(t=>[t,qn(t,!n?.has(t))]))}function ci(e,n){let t=new Set,r={};for(let o of e){let i=qn(o,!n?.has(o)),a=i.id||"object",s=a;for(let l=2;t.has(s);l++)s=`${a}-${l}`;t.add(s),i.id=s;let c=(i.actions??[]).filter(l=>Un.includes(l.id));i.actions=c.length>0?c:Gn("other",!n?.has(o)),r[o]=i}return r}function li(e){let n=new Set;for(let[t,r]of Object.entries(ue(e).nodesById))Qe(r)||n.add(t);return n}function di(e){let{nodesById:n}=ue(e),t=[];for(let[r,o]of Object.entries(n)){let i=o;i.isMesh&&i.geometry&&o.name&&t.push(r)}return t.sort((r,o)=>r.localeCompare(o))}var Kn={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"},ar=Object.keys(Kn),cr=new Set(["__proto__","prototype","constructor"]);function Z(e,n=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"||n.has(e))throw new Error("Comparison values must be acyclic JSON data");n.add(e);let t=Array.isArray(e)?e.map(r=>Z(r,n)):Object.fromEntries(Object.entries(e).filter(([r,o])=>!cr.has(r)&&o!==void 0).map(([r,o])=>[r,Z(o,n)]));return n.delete(e),t}var Wn=e=>e&&typeof e=="object"&&!Array.isArray(e)&&!Object.keys(e).length;function Hn(e,n){let t=Z(e);t.visible=e.visible??!0,t.selectable=e.selectable??!0,t.hoverable=e.hoverable??!0,t.status=e.status??"normal",t.type=e.type??"other",t.tags=[...new Set(e.tags??[])].sort(),Wn(t.transform)&&delete t.transform,t.metadata=Object.fromEntries(Object.entries(e.metadata??{}).filter(([r])=>!n.includes(r)));for(let r of["metrics","style","metadata"])Wn(t[r])&&delete t[r];for(let r of["actions","decals"])Array.isArray(t[r])&&!t[r].length&&delete t[r];return t}function ve(e,n,t,r,o,i){if(Object.is(e,n)||typeof e=="number"&&typeof n=="number"&&Math.abs(e-n)<=o)return;let a=s=>!!s&&typeof s=="object"&&!Array.isArray(s);if(a(e)&&a(n)){for(let s of[...new Set([...Object.keys(e),...Object.keys(n)])].sort())ve(e[s],n[s],`${t}.${s}`,r,o,i);return}if(Array.isArray(e)&&Array.isArray(n)&&e.length===n.length){for(let s=0;s<e.length;s++)ve(e[s],n[s],`${t}[${s}]`,r,o,i);return}i.push({path:t,category:r,...e!==void 0?{before:Z(e)}:{},...n!==void 0?{after:Z(n)}:{}})}function mi(e,n,t={}){let r=t.tolerance??1e-6;if(!Number.isFinite(r)||r<0)throw new Error("Comparison tolerance must be finite and nonnegative");let o=Object.entries(e.objectBindings).filter(([,b])=>!b.removed),i=Object.entries(n.objectBindings).filter(([,b])=>!b.removed),a=new Map(o),s=new Map(i),c=new Set,l=new Set,f=[],m=b=>{let y=t.matchBy??"modelObjectId",w=typeof y=="object"?b.metadata?.[y.metadataKey]:b[y];return typeof w=="string"&&w.length>0||typeof w=="number"?`${typeof w}:${w}`:null};function d(b,y,w){let O=b===void 0?void 0:a.get(b),x=y===void 0?void 0:s.get(y),A=[];if(O||x){let R=O?Hn(O,t.ignoreMetadataKeys??[]):{},re=x?Hn(x,t.ignoreMetadataKeys??[]):{};for(let k of ar)ve(R[k],re[k],k,Kn[k],r,A)}let E=O?x?A.length?"modified":"unchanged":"removed":"added";f.push({id:JSON.stringify([b??null,y??null]),identity:w,label:x?.label??O?.label??x?.modelObjectId??O?.modelObjectId??w,status:E,beforeKey:b,afterKey:y,beforeObjectId:O?.modelObjectId,afterObjectId:x?.modelObjectId,changes:A}),b!==void 0&&c.add(b),y!==void 0&&l.add(y)}let u=new Set;for(let[b,y]of Object.entries(t.mapping??{})){if(!a.has(b)||!s.has(y)||u.has(y))throw new Error("Comparison mapping must reference existing, unique binding keys");u.add(y),d(b,y,`mapped:${b}`)}let g=new Map;for(let[b,y,w]of[[o,c,"a"],[i,l,"b"]])for(let[O,x]of b){if(y.has(O))continue;let A=m(x);if(A===null){f.push({id:JSON.stringify([w,O]),identity:"",label:x.label??x.modelObjectId,status:"ambiguous",...w==="a"?{beforeKey:O,beforeObjectId:x.modelObjectId}:{afterKey:O,afterObjectId:x.modelObjectId},changes:[],message:"Missing match identity. Supply an explicit mapping or another match field."});continue}let E=g.get(A)??{a:[],b:[]};E[w].push(O),g.set(A,E)}for(let[b,y]of g){if(y.a.length<=1&&y.b.length<=1){d(y.a[0],y.b[0],b);continue}for(let w of["a","b"])for(let O of y[w]){let x=(w==="a"?a:s).get(O);f.push({id:JSON.stringify([w,O]),identity:b,label:x.label??x.modelObjectId,status:"ambiguous",...w==="a"?{beforeKey:O,beforeObjectId:x.modelObjectId}:{afterKey:O,afterObjectId:x.modelObjectId},changes:[],message:"Duplicate match identity. Supply an explicit one-to-one mapping."})}}f.sort((b,y)=>b.label.localeCompare(y.label)||b.id.localeCompare(y.id));let h=[];ve(Z(e.sceneConfig??{}),Z(n.sceneConfig??{}),"sceneConfig","scene",r,h);let p={added:0,removed:0,modified:0,unchanged:0,ambiguous:0};for(let b of f)p[b.status]++;return{version:1,objects:f,counts:p,sceneChanges:h}}function fi(e,n,t){let r={added:"#22c55e",removed:"#f87171",modified:"#fbbf24",unchanged:"#94a3b8",ambiguous:"#c084fc"};return e.objects.flatMap(o=>{let i=n==="before"?o.beforeObjectId:o.afterObjectId;return i&&(o.status!=="unchanged"||o.id===t)?[{objectId:i,color:o.id===t?"#22d3ee":r[o.status]}]:[]})}var pi=["front","back","double"],bi=["normal","additive"];function Si(e){ue(e);let n=[],t=[{node:e,path:"0",parentId:null}];for(;t.length;){let{node:o,path:i,parentId:a}=t.pop(),s=`node:${i}`,c=o.isMesh&&o.name?me(o):null;n.push({id:s,parentId:a,name:o.name||o.type||"Group",...c?{objectId:c}:{}});for(let l=o.children.length-1;l>=0;l--)t.push({node:o.children[l],path:`${i}/${l}`,parentId:s})}let r=new Set;for(let o=n.length-1;o>=0;o--){let i=n[o];(i.objectId||r.has(i.id))&&(r.add(i.id),i.parentId&&r.add(i.parentId))}return n.filter(o=>r.has(o.id))}function Oi(e){return structuredClone(e.style??{})}function Ai(e,n,t){let r=J(e,n).filter(i=>!e[i].removed);if(!r.length)return e;let o={...e};for(let i of r)o[i]={...e[i],style:structuredClone(t)};return o}export{ue as a,me as b,ko as c,Bo as d,Eo as e,Xn as f,Jn as g,et as h,nt as i,nn as j,dr as k,ur as l,Dn as m,Ue as n,Hr as o,Kr as p,Yr as q,Xr as r,we as s,Jr as t,Zr as u,Ct as v,Qr as w,eo as x,no as y,to as z,ro as A,oo as B,io as C,fr as D,gr as E,pr as F,br as G,yr as H,hr as I,Sr as J,Ee as K,ne as L,ie as M,Or as N,Ar as O,Mr as P,vr as Q,Re as R,se as S,Ir as T,Tr as U,kr as V,Br as W,an as X,cn as Y,ln as Z,Pe as _,Nr as $,Pr as aa,Vr as ba,Lr as ca,St as da,Le as ea,wt as fa,Ur as ga,Dr as ha,fn as ia,Ot as ja,ae as ka,$r as la,Fr as ma,gn as na,X as oa,po as pa,Oe as qa,vn as ra,wo as sa,Oo as ta,Lt as ua,Ao as va,Mo as wa,jo as xa,vo as ya,Pn as za,$o as Aa,Ce as Ba,Go as Ca,qt as Da,Un as Ea,qo as Fa,Wo as Ga,J as Ha,Xo as Ia,Qt as Ja,nr as Ka,Qo as La,rr as Ma,ti as Na,sr as Oa,qn as Pa,ai as Qa,ci as Ra,li as Sa,di as Ta,mi as Ua,fi as Va,pi as Wa,bi as Xa,Si as Ya,Oi as Za,Ai as _a};
|