three-live 0.0.1-alpha.0 → 1.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/LICENSE +202 -0
- package/README.md +58 -0
- package/dist/index.d.ts +224 -0
- package/dist/three-author-engine.js +292 -0
- package/dist/three-author.cjs +292 -0
- package/dist/three-author.d.ts +224 -0
- package/dist/three-author.js +292 -0
- package/dist/three-convert.cjs +286 -0
- package/dist/three-convert.d.ts +224 -0
- package/dist/three-convert.js +286 -0
- package/dist/three-live-animation.cjs +36 -0
- package/dist/three-live-animation.d.ts +224 -0
- package/dist/three-live-animation.js +36 -0
- package/dist/three-live-animation.min.js +36 -0
- package/dist/three-live-element.cjs +217 -0
- package/dist/three-live-element.d.ts +224 -0
- package/dist/three-live-element.js +217 -0
- package/dist/three-live-extras.cjs +42 -0
- package/dist/three-live-extras.d.ts +224 -0
- package/dist/three-live-extras.js +42 -0
- package/dist/three-live-extras.min.js +42 -0
- package/dist/three-live-full.cjs +336 -0
- package/dist/three-live-full.js +336 -0
- package/dist/three-live-full.min.js +336 -0
- package/dist/three-live-sandbox.html +157 -0
- package/dist/three-live-viewer.cjs +217 -0
- package/dist/three-live-viewer.d.ts +224 -0
- package/dist/three-live-viewer.js +217 -0
- package/dist/three-live-viewer.min.js +217 -0
- package/dist/three-live.cjs +294 -0
- package/dist/three-live.js +294 -0
- package/dist/three-live.min.js +294 -0
- package/dist/three-view.cjs +217 -0
- package/dist/three-view.d.ts +224 -0
- package/dist/three-view.js +217 -0
- package/dist/three-xr.cjs +286 -0
- package/dist/three-xr.d.ts +224 -0
- package/dist/three-xr.js +286 -0
- package/package.json +78 -6
- package/index.js +0 -1
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// Copyright 2026 Google LLC
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @fileoverview Ambient and module declarations for three-live and xr-live.
|
|
17
|
+
* Enables zero-config, type-safe usage of <three-live> and <xr-live> in React 19,
|
|
18
|
+
* Next.js, Vue, Svelte, and modern TSX/JSX environments.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import type {
|
|
22
|
+
CameraState,
|
|
23
|
+
ThreeLiveElement,
|
|
24
|
+
} from './three-live/src/three-live-element';
|
|
25
|
+
import type {
|
|
26
|
+
CameraDetail,
|
|
27
|
+
GLBData,
|
|
28
|
+
HitDetail,
|
|
29
|
+
ThreeView,
|
|
30
|
+
} from './three-live/src/three-view';
|
|
31
|
+
import type {ARLaunchResult, ARMode} from './three-live/src/three-xr';
|
|
32
|
+
import type {TranscriptEvent} from './xr-live/src/plugins/gemini-live';
|
|
33
|
+
import type {Detection3D} from './xr-live/src/plugins/world-understanding';
|
|
34
|
+
import type {
|
|
35
|
+
XRAnchorElement,
|
|
36
|
+
XRDepthMode,
|
|
37
|
+
XRHandsMode,
|
|
38
|
+
XRLiveElement,
|
|
39
|
+
XRMode,
|
|
40
|
+
XRProfile,
|
|
41
|
+
XRSimulatorRoom,
|
|
42
|
+
} from './xr-live/src/xr-live-element';
|
|
43
|
+
|
|
44
|
+
export * from './three-live/src/core';
|
|
45
|
+
export {
|
|
46
|
+
getInteractivityVM,
|
|
47
|
+
interactivityPlugin,
|
|
48
|
+
InteractivityVM,
|
|
49
|
+
parseSafeGltfPointer,
|
|
50
|
+
sendInteractivityEvent,
|
|
51
|
+
type InteractivityDeclaration,
|
|
52
|
+
type InteractivityEventDef,
|
|
53
|
+
type InteractivityFlowTarget,
|
|
54
|
+
type InteractivityGraph,
|
|
55
|
+
type InteractivityNode,
|
|
56
|
+
type InteractivityValue,
|
|
57
|
+
type InteractivityValueSocket,
|
|
58
|
+
type InteractivityVariableDef,
|
|
59
|
+
} from './three-live/src/plugins/interactivity';
|
|
60
|
+
export {
|
|
61
|
+
ThreeLiveElement,
|
|
62
|
+
type ARLaunchOptions,
|
|
63
|
+
type ARLaunchResult,
|
|
64
|
+
type ARMode,
|
|
65
|
+
type ARProvider,
|
|
66
|
+
type CameraState,
|
|
67
|
+
} from './three-live/src/three-live-element';
|
|
68
|
+
export {
|
|
69
|
+
XRAnchorElement,
|
|
70
|
+
XRLiveElement,
|
|
71
|
+
type XRDepthMode,
|
|
72
|
+
type XRHandsMode,
|
|
73
|
+
type XRMode,
|
|
74
|
+
type XRProfile,
|
|
75
|
+
type XRSimulatorRoom,
|
|
76
|
+
} from './xr-live/src/xr-live-element';
|
|
77
|
+
/** Optional XR Blocks plugins (`xr-live/blocks`, `xr-live-blocks.min.js`). */
|
|
78
|
+
export * from './xr-live/src/plugins/index';
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Declarative JSX / HTML attributes supported by the <three-live> custom element.
|
|
82
|
+
*/
|
|
83
|
+
export interface ThreeLiveAttributes {
|
|
84
|
+
/** URL to glTF 2.0 binary (.glb) model. */
|
|
85
|
+
'src'?: string;
|
|
86
|
+
/** URL to Apple Universal Scene Description (.usdz) model for iOS Quick Look. */
|
|
87
|
+
'ios-src'?: string;
|
|
88
|
+
/** URL or inline script for procedural Three.js scene generation. */
|
|
89
|
+
'script-src'?: string;
|
|
90
|
+
/** Responsive image preview shown before 3D model finishes hydration. */
|
|
91
|
+
'poster'?: string;
|
|
92
|
+
/** Uniform or per-axis scale multiplier ("x y z"). */
|
|
93
|
+
'scale'?: string;
|
|
94
|
+
/** Initial camera orbit angles and distance: "theta phi [radius]" (e.g. "0deg 75deg 3m") or JSON string. */
|
|
95
|
+
'camera-orbit'?: string | CameraState;
|
|
96
|
+
/** Orbit center coordinate "x y z". */
|
|
97
|
+
'camera-target'?: string;
|
|
98
|
+
/** Lower bounds for camera orbit ("theta phi radius"). */
|
|
99
|
+
'min-camera-orbit'?: string;
|
|
100
|
+
/** Upper bounds for camera orbit ("theta phi radius"). */
|
|
101
|
+
'max-camera-orbit'?: string;
|
|
102
|
+
/** Vertical field of view angle (e.g. "45deg"). */
|
|
103
|
+
'field-of-view'?: string;
|
|
104
|
+
/** Sub-mesh name to highlight with interactive selection color. */
|
|
105
|
+
'selected-mesh'?: string;
|
|
106
|
+
/** Exposure / lighting multiplier for studio IBL lighting (default: 1.0). */
|
|
107
|
+
'exposure'?: number | string;
|
|
108
|
+
/** Equirectangular HDR/LDR environment map URL. */
|
|
109
|
+
'environment-image'?: string;
|
|
110
|
+
/** Visible background equirectangular skybox image URL. */
|
|
111
|
+
'skybox-image'?: string;
|
|
112
|
+
/** Ground contact shadow opacity (0.0 to 1.0). */
|
|
113
|
+
'shadow-intensity'?: number | string;
|
|
114
|
+
/** Radial Gaussian blur falloff of contact shadow (0.0 to 1.0). */
|
|
115
|
+
'shadow-softness'?: number | string;
|
|
116
|
+
/** Tone mapping mode ("neutral", "reinhard", "none"). */
|
|
117
|
+
'tone-mapping'?: string;
|
|
118
|
+
/** Enable or disable interactive camera orbit/pan/zoom controls (default: true). */
|
|
119
|
+
'camera-controls'?: boolean | string;
|
|
120
|
+
/** Automatically start keyframe animation playback. */
|
|
121
|
+
'autoplay'?: boolean | string;
|
|
122
|
+
/** Name of specific glTF animation clip to play. */
|
|
123
|
+
'animation-name'?: string;
|
|
124
|
+
/** Automatically rotate scene around the Y-axis when user is idle. */
|
|
125
|
+
'auto-rotate'?: boolean | string;
|
|
126
|
+
/** Delay in milliseconds before auto-rotation resumes after user interaction (default: 3000). */
|
|
127
|
+
'auto-rotate-delay'?: number | string;
|
|
128
|
+
/** Rate of turntable auto-rotation (e.g. "30deg", "0.5rad", "100%", default: "30deg"). */
|
|
129
|
+
'rotation-per-second'?: string;
|
|
130
|
+
/** Enable one-tap Augmented Reality button overlay. */
|
|
131
|
+
'ar'?: boolean | string;
|
|
132
|
+
/** Ordered list of AR launch targets ('webxr', 'quick-look', 'scene-viewer'). */
|
|
133
|
+
'ar-modes'?: string;
|
|
134
|
+
/** Controls whether the model can be scaled in AR ("auto" or "fixed"). */
|
|
135
|
+
'ar-scale'?: 'auto' | 'fixed';
|
|
136
|
+
/** Controls whether the model is placed on horizontal surfaces ("floor") or vertical surfaces ("wall"). */
|
|
137
|
+
'ar-placement'?: 'floor' | 'wall';
|
|
138
|
+
/**
|
|
139
|
+
* Mandatory isolation level for procedural scripts. Defaults to `'worker'`,
|
|
140
|
+
* which runs the script in a dedicated Web Worker with network, storage and
|
|
141
|
+
* thread-spawning capabilities revoked across the prototype chain. `'iframe'`
|
|
142
|
+
* runs the Worker inside an opaque-origin `<iframe sandbox="allow-scripts">`
|
|
143
|
+
* (`three-live-sandbox.html`) with a strict `connect-src 'none'` Content
|
|
144
|
+
* Security Policy.
|
|
145
|
+
*/
|
|
146
|
+
sandbox?: 'worker' | 'iframe';
|
|
147
|
+
/**
|
|
148
|
+
* Opt-in attribute allowing client-modified Three.js script strings
|
|
149
|
+
* (`executeScript(code)` and inline `<script type="text/three-live">`).
|
|
150
|
+
* Server-generated scripts (`script-src`) are enabled by default.
|
|
151
|
+
*/
|
|
152
|
+
'allow-client-scripts'?: boolean | string;
|
|
153
|
+
|
|
154
|
+
// React 19 / JSX Event Listeners
|
|
155
|
+
onload?: (e: CustomEvent<{model: GLBData}>) => void;
|
|
156
|
+
onerror?: (e: CustomEvent<{error: any}>) => void;
|
|
157
|
+
onmeshclick?: (e: CustomEvent<HitDetail>) => void;
|
|
158
|
+
'oncamera-change'?: (e: CustomEvent<CameraDetail>) => void;
|
|
159
|
+
'onar-status'?: (
|
|
160
|
+
e: CustomEvent<{
|
|
161
|
+
status: 'session-started' | 'not-presenting' | 'failed';
|
|
162
|
+
error?: any;
|
|
163
|
+
}>,
|
|
164
|
+
) => void;
|
|
165
|
+
|
|
166
|
+
// Standard HTML / JSX attributes
|
|
167
|
+
id?: string;
|
|
168
|
+
className?: string;
|
|
169
|
+
class?: string;
|
|
170
|
+
style?: any;
|
|
171
|
+
ref?: any;
|
|
172
|
+
key?: any;
|
|
173
|
+
slot?: string;
|
|
174
|
+
tabIndex?: number;
|
|
175
|
+
role?: string;
|
|
176
|
+
'aria-label'?: string;
|
|
177
|
+
children?: any;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Declarative JSX / HTML attributes supported by the <xr-live> spatial computing element.
|
|
182
|
+
*/
|
|
183
|
+
export interface XRLiveAttributes extends ThreeLiveAttributes {
|
|
184
|
+
/** WebXR session target mode ("ar", "vr", "inline", or "auto"). */
|
|
185
|
+
'xr-mode'?: XRMode;
|
|
186
|
+
/** Real-world hardware depth occlusion or physics mode ("occlusion", "occlusion-physics", "mesh", "none"). */
|
|
187
|
+
'xr-depth'?: XRDepthMode;
|
|
188
|
+
/** 25-joint hand tracking and gesture recognition mode ("gestures", "joints", "pinch", "none"). */
|
|
189
|
+
'xr-hands'?: XRHandsMode;
|
|
190
|
+
/** Desktop room simulator environment ("living-room", "office", "tabletop", "none"). */
|
|
191
|
+
'xr-simulator'?: XRSimulatorRoom;
|
|
192
|
+
/** Spatial UI profile ("quest3", "android-xr", "visionos", "auto"). */
|
|
193
|
+
'xr-profile'?: XRProfile;
|
|
194
|
+
/** XR Blocks: enables plane/mesh detection; include "reticle" for a gaze reticle. */
|
|
195
|
+
'world-understanding'?: boolean | string;
|
|
196
|
+
/** XR Blocks: pinch in empty space to paint 3D tubes (optional `#rrggbb` color). */
|
|
197
|
+
'spatial-paint'?: boolean | string;
|
|
198
|
+
'onxr-object-detected'?: (e: CustomEvent<Detection3D>) => void;
|
|
199
|
+
'onxr-transcription'?: (e: CustomEvent<TranscriptEvent>) => void;
|
|
200
|
+
'onxr-hold-to-ask'?: (
|
|
201
|
+
e: CustomEvent<{mesh: string; transcript: string; prompt: string}>,
|
|
202
|
+
) => void;
|
|
203
|
+
'onxr-handles-change'?: (
|
|
204
|
+
e: CustomEvent<{mesh: string; scale: number; yawDeg: number}>,
|
|
205
|
+
) => void;
|
|
206
|
+
'onxr-paint-stroke'?: (
|
|
207
|
+
e: CustomEvent<{index: number; points: number; lengthMeters: number}>,
|
|
208
|
+
) => void;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
declare global {
|
|
212
|
+
namespace JSX {
|
|
213
|
+
interface IntrinsicElements {
|
|
214
|
+
'three-live': ThreeLiveAttributes;
|
|
215
|
+
'xr-live': XRLiveAttributes;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
interface HTMLElementTagNameMap {
|
|
220
|
+
'three-live': ThreeLiveElement;
|
|
221
|
+
'xr-live': XRLiveElement;
|
|
222
|
+
'xr-anchor': XRAnchorElement;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
var ce="__THREE_LIVE_REGISTRY__";function ve(){let e=typeof globalThis<"u"?globalThis:{};if(!e[ce]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,ce,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[ce]=t}}return e[ce]}var St=ve().plugins;function Q(e){let t=ve().plugins;t.some(n=>n.name===e.name)||t.push(e)}function Ce(){return ve().plugins}function ne(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function it(e,t,n){let a=t[0],r=t[1],s=t[2],y=t[3],l=t[4],u=t[5],m=t[6],o=t[7],b=t[8],S=t[9],w=t[10],g=t[11],x=t[12],R=t[13],I=t[14],C=t[15],E=n[0],F=n[1],L=n[2],N=n[3];return e[0]=E*a+F*l+L*b+N*x,e[1]=E*r+F*u+L*S+N*R,e[2]=E*s+F*m+L*w+N*I,e[3]=E*y+F*o+L*g+N*C,E=n[4],F=n[5],L=n[6],N=n[7],e[4]=E*a+F*l+L*b+N*x,e[5]=E*r+F*u+L*S+N*R,e[6]=E*s+F*m+L*w+N*I,e[7]=E*y+F*o+L*g+N*C,E=n[8],F=n[9],L=n[10],N=n[11],e[8]=E*a+F*l+L*b+N*x,e[9]=E*r+F*u+L*S+N*R,e[10]=E*s+F*m+L*w+N*I,e[11]=E*y+F*o+L*g+N*C,E=n[12],F=n[13],L=n[14],N=n[15],e[12]=E*a+F*l+L*b+N*x,e[13]=E*r+F*u+L*S+N*R,e[14]=E*s+F*m+L*w+N*I,e[15]=E*y+F*o+L*g+N*C,e}function st(e,t,n,a){let r=t[0],s=t[1],y=t[2],l=t[3],u=r+r,m=s+s,o=y+y,b=r*u,S=r*m,w=r*o,g=s*m,x=s*o,R=y*o,I=l*u,C=l*m,E=l*o,F=a[0],L=a[1],N=a[2];return e[0]=(1-(g+R))*F,e[1]=(S+E)*F,e[2]=(w-C)*F,e[3]=0,e[4]=(S-E)*L,e[5]=(1-(b+R))*L,e[6]=(x+I)*L,e[7]=0,e[8]=(w+C)*N,e[9]=(x-I)*N,e[10]=(1-(b+g))*N,e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function re(e,t){let n=t[0],a=t[1],r=t[2],s=t[4],y=t[5],l=t[6],u=t[8],m=t[9],o=t[10],b=o*y-l*m,S=-o*s+l*u,w=m*s-y*u,g=n*b+a*S+r*w;return g&&(g=1/g,e[0]=b*g,e[1]=(-o*a+r*m)*g,e[2]=(l*a-r*y)*g,e[3]=S*g,e[4]=(o*n-r*u)*g,e[5]=(-l*n+r*s)*g,e[6]=w*g,e[7]=(-m*n+a*u)*g,e[8]=(y*n-a*s)*g),e}function Ve(e,t){let n=t[0],a=t[1],r=t[2],s=t[3],y=t[4],l=t[5],u=t[6],m=t[7],o=t[8],b=t[9],S=t[10],w=t[11],g=t[12],x=t[13],R=t[14],I=t[15],C=n*l-a*y,E=n*u-r*y,F=n*m-s*y,L=a*u-r*l,N=a*m-s*l,G=r*m-s*u,H=o*x-b*g,O=o*R-S*g,U=o*I-w*g,K=b*R-S*x,q=b*I-w*x,Z=S*I-w*R,z=C*Z-E*q+F*K+L*U-N*O+G*H;return z?(z=1/z,e[0]=(l*Z-u*q+m*K)*z,e[1]=(r*q-a*Z-s*K)*z,e[2]=(x*G-R*N+I*L)*z,e[3]=(S*N-b*G-w*L)*z,e[4]=(u*U-y*Z-m*O)*z,e[5]=(n*Z-r*U+s*O)*z,e[6]=(R*F-g*G-I*E)*z,e[7]=(o*G-S*F+w*E)*z,e[8]=(y*q-l*U+m*H)*z,e[9]=(a*U-n*q-s*H)*z,e[10]=(g*N-x*F+I*C)*z,e[11]=(b*F-o*N-w*C)*z,e[12]=(l*O-y*K-u*H)*z,e[13]=(n*K-a*O+r*H)*z,e[14]=(x*E-g*L-R*C)*z,e[15]=(o*L-b*E+S*C)*z,e):null}function Ae(e,t){let n=Array.isArray(e?.nodes)?e.nodes.length:0,a=[];for(let o=0;o<n;o++)a.push(ne());if(n===0)return a;let r=new Set;for(let o of e.nodes)if(Array.isArray(o.children))for(let b of o.children)r.add(b);let s=new Set,y=128,l=(o,b,S=0)=>{if(S>y||o<0||o>=n||s.has(o))return;s.add(o);let w=e.nodes[o];if(!w)return;let g=ne();if(t&&t[o])g.set(t[o]);else if(w.matrix&&w.matrix.length===16)g.set(w.matrix);else{let R=w.translation||[0,0,0],I=w.rotation||[0,0,0,1],C=w.scale||[1,1,1];st(g,I,R,C)}let x=a[o];if(b?it(x,b,g):x.set(g),Array.isArray(w.children))for(let R of w.children)typeof R=="number"&&l(R,x,S+1)},u=[],m=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(m&&Array.isArray(m.nodes))u.push(...m.nodes);else for(let o=0;o<n;o++)r.has(o)||u.push(o);for(let o of u)l(o,null);for(let o=0;o<n;o++)!r.has(o)&&!u.includes(o)&&l(o,null);return a}var Te=new WeakMap;function Me(e,t){let n=t instanceof Float32Array?t:new Float32Array(t);Te.set(e,n)}function ct(e){return Te.get(e)}async function lt(e,t){if(!t)return null;let n;if(typeof t=="string")if(typeof fetch<"u"&&typeof createImageBitmap=="function"){let s=await(await fetch(t)).blob();n=await createImageBitmap(s)}else if(typeof Image<"u")n=await new Promise((r,s)=>{let y=new Image;y.crossOrigin="anonymous",y.onload=()=>r(y),y.onerror=s,y.src=t});else return null;else n=t;let a=e.createTexture();return e.bindTexture(3553,a),e.texImage2D(3553,0,6408,6408,5121,n),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9987),e.texParameteri(3553,10240,9729),e.generateMipmap(3553),a}var Ne=new WeakMap,ke=new Float32Array(16);async function De(e,t,n){let a=n?await lt(e.gl,n):null;e[t]&&e.gl.deleteTexture(e[t]),e[t]=a}var Ue={name:"environment-map",setEnvironmentImage(e,t){return De(e,"environmentTexture",t)},setSkyboxImage(e,t){return De(e,"skyboxTexture",t)},onBeforeDrawScene(e,t,n,a,r){if(!e.skyboxTexture||typeof t.createProgram!="function")return;let s=Ne.get(t);if(!s){let b=(g,x)=>{let R=t.createShader(g);return t.shaderSource(R,x),t.compileShader(R),R},S=t.createProgram();t.attachShader(S,b(35633,`#version 300 es
|
|
18
|
+
out vec2 vNDC;void main(){vec2 p=vec2((gl_VertexID<<1)&2,gl_VertexID&2);vNDC=p*2.-1.;gl_Position=vec4(vNDC,.999999,1.);}`)),t.attachShader(S,b(35632,`#version 300 es
|
|
19
|
+
precision highp float;in vec2 vNDC;uniform mat4 uInvVP;uniform vec3 uCameraPos;uniform sampler2D uSkyboxMap;uniform float uExposure;out vec4 fragColor;vec2 eqUV(vec3 d){return vec2(atan(d.x,d.z)/6.2831853+.5,asin(clamp(d.y,-1.,1.))/3.1415926+.5);}void main(){vec4 fp=uInvVP*vec4(vNDC,1.,1.);vec3 dir=normalize(fp.xyz/fp.w-uCameraPos);fragColor=vec4(pow(texture(uSkyboxMap,eqUV(dir)).rgb*uExposure,vec3(1./2.2)),1.);}`)),t.linkProgram(S);let w=typeof t.createVertexArray=="function"?t.createVertexArray():null;s={program:S,vao:w},Ne.set(t,s)}let y=Ve(ke,n)||ke;t.depthMask(!1),t.useProgram(s.program),s.vao&&t.bindVertexArray(s.vao),t.activeTexture(33984),t.bindTexture(3553,e.skyboxTexture);let l=t.getUniformLocation(s.program,"uSkyboxMap");l&&t.uniform1i(l,0);let u=t.getUniformLocation(s.program,"uInvVP");u&&t.uniformMatrix4fv(u,!1,y);let m=t.getUniformLocation(s.program,"uCameraPos");m&&t.uniform3f(m,a[0],a[1],a[2]);let o=t.getUniformLocation(s.program,"uExposure");o&&t.uniform1f(o,e.exposure??1),t.drawArrays(4,0,3),t.depthMask(!0)},onResolveShader(e,t,n,a){if(a.includes("evalSHIrradiance"))return null;let r=a.replace("out vec4 fragColor;",`uniform vec3 uSH[9];
|
|
20
|
+
uniform int uHasSH;
|
|
21
|
+
out vec4 fragColor;`).replace("void main(){",`vec3 integrateBRDFApprox(vec3 f0,float r,float NoV){vec4 c0=vec4(-1.,-.0275,-.572,.022),c1=vec4(1.,.0425,1.04,-.04),rv=r*c0+c1;float a=min(rv.x*rv.x,exp2(-9.28*NoV))*rv.x+rv.y;vec2 ab=vec2(-1.04,1.04)*a+rv.zw;return f0*ab.x+vec3(ab.y);}
|
|
22
|
+
vec3 evalSHIrradiance(vec3 n){return max(vec3(0.),uSH[0]+uSH[1]*n.y+uSH[2]*n.z+uSH[3]*n.x+uSH[4]*(n.x*n.y)+uSH[5]*(n.y*n.z)+uSH[6]*(3.*n.z*n.z-1.)+uSH[7]*(n.x*n.z)+uSH[8]*(n.x*n.x-n.y*n.y));}
|
|
23
|
+
void main(){`);return r=r.replace(`if(uHasEnvironmentMap==1){
|
|
24
|
+
specularIBL=texture(uEnvironmentMap,equirectangularUV(R)).rgb*(F*brdf.x+brdf.y);
|
|
25
|
+
envDiffuse=texture(uEnvironmentMap,equirectangularUV(N)).rgb;
|
|
26
|
+
}`,`if(uHasEnvironmentMap==1){
|
|
27
|
+
specularIBL=textureLod(uEnvironmentMap,equirectangularUV(R),clamp(roughness*6.0,0.0,6.0)).rgb*integrateBRDFApprox(F,roughness,NoV);
|
|
28
|
+
envDiffuse=uHasSH==1?evalSHIrradiance(N):textureLod(uEnvironmentMap,equirectangularUV(N),5.0).rgb;
|
|
29
|
+
}else if(uHasSH==1){
|
|
30
|
+
specularIBL=getStudioRadiance(R,roughness)*integrateBRDFApprox(F,roughness,NoV);
|
|
31
|
+
envDiffuse=evalSHIrradiance(N);
|
|
32
|
+
}`),{vs:n,fs:r}},onBeforeDrawPrimitive(e,t,n,a,r,s){let y=Te.get(e),l=e.getUniformLocation(t,"uHasSH");if(y&&y.length>=27){l&&e.uniform1i(l,1);let u=e.getUniformLocation(t,"uSH");u&&e.uniform3fv(u,y)}else l&&e.uniform1i(l,0)},onAttributeChanged(e,t,n,a){t==="environment-image"&&e.viewer?this.setEnvironmentImage?.(e.viewer,a):t==="skybox-image"&&e.viewer&&this.setSkyboxImage?.(e.viewer,a)}};var Re=new WeakMap;function Se(e,t){let n=t||e.viewer;if(!n||typeof n.projectPointToScreen!="function")return;let a=e.mockHotspots||e.querySelectorAll('[slot^="hotspot-"], [data-position]');for(let r=0;r<a.length;r++){let s=a[r],y=s.getAttribute("data-position");if(!y)continue;let l=y.trim().split(/\s+/).map(b=>parseFloat(b.replace(/m$/,"")));if(l.length<3||l.some(isNaN))continue;let u=s.getAttribute("data-normal"),m;if(u){let b=u.trim().split(/\s+/).map(S=>parseFloat(S));b.length>=3&&!b.some(isNaN)&&(m=[b[0],b[1],b[2]])}let o=n.projectPointToScreen([l[0],l[1],l[2]],m);s.style.position="absolute",s.style.left="0",s.style.top="0",s.style.transform=`translate(-50%, -50%) translate3d(${o.x}px, ${o.y}px, 0)`,s.style.zIndex="3",o.visible?(s.style.opacity="1",s.style.pointerEvents="auto",s.removeAttribute("data-occluded")):(s.style.opacity="0",s.style.pointerEvents="none",s.setAttribute("data-occluded",""))}}var He={name:"hotspots",updateHotspotsForElement:Se,onElementConnected(e){if(typeof MutationObserver>"u"||!e)return;let t=new MutationObserver(()=>{Se(e)});t.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-position","data-normal"]}),Re.set(e,t)},onCameraChange(e,t){t&&Se(t,e)},onElementDisconnected(e){let t=Re.get(e);t&&(t.disconnect(),Re.delete(e))}};function le(e,t,n,a){let r=typeof e=="number"&&Number.isFinite(e)?e:a;return Math.max(t,Math.min(n,r))}function ut(e){return Array.isArray(e)&&e.length>=3&&Number.isFinite(e[0])&&Number.isFinite(e[1])&&Number.isFinite(e[2])}function ft(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function ze(e){let t=ft(e);if(!t)return null;let n=t.target;return{target:ut(n)?[n[0],n[1],n[2]]:typeof n=="string"&&n.length>0&&n.length<=256?n:[0,0,0],radius:le(t.radius,.01,50,.5),speed:le(t.speed,-20,20,.5),height:le(t.height,-10,10,0),phase:le(t.phase,-1e6,1e6,0),faceCenter:t.faceCenter===!0}}function Be(e,t,n,a){let r=t[0],s=t[1],y=t[2],l=t[3],u=n[0],m=n[1],o=n[2],b=n[3],S=r*u+s*m+y*o+l*b;if(S<0&&(u=-u,m=-m,o=-o,b=-b,S=-S),Math.abs(S)>=1)return e[0]=r,e[1]=s,e[2]=y,e[3]=l,e;let w=Math.acos(S),g=Math.sqrt(1-S*S);if(Math.abs(g)<.001)return e[0]=.5*(r+u),e[1]=.5*(s+m),e[2]=.5*(y+o),e[3]=.5*(l+b),e;let x=Math.sin((1-a)*w)/g,R=Math.sin(a*w)/g;return e[0]=r*x+u*R,e[1]=s*x+m*R,e[2]=y*x+o*R,e[3]=l*x+b*R,e}var Oe=1024,we=256,ue=2048,mt=128,dt=64,pt=16,bt=1e4,yt=8,Y=new Set(["__proto__","constructor","prototype"]),We={neg:e=>-e,abs:Math.abs,sign:Math.sign,floor:Math.floor,ceil:Math.ceil,round:Math.round,trunc:Math.trunc,fract:e=>e-Math.floor(e),sqrt:e=>Math.sqrt(Math.max(0,e)),cbrt:Math.cbrt,exp:Math.exp,log:e=>e>0?Math.log(e):0,sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:e=>Math.asin(Math.max(-1,Math.min(1,e))),acos:e=>Math.acos(Math.max(-1,Math.min(1,e))),atan:Math.atan,rad:e=>e*Math.PI/180,deg:e=>e*180/Math.PI,saturate:e=>Math.max(0,Math.min(1,e))},Ge={add:(e,t)=>e+t,sub:(e,t)=>e-t,mul:(e,t)=>e*t,div:(e,t)=>Math.abs(t)<1e-12?0:e/t,rem:(e,t)=>Math.abs(t)<1e-12?0:e%t,mod:(e,t)=>Math.abs(t)<1e-12?0:e%t,min:Math.min,max:Math.max,pow:Math.pow,atan2:Math.atan2},fe={translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]},de=(e,t)=>e!==null&&typeof e=="object"&&!Y.has(t)&&Object.prototype.hasOwnProperty.call(e,t),W=e=>Array.isArray(e)?[...e]:e,qe=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)&&de(e,"value")?e.value:e,D=(e,t)=>de(e.configuration,t)?qe(e.configuration[t]):void 0,T=(e,t=0)=>{let n=Number(e);return Number.isFinite(n)?n:t},J=e=>Math.max(0,Math.min(1,e)),X=e=>typeof e=="boolean"?e:typeof e=="number"?e!==0&&!Number.isNaN(e):typeof e=="string"?e.length>0&&e!=="false":!!e;function me(e){if(typeof e!="string"||!e.startsWith("/"))return null;let t=[];for(let n of e.slice(1).split("/")){let a=n.replace(/~1/g,"/").replace(/~0/g,"~");if(!a||Y.has(a)||Y.has(n))return null;t.push(a)}return{segments:t}}var te=(e,t)=>{if(e===void 0||!/^\d+$/.test(e))return-1;let n=Number(e);return Number.isSafeInteger(n)&&n>=0&&n<t?n:-1},Xe=e=>{let t=T(e[0]),n=T(e[1]),a=T(e[2]),r=T(e[3],1),s=Math.hypot(t,n,a,r);return s>1e-8?[t/s,n/s,a/s,r/s]:[0,0,0,1]},$e=(e,t,n,a)=>{if(typeof e=="number"&&typeof t=="number")return e+(t-e)*n;if(Array.isArray(e)&&Array.isArray(t)){if(a&&e.length===4&&t.length===4){let r=[0,0,0,1];return Be(r,Xe(e),Xe(t),n),r}return e.slice(0,t.length).map((r,s)=>r+(t[s]-r)*n)}return n>=.5?t:e},Ee=(e,t,n)=>Array.isArray(e)&&Array.isArray(t)?e.slice(0,t.length).map((a,r)=>n(T(a),T(t[r]))):Array.isArray(e)?e.map(a=>n(T(a),T(t))):Array.isArray(t)?t.map(a=>n(T(e),T(a))):n(T(e),T(t)),ht=(e,t)=>Array.isArray(e)?e.map(n=>t(T(n))):t(T(e)),je=(e,t)=>Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((n,a)=>Math.abs(n-t[a])<=1e-6):e===t,pe=class{constructor(t,n,a){let r=Array.isArray(a.nodes)?a.nodes:[];if(r.length>Oe)throw new Error(`SecurityError: Exceeds MAX_GRAPH_NODES (${Oe})`);let s=Array.isArray(a.variables)?a.variables:[];if(s.length>we)throw new Error(`SecurityError: Exceeds MAX_VARIABLES (${we})`);let y=Array.isArray(a.declarations)?a.declarations:[],l=Array.isArray(a.events)?a.events:[],u=new Map,m=new Map,o=new Map,b=new Map,S=new Map,w=new Map,g=[],x=[],R=new Map,I=1,C=0,E=0,F=0,L=0,N=!1,G=!1,H=!1;s.forEach((d,p)=>{if(!d||typeof d!="object")return;let v=W(qe(d.value));u.set(p,v);let A=d.id??d.name;typeof A=="string"&&A&&!Y.has(A)&&u.set(A,v)}),(n?.nodes||[]).forEach((d,p)=>{for(let v of d?.children||[])typeof v=="number"&&R.set(v,p)});let O=d=>d.op||typeof d.declaration=="number"&&y[d.declaration]?.op||"",U=(d,p,v)=>{if(Y.has(p))return;let A=m.get(d);A||m.set(d,A=Object.create(null)),A[p]=v},K=(d,p)=>{if(typeof d!="number"&&typeof d!="string"||typeof d=="string"&&Y.has(d)||!u.has(d)&&u.size>=we*2)return;let v=W(p);if(u.set(d,v),typeof d=="number"){let A=s[d]?.id??s[d]?.name;typeof A=="string"&&!Y.has(A)&&u.set(A,v)}},q=d=>typeof d=="number"?l[d]?.id??String(d):typeof d=="string"?/^\d+$/.test(d)&&l[Number(d)]?.id?l[Number(d)].id:d:"",Z=(d,p)=>{for(let v=d,A=0;v!==void 0&&v>=0&&A<128;v=R.get(v),A++)if(v===p)return!0;return!1},z=d=>{for(let p=g.length-1;p>=0;p--)g[p].key===d&&g.splice(p,1)},Fe=d=>{z(d.key),g.length>=mt&&g.shift(),g.push(d)},he=d=>{let p=me(d)?.segments;if(p){if(p[0]==="nodes"&&Array.isArray(n?.nodes)){let v=n.nodes[te(p[1],n.nodes.length)];if(!v)return;let A=p[2];if(A in fe){let f=fe[A],i=v[A]||f;return f.map((c,h)=>T(i[h],c))}if(A==="weights"){let f=Array.isArray(v.weights)?v.weights:[0],i=p.length===4?te(p[3],64):-2;return i===-2?f.map(c=>T(c)):i>=0?T(f[i]):void 0}if(A==="visible"||A==="extensions"&&p[3]==="KHR_node_visibility"&&p[4]==="visible")return v.extensions?.KHR_node_visibility?.visible??v.visible??!0}else if(p[0]==="materials"&&Array.isArray(n?.materials)){let v=n.materials[te(p[1],n.materials.length)];if(!v)return;let A=v.pbrMetallicRoughness||{};if(p[2]==="pbrMetallicRoughness"){if(p[3]==="baseColorFactor"){let f=A.baseColorFactor||[1,1,1,1];return[T(f[0],1),T(f[1],1),T(f[2],1),T(f[3],1)]}if(p[3]==="metallicFactor"||p[3]==="roughnessFactor")return T(A[p[3]],1)}if(p[2]==="emissiveFactor"){let f=v.emissiveFactor||[0,0,0];return[T(f[0]),T(f[1]),T(f[2])]}if(p[2]==="alphaCutoff")return T(v.alphaCutoff,.5)}}},ae=(d,p)=>{let v=me(d)?.segments;if(!v)return!1;if(v[0]==="nodes"&&Array.isArray(n?.nodes)){let A=te(v[1],n.nodes.length),f=n.nodes[A];if(!f)return!1;let i=v[2];if(i in fe&&Array.isArray(p)){let c=fe[i];if(p.length<c.length)return!1;let h=c.map((V,k)=>T(p[k],V));if(i==="rotation"){let V=Math.hypot(...h);h=V>1e-8?h.map(k=>k/V):[0,0,0,1]}f[i]=h,delete f.matrix;let P=t?.initialNodeTransforms?.[A];return P&&(P[i[0]]=[...h]),N=!0,!0}if(i==="weights"){Array.isArray(f.weights)||(f.weights=[]);let c=(h,P)=>{for(let V of t?.meshes||[])if(V.nodeIndex===A)for(let k of V.primitives||[])k.pluginData?.morph?.weights&&(k.pluginData.morph.weights[h]=P)};if(v.length===4){let h=te(v[3],64);if(h<0)return!1;c(h,f.weights[h]=T(p))}else if(Array.isArray(p))f.weights=p.slice(0,64).map(h=>T(h)),f.weights.forEach((h,P)=>c(P,h));else return!1;return H=!0,!0}if(i==="visible"||i==="extensions"&&v[3]==="KHR_node_visibility"&&v[4]==="visible"){let c=X(p);return f.visible=c,(!f.extensions||typeof f.extensions!="object")&&(f.extensions={}),f.extensions.KHR_node_visibility={visible:c},G=!0,!0}}else if(v[0]==="materials"&&Array.isArray(n?.materials)){let A=te(v[1],n.materials.length),f=n.materials[A];if(!f)return!1;let i=f.pbrMetallicRoughness||(f.pbrMetallicRoughness={}),c=h=>{for(let P of t?.meshes||[])for(let V of P.primitives||[])(V.materialIndex??0)===A&&h(V)};if(v[2]==="pbrMetallicRoughness"){if(v[3]==="baseColorFactor"&&Array.isArray(p)&&p.length>=3){let h=[J(T(p[0],1)),J(T(p[1],1)),J(T(p[2],1)),p[3]!==void 0?J(T(p[3],1)):i.baseColorFactor?.[3]??1];return i.baseColorFactor=h,c(P=>P.baseColor=[...h]),H=!0}if(v[3]==="metallicFactor"||v[3]==="roughnessFactor"){let h=v[3]==="metallicFactor",P=J(T(p,h?0:.5));return i[v[3]]=P,c(V=>V[h?"metallic":"roughness"]=P),H=!0}}if(v[2]==="emissiveFactor"&&Array.isArray(p)&&p.length>=3)return f.emissiveFactor=[0,1,2].map(h=>Math.max(0,T(p[h]))),H=!0;if(v[2]==="alphaCutoff")return f.alphaCutoff=J(T(p,.5)),H=!0}return!1},ge=(d,p,v=new Set)=>{let A=D(p,"pointer");if(typeof A!="string"||!A.startsWith("/"))return null;let f=A.replace(/\{([a-zA-Z0-9_]+)\}/g,(i,c)=>{let h=Math.trunc(Number(ie(d,c,void 0,v)??D(p,c)));return Number.isSafeInteger(h)&&h>=0?String(h):"-1"});return me(f)?f:null},ie=(d,p,v,A)=>{let f=r[d]?.values;if(!de(f,p))return v;let i=f[p];if(i==null)return v;if(typeof i!="object"||Array.isArray(i))return W(i);let c=i;return typeof c.node=="number"?ot(c.node,c.socket||"value",A):de(c,"value")?W(c.value):v},ot=(d,p,v)=>{if(d<0||d>=r.length||v.has(d)||v.size>128||++F>bt)return;let A=r[d],f=O(A);if(/^(event\/|pointer\/on|scene\/on|flow\/)/.test(f))return W(m.get(d)?.[p]);v.add(d);try{let i=(c,h=0)=>ie(d,c,h,v);if(f==="variable/get"){let c=D(A,"variable")??D(A,"id");return typeof c=="number"||typeof c=="string"?W(u.get(c)):void 0}if(f==="pointer/get"){let c=ge(d,A,v);return c?he(c):void 0}if(f.startsWith("math/")){let c=f.slice(5);if(c in We)return ht(i("a"),We[c]);if(c in Ge){let h=/^(mul|div|rem|mod|pow)$/.test(c)?1:0;return Ee(i("a",c==="mul"?1:0),i("b",h),Ge[c])}if(c==="pi")return Math.PI;if(c==="e")return Math.E;if(c==="random")return Math.random();if(c==="clamp")return Ee(Ee(i("a"),i("b",i("min",0)),Math.max),i("c",i("max",1)),Math.min);if(c==="mix"||c==="quatSlerp")return $e(i("a",0),i("b",1),T(i("c",i("t",.5)),.5),c==="quatSlerp");if(c==="dot"){let h=i("a"),P=i("b");return Array.isArray(h)&&Array.isArray(P)?h.reduce((V,k,M)=>V+(k||0)*(P[M]||0),0):T(h)*T(P)}if(c==="cross"){let h=i("a",[0,0,0]),P=i("b",[0,0,0]);return Array.isArray(h)&&Array.isArray(P)?[(h[1]||0)*(P[2]||0)-(h[2]||0)*(P[1]||0),(h[2]||0)*(P[0]||0)-(h[0]||0)*(P[2]||0),(h[0]||0)*(P[1]||0)-(h[1]||0)*(P[0]||0)]:[0,0,0]}if(c==="length"){let h=i("a");return Array.isArray(h)?Math.hypot(...h):Math.abs(T(h))}if(c==="distance"){let h=i("a"),P=i("b");return Array.isArray(h)&&Array.isArray(P)?Math.hypot(...h.map((V,k)=>(V||0)-(P[k]||0))):Math.abs(T(h)-T(P))}if(c==="normalize"){let h=i("a");if(!Array.isArray(h))return T(h)>=0?1:-1;let P=Math.hypot(...h);return P>1e-8?h.map(V=>V/P):h.map(()=>0)}if(c.startsWith("combine"))return["a","b","c","d"].slice(0,Number(c[7])||2).map(h=>T(i(h)));if(c.startsWith("extract")){let h=i("a");return Array.isArray(h)?h[p==="0"||p==="x"?0:p==="1"||p==="y"?1:p==="2"||p==="z"?2:3]??0:0}if(c==="eq")return je(i("a"),i("b"));if(c==="ne")return!je(i("a"),i("b"));if(c==="lt")return T(i("a"))<T(i("b"));if(c==="le")return T(i("a"))<=T(i("b"));if(c==="gt")return T(i("a"))>T(i("b"));if(c==="ge")return T(i("a"))>=T(i("b"));if(c==="isNaN")return Number.isNaN(Number(i("a")));if(c==="isInf"){let h=Number(i("a"));return!Number.isFinite(h)&&!Number.isNaN(h)}return c==="and"?X(i("a",!1))&&X(i("b",!1)):c==="or"?X(i("a",!1))||X(i("b",!1)):c==="xor"?X(i("a",!1))!==X(i("b",!1)):c==="not"?!X(i("a",!1)):c==="select"?W(X(i("condition",!1))?i("a"):i("b")):void 0}return f==="type/boolToInt"||f==="type/boolToFloat"?X(i("a",!1))?1:0:f==="type/intToBool"||f==="type/floatToBool"?T(i("a",0))!==0:f==="type/intToFloat"?T(i("a",0)):f==="type/floatToInt"?Math.trunc(T(i("a",0))):void 0}finally{v.delete(d)}},se=()=>{if(N){N=!1,H=!0;let d=Ae(n);if(t){t.worldMatrices=d;for(let p of t.meshes||[])p.nodeIndex>=0&&p.nodeIndex<d.length&&(p.transform.set(d[p.nodeIndex]),re(p.normalMatrix,p.transform))}}if(G){G=!1,H=!0;let d=n?.nodes;if(Array.isArray(t?.meshes)&&Array.isArray(d))for(let p of t.meshes){let v=!0;for(let A=p.nodeIndex,f=0;A!==void 0&&A>=0&&f<128;A=R.get(A),f++){let i=d[A];if(i?.visible===!1||i?.extensions?.KHR_node_visibility?.visible===!1){v=!1;break}}p.visible=v}}H&&(H=!1,t?.render?.())},ee=(d,p={steps:0})=>{if(!d||typeof d.node!="number")return;p.steps===0&&(F=0);let v=[d],A=f=>{v.length+p.steps<ue&&v.push(f)};for(;v.length>0&&p.steps<ue;){p.steps++;let f=v.shift();if(!f||f.node<0||f.node>=r.length)continue;let i=f.node,c=r[i];if(!c)continue;let h=f.socket||"in",P=O(c),V=(M,_=void 0)=>ie(i,M,_,new Set),k=(M="out")=>{let _=c.flows?.[M];_&&A(_)};switch(P){case"flow/branch":k(X(V("condition",!1))?"true":"false");break;case"flow/sequence":for(let M of Object.keys(c.flows||{}).sort((_,B)=>Number(_)-Number(B)||_.localeCompare(B)))k(M);break;case"flow/switch":{let M=c.flows?.[String(V("selection",V("value",0)))]??c.flows?.default;M&&A(M);break}case"flow/for":{let M=Math.trunc(T(V("startIndex",0))),_=Math.trunc(T(V("endIndex",0))),B=Math.max(1,Math.trunc(T(V("step",1),1))),$=c.flows?.body;if($&&_>M&&L<yt){let at=Math.min(Math.ceil((_-M)/B),ue);L++;try{for(let xe=0;xe<at&&p.steps<ue;xe++)U(i,"index",M+xe*B),ee($,p)}finally{L--}}let Le=c.flows?.completed??c.flows?.out;Le&&A(Le);break}case"flow/doN":{let M=h==="reset"?0:(o.get(i)||0)+1;if(o.set(i,M),U(i,"currentCount",M),U(i,"count",M),h!=="reset"){let _=Math.trunc(T(V("n",D(c,"stopIterations")??D(c,"n")??1),1));M<=_&&k()}break}case"flow/multiGate":{if(h==="reset"){w.set(i,0);break}let M=Object.keys(c.flows||{}).sort();if(!M.length)break;let _=D(c,"isRandom")?Math.floor(Math.random()*M.length):w.get(i)||0;_<M.length&&(k(M[_]),w.set(i,D(c,"isLoop")!==!1?(_+1)%M.length:_+1));break}case"flow/waitAll":{if(h==="reset"){b.delete(i);break}let M=b.get(i);M||b.set(i,M=new Set),M.add(h),M.size>=Math.max(1,Math.trunc(Number(D(c,"inputFlows")??2)||2))&&(M.clear(),k("out"),k("completed"));break}case"flow/throttle":{if(h==="reset"){S.delete(i);break}let M=Math.max(0,T(V("duration",0))),_=S.get(i);_===void 0||C-_>=M?(S.set(i,C),U(i,"lastRemainingTime",0),k()):U(i,"lastRemainingTime",Math.max(0,M-(C-_)));break}case"flow/delay":case"flow/setDelay":{if(h==="cancel"){for(let $=x.length-1;$>=0;$--)x[$].nodeIdx===i&&x.splice($,1);U(i,"lastDelayIndex",-1);break}let M=Math.max(0,T(V("duration",D(c,"duration")??0))),_=c.flows?.done??c.flows?.out;if(M<=0){U(i,"lastDelayIndex",-1),_&&A(_);break}x.length>=dt&&x.shift();let B=I++;U(i,"lastDelayIndex",B),x.push({id:B,nodeIdx:i,rem:M,done:_}),P==="flow/setDelay"&&c.flows?.out&&c.flows?.done&&k("out");break}case"flow/cancelDelay":{let M=Math.trunc(T(V("delayIndex",-1),-1));if(M<0)x.length=0;else for(let _=x.length-1;_>=0;_--)x[_].id===M&&x.splice(_,1);k();break}case"variable/set":K(D(c,"variable")??D(c,"id"),V("value")),k();break;case"variable/interpolate":{let M=D(c,"variable")??D(c,"id"),_=V("value",V("target")),B=Math.max(0,T(V("duration",D(c,"duration")??.3),.3));M!==void 0&&_!==void 0&&Fe({key:`var:${String(M)}`,varKey:M,from:W(V("from")??u.get(M)??0),to:W(_),dur:B,elapsed:0,quat:!1,linear:D(c,"easing")==="linear",done:c.flows?.done}),k();break}case"pointer/set":{let M=ge(i,c),_=V("value");M&&_!==void 0&&(z(`ptr:${M}`),ae(M,_)),k();break}case"pointer/interpolate":{let M=ge(i,c),_=V("value",V("target")),B=Math.max(0,T(V("duration",D(c,"duration")??.3),.3));if(M&&_!==void 0){let $=V("from")??he(M);$!==void 0&&(B<=0?(ae(M,_),k("done")):Fe({key:`ptr:${M}`,ptr:M,from:W($),to:W(_),dur:B,elapsed:0,quat:M.endsWith("/rotation"),linear:D(c,"easing")==="linear",done:c.flows?.done}))}k();break}case"animation/start":{let M=V("animation")??D(c,"animation")??D(c,"clipName"),_=typeof M=="number"?t?.animations?.[M]?.name??n?.animations?.[M]?.name:typeof M=="string"?M:void 0;t?.playAnimation?.(_),H=!0,k();break}case"animation/stop":case"animation/resetAt":t?.pauseAnimation?.(),P==="animation/resetAt"&&t?.evaluateAnimation?.(T(V("time",0))),H=!0,k();break;case"event/send":case"customEvent/send":{let M=q(D(c,"event")??D(c,"id")),_={};for(let B of Object.keys(c.values||{}))Y.has(B)||(_[B]=V(B));M&&(typeof CustomEvent<"u"&&typeof t?.container?.dispatchEvent=="function"&&t.container.dispatchEvent(new CustomEvent("interactivityEvent",{bubbles:!0,composed:!0,detail:{id:M,values:_}})),Pe(M,_,p)),k();break}default:k();break}}};this.readScenePointer=he,this.writeScenePointer=ae,this.fireOnStart=()=>{r.forEach(d=>{O(d)==="event/onStart"&&ee(d.flows?.out)}),se()},this.fireOnSelect=d=>{if(!d)return;let p=typeof d.meshIndex=="number"?d.meshIndex:-1,v=typeof d.nodeIndex=="number"?d.nodeIndex:t?.meshes?.[p]?.nodeIndex??-1;r.forEach((A,f)=>{if(!/^(pointer|event|scene)\/onSelect$/.test(O(A)))return;let i=D(A,"nodeIndex")??D(A,"node")??ie(f,"nodeIndex",void 0,new Set),c=D(A,"meshName");if(typeof c=="string"&&c?d.meshName===c:i==null||Number(i)<0||Number.isNaN(Number(i))||Z(v,Math.trunc(Number(i)))){if(U(f,"nodeIndex",v),U(f,"meshIndex",p),Array.isArray(d.hitPoint)){let P=[T(d.hitPoint[0]),T(d.hitPoint[1]),T(d.hitPoint[2])];U(f,"hitPoint",P),U(f,"point",P),U(f,"intersectionPoint",P)}if(Array.isArray(d.normal)){let P=[T(d.normal[0]),T(d.normal[1],1),T(d.normal[2])];U(f,"normal",P),U(f,"hitNormal",P)}typeof d.distance=="number"&&U(f,"distance",d.distance),ee(A.flows?.out)}}),se()},this.receiveCustomEvent=(d,p={})=>Pe(d,p,{steps:0});function Pe(d,p,v){if(!(E>=pt)){E++;try{let A=q(d);r.forEach((f,i)=>{if(!/^(customE|e)vent\/receive$/.test(O(f)))return;let c=D(f,"event")??D(f,"id");if(!(q(c)!==A&&String(c)!==String(d))){for(let[h,P]of Object.entries(p))Y.has(h)||U(i,h,W(P));ee(f.flows?.out,v)}}),se()}finally{E--}}}this.tick=d=>{if(!Number.isFinite(d)||d<0)return;let p=Math.min(d,.25);C+=p,r.forEach((A,f)=>{O(A)==="event/onTick"&&(U(f,"timeDelta",p),U(f,"dt",p),U(f,"timeElapsed",C),ee(A.flows?.out))});let v=[];for(let A=g.length-1;A>=0;A--){let f=g[A];f.elapsed+=p;let i=f.dur>1e-6?J(f.elapsed/f.dur):1,c=f.linear?i:i*i*(3-2*i),h=$e(f.from,f.to,c,f.quat);f.ptr?ae(f.ptr,h):f.varKey!==void 0&&K(f.varKey,h),i>=1&&(g.splice(A,1),f.done&&v.push(f.done))}for(let A=x.length-1;A>=0;A--){let f=x[A];f.rem-=p,f.rem<=0&&(x.splice(A,1),f.done&&v.push(f.done))}for(let A of v)ee(A);se()},this.dispose=()=>{g.length=0,x.length=0,u.clear(),m.clear(),o.clear(),b.clear(),S.clear(),w.clear()}}},j=new WeakMap,be=new WeakMap;function gt(e,t){if(!e||typeof e!="object"||!Number.isFinite(t)||t<=0||Ce().some(l=>l.name==="xr-live-head-follow"))return;let n=e.gltf,a=n?.nodes;if(!Array.isArray(a)||a.length===0)return;let r=Math.min(t,.1),s=(be.get(e)||0)+r,y=!1;for(let l=0;l<a.length;l++){let u=a[l],m=ze(u?.extras?.xr?.orbit);if(!m)continue;let o=0,b=0,S=0;if(Array.isArray(m.target))o=m.target[0],b=m.target[1],S=m.target[2];else if(typeof m.target=="string"&&m.target!=="head"){let I=a.find(C=>C?.name===m.target);Array.isArray(I?.translation)&&(o=T(I.translation[0]),b=T(I.translation[1]),S=T(I.translation[2]))}let w=m.phase+m.speed*s,g=o+Math.cos(w)*m.radius,x=b+m.height,R=S+Math.sin(w)*m.radius;if(u.translation=[g,x,R],m.faceCenter){let I=Math.atan2(o-g,S-R);u.rotation=[0,Math.sin(I*.5),0,Math.cos(I*.5)]}y=!0}if(y){be.set(e,s);let l=Ae(n);e.worldMatrices=l;for(let u of e.meshes||[])u.nodeIndex>=0&&u.nodeIndex<l.length&&(u.transform.set(l[u.nodeIndex]),re(u.normalMatrix,u.transform))}}function Ie(e){if(!(!e||typeof e!="object"))return j.get(e)||j.get(e.viewer)||j.get(e._view)}function Ye(e,t,n){let a=Ie(e);return a?(a.receiveCustomEvent(t,n),!0):!1}var Ke={name:"khr-interactivity",sendInteractivityEvent:Ye,getInteractivityVM:Ie,onLoadModel(e,t){if(!e||typeof e!="object")return;j.get(e)?.dispose(),j.delete(e),be.delete(e);let n=t?.extensions?.KHR_interactivity,a=Array.isArray(n?.graphs)?n.graphs[n.graph??0]:n;if(!a||!Array.isArray(a.nodes))return;let r=new pe(e,t,a);j.set(e,r),r.fireOnStart()},onMeshSelect(e,t){j.get(e)?.fireOnSelect(t)},onUpdate(e,t){j.get(e)?.tick(t),gt(e,t)},onDestroy(e,t){j.get(t)?.dispose(),j.delete(t),be.delete(t)}};var oe=new Map,_e=new WeakMap;function xt(e,t){oe.set(e,t)}var Ze={name:"materials",onBuildPrimitiveVAO(e,t,n,a,r){return(((a?.materials&&n.material!==void 0?a.materials[n.material]:null)?.extensions||{}).KHR_materials_transmission?.transmissionFactor??0)>0?{isTransmissive:!0}:null},onBeforeTransmissivePass(e,t){let n=_e.get(e);n||(n=e.createTexture(),_e.set(e,n));let a=Math.max(1,t.canvas.width),r=Math.max(1,t.canvas.height);e.activeTexture(33990),e.bindTexture(3553,n),e.copyTexImage2D(3553,0,6408,0,0,a,r,0),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9987),e.texParameteri(3553,10240,9729),e.generateMipmap(3553)},onResolveShader(e,t,n,a){if(!t)return null;if(t.name&&oe.has(t.name)){let g=oe.get(t.name);return{vs:g.vs||n,fs:g.fs||a}}let r=t.extensions||{},s=r.KHR_materials_clearcoat,y=r.KHR_materials_sheen,l=!!r.KHR_materials_transmission,u=!!r.KHR_materials_ior,m=r.KHR_materials_iridescence;if(!s&&!y&&!r.KHR_materials_unlit&&!l&&!r.KHR_materials_volume&&!u&&!r.KHR_materials_dispersion&&!m)return null;if(r.KHR_materials_unlit)return{vs:n,fs:a.replace("fragColor=vec4(color,outAlpha);","fragColor=vec4(base.rgb,outAlpha);").replace("fragColor=vec4(color,base.a);","fragColor=vec4(base.rgb,base.a);")};let o=a;l&&(o=o.replace("out vec4 fragColor;",`uniform sampler2D uTransmissionTex;
|
|
33
|
+
uniform vec2 uViewportSize;
|
|
34
|
+
out vec4 fragColor;`));let b=(g,x,R=0,I=1e6,C=3)=>{let E=Number(g);return(Number.isFinite(E)?Math.min(I,Math.max(R,E)):x).toFixed(C)},S=Number(r.KHR_materials_ior?.ior??1.5),w=Number.isFinite(S)?Math.min(10,Math.max(1,S)):1.5;if(u){let g=Math.pow((w-1)/(w+1),2);o=o.replace("vec3 F0=mix(vec3(0.04),base.rgb,metallic);",`vec3 F0=mix(vec3(${b(g,.04,0,1,4)}),base.rgb,metallic);`)}if(m){let g=b(m.iridescenceFactor,1,0,1),x=b(m.iridescenceIor,1.3,1,10);o=o.replace("vec3 F=F_SchlickRoughness(F0,roughness,NoV);",`vec3 F=F_SchlickRoughness(F0,roughness,NoV);vec3 iridColor=.5+.5*cos(800.*${x}*NoV*vec3(.015,.018,.022));F=mix(F,iridColor,${g}*pow(1.-NoV,2.));`)}if(l){let g=b(r.KHR_materials_transmission?.transmissionFactor,1,0,1),x=r.KHR_materials_volume||{},R=b(x.thicknessFactor,.5,0,1e4),I=b(x.attenuationDistance,1,.001,1e6),C=Array.isArray(x.attenuationColor)?x.attenuationColor:[1,1,1],E=b(r.KHR_materials_dispersion?.dispersion,0,0,10);o=o.replace("vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;",`vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;
|
|
35
|
+
vec2 sUV=gl_FragCoord.xy/max(uViewportSize,vec2(1.));float iorB=${b(w,1.5,1,10)},dV=${E},tV=${R},lod=clamp(roughness*5.,0.,5.),sc=.06*(1.+tV);
|
|
36
|
+
vec3 refractedR=refract(-V,N,1./(iorB-.02*dV)),rG=refract(-V,N,1./iorB),refractedB=refract(-V,N,1./(iorB+.02*dV));
|
|
37
|
+
vec3 tr=vec3(textureLod(uTransmissionTex,clamp(sUV+refractedR.xy*sc,.001,.999),lod).r,textureLod(uTransmissionTex,clamp(sUV+rG.xy*sc,.001,.999),lod).g,textureLod(uTransmissionTex,clamp(sUV+refractedB.xy*sc,.001,.999),lod).b);
|
|
38
|
+
vec3 aCol=vec3(${b(C[0],1,0,1)},${b(C[1],1,0,1)},${b(C[2],1,0,1)});
|
|
39
|
+
vec3 volumeAtten=exp(-tV*(vec3(1.)-aCol)/max(${I},.001));
|
|
40
|
+
diffuseIBL=mix(diffuseIBL,tr*volumeAtten*base.rgb,${g});`)}if(s&&!a.includes("uClearcoat")){let g=b(s.clearcoatFactor,1,0,1),x=b(s.clearcoatRoughnessFactor,0,0,1);o=o.replace("fragColor=vec4(color,base.a);",`vec3 ccF=F_SchlickRoughness(vec3(.04),${x},NoV)*${g};color=color*(vec3(1.)-ccF)+getStudioRadiance(R,${x})*ccF;fragColor=vec4(color,base.a);`)}if(y){let g=Array.isArray(y.sheenColorFactor)?y.sheenColorFactor:[1,1,1],x=`color+=vec3(${b(g[0],1,0,1)},${b(g[1],1,0,1)},${b(g[2],1,0,1)})*pow(1.-NoV,4.)*.5;`;o.includes("color=applyToneMapping(color,uToneMapping);")?o=o.replace("color=applyToneMapping(color,uToneMapping);",`${x}color=applyToneMapping(color,uToneMapping);`):o=o.replace("fragColor=vec4(color,base.a);",`${x}fragColor=vec4(color,base.a);`)}return{vs:n,fs:o}},onBeforeDrawPrimitive(e,t,n,a,r,s){let y=n.materialIndex;if(y!==void 0&&s?.materials){let l=s.materials[y];l?.name&&oe.has(l.name)&&oe.get(l.name).onBindUniforms?.(e,t,n)}if(n.isTransmissive){let l=_e.get(e);if(l){e.activeTexture(33990),e.bindTexture(3553,l);let u=e.getUniformLocation(t,"uTransmissionTex");u&&e.uniform1i(u,6);let m=e.getUniformLocation(t,"uViewportSize");m&&e.uniform2f(m,e.drawingBufferWidth||1,e.drawingBufferHeight||1)}}}};var vt=`#version 300 es
|
|
41
|
+
layout(location=0) in vec3 aPosition;layout(location=1) in vec2 aUV;uniform mat4 uMVP;out vec2 vUV;void main(){vUV=aUV;gl_Position=uMVP*vec4(aPosition,1.);}`,At=`#version 300 es
|
|
42
|
+
precision highp float;in vec2 vUV;uniform float uShadowIntensity,uShadowSoftness;out vec4 fragColor;void main(){vec2 p=(vUV-.5)*2.;float d=clamp(length(p),0.,1.);fragColor=vec4(0.,0.,0.,pow(1.-d*d,mix(1.2,2.8,uShadowSoftness))*smoothstep(1.,.85-uShadowSoftness*.6,d)*uShadowIntensity);}`,ye=new WeakMap,Qe=new Float32Array(20);function Je(e,t){let[n,a,r,s,y,l]=t;return[e[0]*n+e[4]*a+e[8]*r+e[12],e[1]*n+e[5]*a+e[9]*r+e[13],e[2]*n+e[6]*a+e[10]*r+e[14],Math.abs(e[0])*s+Math.abs(e[4])*y+Math.abs(e[8])*l,Math.abs(e[1])*s+Math.abs(e[5])*y+Math.abs(e[9])*l,Math.abs(e[2])*s+Math.abs(e[6])*y+Math.abs(e[10])*l]}function Tt(e){if(e._lb!==void 0)return e._lb;let t=1e9,n=1e9,a=1e9,r=-1e9,s=-1e9,y=-1e9;for(let l of e.primitives||[]){let u=l.positions;if(u)for(let m=0;m<u.length;m+=3)u[m]<t&&(t=u[m]),u[m+1]<n&&(n=u[m+1]),u[m+2]<a&&(a=u[m+2]),u[m]>r&&(r=u[m]),u[m+1]>s&&(s=u[m+1]),u[m+2]>y&&(y=u[m+2])}return e._lb=t<=r?[(t+r)*.5,(n+s)*.5,(a+y)*.5,(r-t)*.5,(s-n)*.5,(y-a)*.5]:null}function Mt(e){let t=ye.get(e);if(t)return t;let n=(l,u)=>{let m=e.createShader(l);return e.shaderSource(m,u),e.compileShader(m),m},a=e.createProgram();e.attachShader(a,n(35633,vt)),e.attachShader(a,n(35632,At)),e.linkProgram(a);let r=e.createVertexArray(),s=e.createBuffer(),y=e.createBuffer();return e.bindVertexArray(r),e.bindBuffer(34962,s),e.bufferData(34962,80,35048),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,3,5126,!1,20,0),e.enableVertexAttribArray(1),e.vertexAttribPointer(1,2,5126,!1,20,12),e.bindBuffer(34963,y),e.bufferData(34963,new Uint16Array([0,1,2,0,2,3]),35044),e.bindVertexArray(null),t={prog:a,vao:r,vbo:s,ibo:y,uMVP:e.getUniformLocation(a,"uMVP"),uIntensity:e.getUniformLocation(a,"uShadowIntensity"),uSoftness:e.getUniformLocation(a,"uShadowSoftness")},ye.set(e,t),t}var et={name:"contact-shadow",onAfterRender(e,t,n){let a=t.shadowIntensity;if(a<=0||!t.bounds)return;let r=Mt(e),s=(t.backdropMeshes?.length??0)>0,y=[],l=[];for(let o of t.meshes||[]){if(!o||o.visible===!1||o.isPluginMesh||o.name==="__xr_reticle__"||o.name?.startsWith("__xr_slot_"))continue;let b=Tt(o);if(!b)continue;o.transform&&(b=Je(o.transform,b)),t.modelRootMatrix&&(b=Je(t.modelRootMatrix,b));let[S,w,g,x,R,I]=b,C=[S,g,x,I,w-R,w+R];/floor|table|pedestal|ground|base|plane/i.test(o.name||"")||R<.14&&Math.min(x,I)>.45?l.push(C):y.push(C)}let u=[],m=(t.bounds.min?t.bounds.min[1]:t.bounds.center[1]-t.bounds.radius)+.002;for(let[o,b,S,w,g]of y){let x=-1/0;for(let[I,C,E,F,,L]of l)g>=L-.08&&Math.abs(o-I)<=E&&Math.abs(b-C)<=F&&L+.002>x&&(x=L+.002);s&&(x=Math.max(x,o>=.04&&o<=.36&&b>=-.34&&b<=-.04&&g>=.01?.036:Math.hypot(o,b)<=.66&&g>=-.06?.003:-.477)),isFinite(x)||(x=m);let R=u.find(I=>Math.hypot(o-I[0],b-I[1])<.06&&Math.abs(x-I[5])<.05);R?(R[2]=Math.max(R[2],S*.78),R[3]=Math.max(R[3],w*.78),R[4]=Math.min(R[4],g)):u.push([o,b,S,w,g,x])}if(u.length===0){let o=t.bounds.center,b=Math.max(.1,t.bounds.radius*1.5)/1.45;u.push([o[0],o[2],b,b,m,m])}e.useProgram(r.prog),e.uniformMatrix4fv(r.uMVP,!1,n),e.enable(3042),(e.blendFuncSeparate||e.blendFunc).call(e,770,771,1,771),e.depthMask(!1),e.bindVertexArray(r.vao),e.bindBuffer(34962,r.vbo);for(let[o,b,S,w,g,x]of u){let R=Math.max(0,g-x),I=a/(1+R*2);if(I<.02)continue;let C=1+Math.min(.75,R*.85),E=Math.max(.045,S*1.45*C),F=Math.max(.045,w*1.45*C);Qe.set([o-E,x,b-F,0,0,o+E,x,b-F,1,0,o+E,x,b+F,1,1,o-E,x,b+F,0,1]),e.bufferSubData(34962,0,Qe),e.uniform1f(r.uIntensity,I),e.uniform1f(r.uSoftness,Math.min(1,t.shadowSoftness+Math.min(.45,R*.6))),e.drawElements(4,6,5123,0)}e.bindVertexArray(null),e.depthMask(!0),e.disable(3042)},onDestroy(e){let t=ye.get(e);t&&(e.deleteVertexArray(t.vao),e.deleteBuffer(t.vbo),e.deleteBuffer(t.ibo),e.deleteProgram(t.prog),ye.delete(e))}};var tt=new WeakMap;function Rt(e){let r=new Float32Array(192),s=new Float32Array(32*2*3),y=new Float32Array(32*2*2),l=new Uint16Array(32*6);for(let R=0;R<32;R++){let I=R/32*Math.PI*2,C=Math.cos(I),E=Math.sin(I),F=R*2,L=R*2+1;r[F*3]=C*.12,r[F*3+1]=.002,r[F*3+2]=E*.12,r[L*3]=C*.15,r[L*3+1]=.002,r[L*3+2]=E*.15,s[F*3+1]=1,s[L*3+1]=1;let N=(R+1)%32*2,G=N+1,H=R*6;l[H]=F,l[H+1]=N,l[H+2]=L,l[H+3]=L,l[H+4]=N,l[H+5]=G}let u=e.createVertexArray();e.bindVertexArray(u);let m=(R,I,C)=>{let E=e.createBuffer();return e.bindBuffer(34962,E),e.bufferData(34962,R,35044),e.enableVertexAttribArray(I),e.vertexAttribPointer(I,C,5126,!1,0,0),E},o=m(r,0,3),b=m(s,1,3),S=m(y,2,2),w=e.createBuffer();e.bindBuffer(34963,w),e.bufferData(34963,l,35044),e.bindVertexArray(null);let g=ne(),x=new Float32Array(9);return x[0]=1,x[4]=1,x[8]=1,{name:"__xr_reticle__",nodeIndex:-1,visible:!1,transform:g,normalMatrix:x,primitives:[{vao:u,indexCount:l.length,indexType:5123,baseColor:[1,1,1,.95],metallic:0,roughness:.2,positions:r,indices:l,texture:null,metallicRoughnessTexture:null,normalTexture:null,occlusionTexture:null,normalScale:1,occlusionStrength:1,buffers:[o,b,S,w]}]}}function nt(e,t,n){let a=Math.cos(n),r=Math.sin(n);e.set(t),e[0]=a,e[1]=0,e[2]=-r,e[4]=0,e[5]=1,e[6]=0,e[8]=r,e[9]=0,e[10]=a}var rt={name:"webxr-suite",onConfigureXRSessionInit(e,t){let n=new Set(t.optionalFeatures||[]);n.add("hit-test"),n.add("light-estimation"),n.add("dom-overlay"),t.optionalFeatures=Array.from(n);let a=e?.querySelector?.('[slot="ar-overlay"]')||e;a&&(t.domOverlay={root:a},a.addEventListener("beforexrselect",r=>{r.preventDefault()}))},onXRFrame(e,t,n,a){if(!e||!t||!n||!a)return;let r=tt.get(t);if(!r){r={initialized:!0,hitTestSource:null,lightProbe:null,reticleMesh:Rt(e.gl),lastHitMatrix:null,hasPlaced:!1,rotationY:0,isDragging:!1,lastTouchAngle:null},tt.set(t,r),e.meshes.push(r.reticleMesh),typeof t.requestReferenceSpace=="function"&&t.requestReferenceSpace("viewer").then(o=>typeof t.requestHitTestSource=="function"?t.requestHitTestSource({space:o}):null).then(o=>{r&&o&&(r.hitTestSource=o)}).catch(()=>{}),typeof t.requestLightProbe=="function"&&t.requestLightProbe().then(o=>{r&&o&&(r.lightProbe=o)}).catch(()=>{});let s=()=>r?.lastHitMatrix&&nt(e.modelRootMatrix,r.lastHitMatrix,r.rotationY),y=o=>Math.atan2(o.touches[1].clientY-o.touches[0].clientY,o.touches[1].clientX-o.touches[0].clientX);t.addEventListener("select",()=>{r?.lastHitMatrix&&(r.hasPlaced=!0,s())});let l=o=>{r&&(o.touches.length===1&&r.hasPlaced?r.isDragging=!0:o.touches.length===2&&(r.isDragging=!1,r.lastTouchAngle=y(o)))},u=o=>{if(r){if(o.touches.length===1&&r.isDragging)s();else if(o.touches.length===2&&r.lastTouchAngle!==null){let b=y(o);r.rotationY+=b-r.lastTouchAngle,r.lastTouchAngle=b,s()}}},m=()=>{r&&(r.isDragging=!1,r.lastTouchAngle=null)};typeof window<"u"&&(window.addEventListener("touchstart",l,{passive:!0}),window.addEventListener("touchmove",u,{passive:!0}),window.addEventListener("touchend",m,{passive:!0})),t.addEventListener("end",()=>{if(r?.reticleMesh){let o=e.meshes.indexOf(r.reticleMesh);o!==-1&&e.meshes.splice(o,1)}e.modelRootMatrix=ne(),typeof window<"u"&&(window.removeEventListener("touchstart",l),window.removeEventListener("touchmove",u),window.removeEventListener("touchend",m))})}if(r.hitTestSource&&typeof n.getHitTestResults=="function"){let s=n.getHitTestResults(r.hitTestSource);if(s&&s.length>0){let y=s[0].getPose(a);if(y?.transform?.matrix){let l=y.transform.matrix;r.lastHitMatrix=l,r.reticleMesh.visible=!r.hasPlaced||r.isDragging,r.reticleMesh.transform.set(l),re(r.reticleMesh.normalMatrix,r.reticleMesh.transform),r.hasPlaced||nt(e.modelRootMatrix,l,r.rotationY)}}else r.reticleMesh.visible=!1}if(r.lightProbe&&typeof n.getLightEstimate=="function"){let s=n.getLightEstimate(r.lightProbe);if(s){let y=s.primaryLightDirection,l=s.primaryLightIntensity;if(y&&l&&Array.isArray(e.lights)){let u=e.lights.find(o=>o.type==="directional");u||(u={type:"directional",direction:[.5,1,.8],color:[1,1,1],intensity:1},e.lights.push(u)),u.direction=[y.x,y.y,y.z];let m=Math.max(l.x,l.y,l.z,.001);u.color=[l.x/m,l.y/m,l.z/m],u.intensity=m}s.sphericalHarmonicsCoefficients&&Me(e.gl,s.sphericalHarmonicsCoefficients)}}}};Q(et);Q(He);Q(Ue);Q(Ze);Q(rt);Q(Ke);export{pe as InteractivityVM,et as contactShadowPlugin,Ue as environmentMapPlugin,ct as getEnvironmentSH,Ie as getInteractivityVM,He as hotspotPlugin,Ke as interactivityPlugin,Ze as materialsPlugin,me as parseSafeGltfPointer,xt as registerMaterialShader,Ye as sendInteractivityEvent,Me as setEnvironmentSH,rt as webxrPlugin};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
"use strict";var ThreeLiveExtras=(()=>{var Te=Object.defineProperty;var lt=Object.getOwnPropertyDescriptor;var ut=Object.getOwnPropertyNames;var ft=Object.prototype.hasOwnProperty;var mt=(e,t)=>{for(var n in t)Te(e,n,{get:t[n],enumerable:!0})},dt=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ut(t))!ft.call(e,r)&&r!==n&&Te(e,r,{get:()=>t[r],enumerable:!(a=lt(t,r))||a.enumerable});return e};var pt=e=>dt(Te({},"__esModule",{value:!0}),e);var Lt={};mt(Lt,{InteractivityVM:()=>ae,contactShadowPlugin:()=>ke,environmentMapPlugin:()=>we,getEnvironmentSH:()=>$e,getInteractivityVM:()=>he,hotspotPlugin:()=>_e,interactivityPlugin:()=>Ce,materialsPlugin:()=>Ne,parseSafeGltfPointer:()=>oe,registerMaterialShader:()=>nt,sendInteractivityEvent:()=>Le,setEnvironmentSH:()=>fe,webxrPlugin:()=>De});var ue="__THREE_LIVE_REGISTRY__";function Me(){let e=typeof globalThis<"u"?globalThis:{};if(!e[ue]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,ue,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[ue]=t}}return e[ue]}var Vt=Me().plugins;function Q(e){let t=Me().plugins;t.some(n=>n.name===e.name)||t.push(e)}function Be(){return Me().plugins}function ne(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function bt(e,t,n){let a=t[0],r=t[1],s=t[2],y=t[3],l=t[4],u=t[5],m=t[6],o=t[7],b=t[8],S=t[9],w=t[10],g=t[11],x=t[12],R=t[13],I=t[14],C=t[15],E=n[0],F=n[1],L=n[2],N=n[3];return e[0]=E*a+F*l+L*b+N*x,e[1]=E*r+F*u+L*S+N*R,e[2]=E*s+F*m+L*w+N*I,e[3]=E*y+F*o+L*g+N*C,E=n[4],F=n[5],L=n[6],N=n[7],e[4]=E*a+F*l+L*b+N*x,e[5]=E*r+F*u+L*S+N*R,e[6]=E*s+F*m+L*w+N*I,e[7]=E*y+F*o+L*g+N*C,E=n[8],F=n[9],L=n[10],N=n[11],e[8]=E*a+F*l+L*b+N*x,e[9]=E*r+F*u+L*S+N*R,e[10]=E*s+F*m+L*w+N*I,e[11]=E*y+F*o+L*g+N*C,E=n[12],F=n[13],L=n[14],N=n[15],e[12]=E*a+F*l+L*b+N*x,e[13]=E*r+F*u+L*S+N*R,e[14]=E*s+F*m+L*w+N*I,e[15]=E*y+F*o+L*g+N*C,e}function yt(e,t,n,a){let r=t[0],s=t[1],y=t[2],l=t[3],u=r+r,m=s+s,o=y+y,b=r*u,S=r*m,w=r*o,g=s*m,x=s*o,R=y*o,I=l*u,C=l*m,E=l*o,F=a[0],L=a[1],N=a[2];return e[0]=(1-(g+R))*F,e[1]=(S+E)*F,e[2]=(w-C)*F,e[3]=0,e[4]=(S-E)*L,e[5]=(1-(b+R))*L,e[6]=(x+I)*L,e[7]=0,e[8]=(w+C)*N,e[9]=(x-I)*N,e[10]=(1-(b+g))*N,e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function re(e,t){let n=t[0],a=t[1],r=t[2],s=t[4],y=t[5],l=t[6],u=t[8],m=t[9],o=t[10],b=o*y-l*m,S=-o*s+l*u,w=m*s-y*u,g=n*b+a*S+r*w;return g&&(g=1/g,e[0]=b*g,e[1]=(-o*a+r*m)*g,e[2]=(l*a-r*y)*g,e[3]=S*g,e[4]=(o*n-r*u)*g,e[5]=(-l*n+r*s)*g,e[6]=w*g,e[7]=(-m*n+a*u)*g,e[8]=(y*n-a*s)*g),e}function Oe(e,t){let n=t[0],a=t[1],r=t[2],s=t[3],y=t[4],l=t[5],u=t[6],m=t[7],o=t[8],b=t[9],S=t[10],w=t[11],g=t[12],x=t[13],R=t[14],I=t[15],C=n*l-a*y,E=n*u-r*y,F=n*m-s*y,L=a*u-r*l,N=a*m-s*l,G=r*m-s*u,H=o*x-b*g,O=o*R-S*g,U=o*I-w*g,K=b*R-S*x,q=b*I-w*x,Z=S*I-w*R,z=C*Z-E*q+F*K+L*U-N*O+G*H;return z?(z=1/z,e[0]=(l*Z-u*q+m*K)*z,e[1]=(r*q-a*Z-s*K)*z,e[2]=(x*G-R*N+I*L)*z,e[3]=(S*N-b*G-w*L)*z,e[4]=(u*U-y*Z-m*O)*z,e[5]=(n*Z-r*U+s*O)*z,e[6]=(R*F-g*G-I*E)*z,e[7]=(o*G-S*F+w*E)*z,e[8]=(y*q-l*U+m*H)*z,e[9]=(a*U-n*q-s*H)*z,e[10]=(g*N-x*F+I*C)*z,e[11]=(b*F-o*N-w*C)*z,e[12]=(l*O-y*K-u*H)*z,e[13]=(n*K-a*O+r*H)*z,e[14]=(x*E-g*L-R*C)*z,e[15]=(o*L-b*E+S*C)*z,e):null}function Re(e,t){let n=Array.isArray(e?.nodes)?e.nodes.length:0,a=[];for(let o=0;o<n;o++)a.push(ne());if(n===0)return a;let r=new Set;for(let o of e.nodes)if(Array.isArray(o.children))for(let b of o.children)r.add(b);let s=new Set,y=128,l=(o,b,S=0)=>{if(S>y||o<0||o>=n||s.has(o))return;s.add(o);let w=e.nodes[o];if(!w)return;let g=ne();if(t&&t[o])g.set(t[o]);else if(w.matrix&&w.matrix.length===16)g.set(w.matrix);else{let R=w.translation||[0,0,0],I=w.rotation||[0,0,0,1],C=w.scale||[1,1,1];yt(g,I,R,C)}let x=a[o];if(b?bt(x,b,g):x.set(g),Array.isArray(w.children))for(let R of w.children)typeof R=="number"&&l(R,x,S+1)},u=[],m=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(m&&Array.isArray(m.nodes))u.push(...m.nodes);else for(let o=0;o<n;o++)r.has(o)||u.push(o);for(let o of u)l(o,null);for(let o=0;o<n;o++)!r.has(o)&&!u.includes(o)&&l(o,null);return a}var Se=new WeakMap;function fe(e,t){let n=t instanceof Float32Array?t:new Float32Array(t);Se.set(e,n)}function $e(e){return Se.get(e)}async function ht(e,t){if(!t)return null;let n;if(typeof t=="string")if(typeof fetch<"u"&&typeof createImageBitmap=="function"){let s=await(await fetch(t)).blob();n=await createImageBitmap(s)}else if(typeof Image<"u")n=await new Promise((r,s)=>{let y=new Image;y.crossOrigin="anonymous",y.onload=()=>r(y),y.onerror=s,y.src=t});else return null;else n=t;let a=e.createTexture();return e.bindTexture(3553,a),e.texImage2D(3553,0,6408,6408,5121,n),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9987),e.texParameteri(3553,10240,9729),e.generateMipmap(3553),a}var We=new WeakMap,Ge=new Float32Array(16);async function Xe(e,t,n){let a=n?await ht(e.gl,n):null;e[t]&&e.gl.deleteTexture(e[t]),e[t]=a}var we={name:"environment-map",setEnvironmentImage(e,t){return Xe(e,"environmentTexture",t)},setSkyboxImage(e,t){return Xe(e,"skyboxTexture",t)},onBeforeDrawScene(e,t,n,a,r){if(!e.skyboxTexture||typeof t.createProgram!="function")return;let s=We.get(t);if(!s){let b=(g,x)=>{let R=t.createShader(g);return t.shaderSource(R,x),t.compileShader(R),R},S=t.createProgram();t.attachShader(S,b(35633,`#version 300 es
|
|
18
|
+
out vec2 vNDC;void main(){vec2 p=vec2((gl_VertexID<<1)&2,gl_VertexID&2);vNDC=p*2.-1.;gl_Position=vec4(vNDC,.999999,1.);}`)),t.attachShader(S,b(35632,`#version 300 es
|
|
19
|
+
precision highp float;in vec2 vNDC;uniform mat4 uInvVP;uniform vec3 uCameraPos;uniform sampler2D uSkyboxMap;uniform float uExposure;out vec4 fragColor;vec2 eqUV(vec3 d){return vec2(atan(d.x,d.z)/6.2831853+.5,asin(clamp(d.y,-1.,1.))/3.1415926+.5);}void main(){vec4 fp=uInvVP*vec4(vNDC,1.,1.);vec3 dir=normalize(fp.xyz/fp.w-uCameraPos);fragColor=vec4(pow(texture(uSkyboxMap,eqUV(dir)).rgb*uExposure,vec3(1./2.2)),1.);}`)),t.linkProgram(S);let w=typeof t.createVertexArray=="function"?t.createVertexArray():null;s={program:S,vao:w},We.set(t,s)}let y=Oe(Ge,n)||Ge;t.depthMask(!1),t.useProgram(s.program),s.vao&&t.bindVertexArray(s.vao),t.activeTexture(33984),t.bindTexture(3553,e.skyboxTexture);let l=t.getUniformLocation(s.program,"uSkyboxMap");l&&t.uniform1i(l,0);let u=t.getUniformLocation(s.program,"uInvVP");u&&t.uniformMatrix4fv(u,!1,y);let m=t.getUniformLocation(s.program,"uCameraPos");m&&t.uniform3f(m,a[0],a[1],a[2]);let o=t.getUniformLocation(s.program,"uExposure");o&&t.uniform1f(o,e.exposure??1),t.drawArrays(4,0,3),t.depthMask(!0)},onResolveShader(e,t,n,a){if(a.includes("evalSHIrradiance"))return null;let r=a.replace("out vec4 fragColor;",`uniform vec3 uSH[9];
|
|
20
|
+
uniform int uHasSH;
|
|
21
|
+
out vec4 fragColor;`).replace("void main(){",`vec3 integrateBRDFApprox(vec3 f0,float r,float NoV){vec4 c0=vec4(-1.,-.0275,-.572,.022),c1=vec4(1.,.0425,1.04,-.04),rv=r*c0+c1;float a=min(rv.x*rv.x,exp2(-9.28*NoV))*rv.x+rv.y;vec2 ab=vec2(-1.04,1.04)*a+rv.zw;return f0*ab.x+vec3(ab.y);}
|
|
22
|
+
vec3 evalSHIrradiance(vec3 n){return max(vec3(0.),uSH[0]+uSH[1]*n.y+uSH[2]*n.z+uSH[3]*n.x+uSH[4]*(n.x*n.y)+uSH[5]*(n.y*n.z)+uSH[6]*(3.*n.z*n.z-1.)+uSH[7]*(n.x*n.z)+uSH[8]*(n.x*n.x-n.y*n.y));}
|
|
23
|
+
void main(){`);return r=r.replace(`if(uHasEnvironmentMap==1){
|
|
24
|
+
specularIBL=texture(uEnvironmentMap,equirectangularUV(R)).rgb*(F*brdf.x+brdf.y);
|
|
25
|
+
envDiffuse=texture(uEnvironmentMap,equirectangularUV(N)).rgb;
|
|
26
|
+
}`,`if(uHasEnvironmentMap==1){
|
|
27
|
+
specularIBL=textureLod(uEnvironmentMap,equirectangularUV(R),clamp(roughness*6.0,0.0,6.0)).rgb*integrateBRDFApprox(F,roughness,NoV);
|
|
28
|
+
envDiffuse=uHasSH==1?evalSHIrradiance(N):textureLod(uEnvironmentMap,equirectangularUV(N),5.0).rgb;
|
|
29
|
+
}else if(uHasSH==1){
|
|
30
|
+
specularIBL=getStudioRadiance(R,roughness)*integrateBRDFApprox(F,roughness,NoV);
|
|
31
|
+
envDiffuse=evalSHIrradiance(N);
|
|
32
|
+
}`),{vs:n,fs:r}},onBeforeDrawPrimitive(e,t,n,a,r,s){let y=Se.get(e),l=e.getUniformLocation(t,"uHasSH");if(y&&y.length>=27){l&&e.uniform1i(l,1);let u=e.getUniformLocation(t,"uSH");u&&e.uniform3fv(u,y)}else l&&e.uniform1i(l,0)},onAttributeChanged(e,t,n,a){t==="environment-image"&&e.viewer?this.setEnvironmentImage?.(e.viewer,a):t==="skybox-image"&&e.viewer&&this.setSkyboxImage?.(e.viewer,a)}};var Ee=new WeakMap;function Ie(e,t){let n=t||e.viewer;if(!n||typeof n.projectPointToScreen!="function")return;let a=e.mockHotspots||e.querySelectorAll('[slot^="hotspot-"], [data-position]');for(let r=0;r<a.length;r++){let s=a[r],y=s.getAttribute("data-position");if(!y)continue;let l=y.trim().split(/\s+/).map(b=>parseFloat(b.replace(/m$/,"")));if(l.length<3||l.some(isNaN))continue;let u=s.getAttribute("data-normal"),m;if(u){let b=u.trim().split(/\s+/).map(S=>parseFloat(S));b.length>=3&&!b.some(isNaN)&&(m=[b[0],b[1],b[2]])}let o=n.projectPointToScreen([l[0],l[1],l[2]],m);s.style.position="absolute",s.style.left="0",s.style.top="0",s.style.transform=`translate(-50%, -50%) translate3d(${o.x}px, ${o.y}px, 0)`,s.style.zIndex="3",o.visible?(s.style.opacity="1",s.style.pointerEvents="auto",s.removeAttribute("data-occluded")):(s.style.opacity="0",s.style.pointerEvents="none",s.setAttribute("data-occluded",""))}}var _e={name:"hotspots",updateHotspotsForElement:Ie,onElementConnected(e){if(typeof MutationObserver>"u"||!e)return;let t=new MutationObserver(()=>{Ie(e)});t.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-position","data-normal"]}),Ee.set(e,t)},onCameraChange(e,t){t&&Ie(t,e)},onElementDisconnected(e){let t=Ee.get(e);t&&(t.disconnect(),Ee.delete(e))}};function me(e,t,n,a){let r=typeof e=="number"&&Number.isFinite(e)?e:a;return Math.max(t,Math.min(n,r))}function gt(e){return Array.isArray(e)&&e.length>=3&&Number.isFinite(e[0])&&Number.isFinite(e[1])&&Number.isFinite(e[2])}function xt(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function je(e){let t=xt(e);if(!t)return null;let n=t.target;return{target:gt(n)?[n[0],n[1],n[2]]:typeof n=="string"&&n.length>0&&n.length<=256?n:[0,0,0],radius:me(t.radius,.01,50,.5),speed:me(t.speed,-20,20,.5),height:me(t.height,-10,10,0),phase:me(t.phase,-1e6,1e6,0),faceCenter:t.faceCenter===!0}}function qe(e,t,n,a){let r=t[0],s=t[1],y=t[2],l=t[3],u=n[0],m=n[1],o=n[2],b=n[3],S=r*u+s*m+y*o+l*b;if(S<0&&(u=-u,m=-m,o=-o,b=-b,S=-S),Math.abs(S)>=1)return e[0]=r,e[1]=s,e[2]=y,e[3]=l,e;let w=Math.acos(S),g=Math.sqrt(1-S*S);if(Math.abs(g)<.001)return e[0]=.5*(r+u),e[1]=.5*(s+m),e[2]=.5*(y+o),e[3]=.5*(l+b),e;let x=Math.sin((1-a)*w)/g,R=Math.sin(a*w)/g;return e[0]=r*x+u*R,e[1]=s*x+m*R,e[2]=y*x+o*R,e[3]=l*x+b*R,e}var Ye=1024,Fe=256,de=2048,vt=128,At=64,Tt=16,Mt=1e4,Rt=8,Y=new Set(["__proto__","constructor","prototype"]),Ke={neg:e=>-e,abs:Math.abs,sign:Math.sign,floor:Math.floor,ceil:Math.ceil,round:Math.round,trunc:Math.trunc,fract:e=>e-Math.floor(e),sqrt:e=>Math.sqrt(Math.max(0,e)),cbrt:Math.cbrt,exp:Math.exp,log:e=>e>0?Math.log(e):0,sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:e=>Math.asin(Math.max(-1,Math.min(1,e))),acos:e=>Math.acos(Math.max(-1,Math.min(1,e))),atan:Math.atan,rad:e=>e*Math.PI/180,deg:e=>e*180/Math.PI,saturate:e=>Math.max(0,Math.min(1,e))},Ze={add:(e,t)=>e+t,sub:(e,t)=>e-t,mul:(e,t)=>e*t,div:(e,t)=>Math.abs(t)<1e-12?0:e/t,rem:(e,t)=>Math.abs(t)<1e-12?0:e%t,mod:(e,t)=>Math.abs(t)<1e-12?0:e%t,min:Math.min,max:Math.max,pow:Math.pow,atan2:Math.atan2},pe={translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]},be=(e,t)=>e!==null&&typeof e=="object"&&!Y.has(t)&&Object.prototype.hasOwnProperty.call(e,t),W=e=>Array.isArray(e)?[...e]:e,tt=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)&&be(e,"value")?e.value:e,D=(e,t)=>be(e.configuration,t)?tt(e.configuration[t]):void 0,T=(e,t=0)=>{let n=Number(e);return Number.isFinite(n)?n:t},J=e=>Math.max(0,Math.min(1,e)),X=e=>typeof e=="boolean"?e:typeof e=="number"?e!==0&&!Number.isNaN(e):typeof e=="string"?e.length>0&&e!=="false":!!e;function oe(e){if(typeof e!="string"||!e.startsWith("/"))return null;let t=[];for(let n of e.slice(1).split("/")){let a=n.replace(/~1/g,"/").replace(/~0/g,"~");if(!a||Y.has(a)||Y.has(n))return null;t.push(a)}return{segments:t}}var te=(e,t)=>{if(e===void 0||!/^\d+$/.test(e))return-1;let n=Number(e);return Number.isSafeInteger(n)&&n>=0&&n<t?n:-1},Qe=e=>{let t=T(e[0]),n=T(e[1]),a=T(e[2]),r=T(e[3],1),s=Math.hypot(t,n,a,r);return s>1e-8?[t/s,n/s,a/s,r/s]:[0,0,0,1]},Je=(e,t,n,a)=>{if(typeof e=="number"&&typeof t=="number")return e+(t-e)*n;if(Array.isArray(e)&&Array.isArray(t)){if(a&&e.length===4&&t.length===4){let r=[0,0,0,1];return qe(r,Qe(e),Qe(t),n),r}return e.slice(0,t.length).map((r,s)=>r+(t[s]-r)*n)}return n>=.5?t:e},Pe=(e,t,n)=>Array.isArray(e)&&Array.isArray(t)?e.slice(0,t.length).map((a,r)=>n(T(a),T(t[r]))):Array.isArray(e)?e.map(a=>n(T(a),T(t))):Array.isArray(t)?t.map(a=>n(T(e),T(a))):n(T(e),T(t)),St=(e,t)=>Array.isArray(e)?e.map(n=>t(T(n))):t(T(e)),et=(e,t)=>Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((n,a)=>Math.abs(n-t[a])<=1e-6):e===t,ae=class{constructor(t,n,a){let r=Array.isArray(a.nodes)?a.nodes:[];if(r.length>Ye)throw new Error(`SecurityError: Exceeds MAX_GRAPH_NODES (${Ye})`);let s=Array.isArray(a.variables)?a.variables:[];if(s.length>Fe)throw new Error(`SecurityError: Exceeds MAX_VARIABLES (${Fe})`);let y=Array.isArray(a.declarations)?a.declarations:[],l=Array.isArray(a.events)?a.events:[],u=new Map,m=new Map,o=new Map,b=new Map,S=new Map,w=new Map,g=[],x=[],R=new Map,I=1,C=0,E=0,F=0,L=0,N=!1,G=!1,H=!1;s.forEach((d,p)=>{if(!d||typeof d!="object")return;let v=W(tt(d.value));u.set(p,v);let A=d.id??d.name;typeof A=="string"&&A&&!Y.has(A)&&u.set(A,v)}),(n?.nodes||[]).forEach((d,p)=>{for(let v of d?.children||[])typeof v=="number"&&R.set(v,p)});let O=d=>d.op||typeof d.declaration=="number"&&y[d.declaration]?.op||"",U=(d,p,v)=>{if(Y.has(p))return;let A=m.get(d);A||m.set(d,A=Object.create(null)),A[p]=v},K=(d,p)=>{if(typeof d!="number"&&typeof d!="string"||typeof d=="string"&&Y.has(d)||!u.has(d)&&u.size>=Fe*2)return;let v=W(p);if(u.set(d,v),typeof d=="number"){let A=s[d]?.id??s[d]?.name;typeof A=="string"&&!Y.has(A)&&u.set(A,v)}},q=d=>typeof d=="number"?l[d]?.id??String(d):typeof d=="string"?/^\d+$/.test(d)&&l[Number(d)]?.id?l[Number(d)].id:d:"",Z=(d,p)=>{for(let v=d,A=0;v!==void 0&&v>=0&&A<128;v=R.get(v),A++)if(v===p)return!0;return!1},z=d=>{for(let p=g.length-1;p>=0;p--)g[p].key===d&&g.splice(p,1)},Ue=d=>{z(d.key),g.length>=vt&&g.shift(),g.push(d)},xe=d=>{let p=oe(d)?.segments;if(p){if(p[0]==="nodes"&&Array.isArray(n?.nodes)){let v=n.nodes[te(p[1],n.nodes.length)];if(!v)return;let A=p[2];if(A in pe){let f=pe[A],i=v[A]||f;return f.map((c,h)=>T(i[h],c))}if(A==="weights"){let f=Array.isArray(v.weights)?v.weights:[0],i=p.length===4?te(p[3],64):-2;return i===-2?f.map(c=>T(c)):i>=0?T(f[i]):void 0}if(A==="visible"||A==="extensions"&&p[3]==="KHR_node_visibility"&&p[4]==="visible")return v.extensions?.KHR_node_visibility?.visible??v.visible??!0}else if(p[0]==="materials"&&Array.isArray(n?.materials)){let v=n.materials[te(p[1],n.materials.length)];if(!v)return;let A=v.pbrMetallicRoughness||{};if(p[2]==="pbrMetallicRoughness"){if(p[3]==="baseColorFactor"){let f=A.baseColorFactor||[1,1,1,1];return[T(f[0],1),T(f[1],1),T(f[2],1),T(f[3],1)]}if(p[3]==="metallicFactor"||p[3]==="roughnessFactor")return T(A[p[3]],1)}if(p[2]==="emissiveFactor"){let f=v.emissiveFactor||[0,0,0];return[T(f[0]),T(f[1]),T(f[2])]}if(p[2]==="alphaCutoff")return T(v.alphaCutoff,.5)}}},se=(d,p)=>{let v=oe(d)?.segments;if(!v)return!1;if(v[0]==="nodes"&&Array.isArray(n?.nodes)){let A=te(v[1],n.nodes.length),f=n.nodes[A];if(!f)return!1;let i=v[2];if(i in pe&&Array.isArray(p)){let c=pe[i];if(p.length<c.length)return!1;let h=c.map((V,k)=>T(p[k],V));if(i==="rotation"){let V=Math.hypot(...h);h=V>1e-8?h.map(k=>k/V):[0,0,0,1]}f[i]=h,delete f.matrix;let P=t?.initialNodeTransforms?.[A];return P&&(P[i[0]]=[...h]),N=!0,!0}if(i==="weights"){Array.isArray(f.weights)||(f.weights=[]);let c=(h,P)=>{for(let V of t?.meshes||[])if(V.nodeIndex===A)for(let k of V.primitives||[])k.pluginData?.morph?.weights&&(k.pluginData.morph.weights[h]=P)};if(v.length===4){let h=te(v[3],64);if(h<0)return!1;c(h,f.weights[h]=T(p))}else if(Array.isArray(p))f.weights=p.slice(0,64).map(h=>T(h)),f.weights.forEach((h,P)=>c(P,h));else return!1;return H=!0,!0}if(i==="visible"||i==="extensions"&&v[3]==="KHR_node_visibility"&&v[4]==="visible"){let c=X(p);return f.visible=c,(!f.extensions||typeof f.extensions!="object")&&(f.extensions={}),f.extensions.KHR_node_visibility={visible:c},G=!0,!0}}else if(v[0]==="materials"&&Array.isArray(n?.materials)){let A=te(v[1],n.materials.length),f=n.materials[A];if(!f)return!1;let i=f.pbrMetallicRoughness||(f.pbrMetallicRoughness={}),c=h=>{for(let P of t?.meshes||[])for(let V of P.primitives||[])(V.materialIndex??0)===A&&h(V)};if(v[2]==="pbrMetallicRoughness"){if(v[3]==="baseColorFactor"&&Array.isArray(p)&&p.length>=3){let h=[J(T(p[0],1)),J(T(p[1],1)),J(T(p[2],1)),p[3]!==void 0?J(T(p[3],1)):i.baseColorFactor?.[3]??1];return i.baseColorFactor=h,c(P=>P.baseColor=[...h]),H=!0}if(v[3]==="metallicFactor"||v[3]==="roughnessFactor"){let h=v[3]==="metallicFactor",P=J(T(p,h?0:.5));return i[v[3]]=P,c(V=>V[h?"metallic":"roughness"]=P),H=!0}}if(v[2]==="emissiveFactor"&&Array.isArray(p)&&p.length>=3)return f.emissiveFactor=[0,1,2].map(h=>Math.max(0,T(p[h]))),H=!0;if(v[2]==="alphaCutoff")return f.alphaCutoff=J(T(p,.5)),H=!0}return!1},ve=(d,p,v=new Set)=>{let A=D(p,"pointer");if(typeof A!="string"||!A.startsWith("/"))return null;let f=A.replace(/\{([a-zA-Z0-9_]+)\}/g,(i,c)=>{let h=Math.trunc(Number(ce(d,c,void 0,v)??D(p,c)));return Number.isSafeInteger(h)&&h>=0?String(h):"-1"});return oe(f)?f:null},ce=(d,p,v,A)=>{let f=r[d]?.values;if(!be(f,p))return v;let i=f[p];if(i==null)return v;if(typeof i!="object"||Array.isArray(i))return W(i);let c=i;return typeof c.node=="number"?st(c.node,c.socket||"value",A):be(c,"value")?W(c.value):v},st=(d,p,v)=>{if(d<0||d>=r.length||v.has(d)||v.size>128||++F>Mt)return;let A=r[d],f=O(A);if(/^(event\/|pointer\/on|scene\/on|flow\/)/.test(f))return W(m.get(d)?.[p]);v.add(d);try{let i=(c,h=0)=>ce(d,c,h,v);if(f==="variable/get"){let c=D(A,"variable")??D(A,"id");return typeof c=="number"||typeof c=="string"?W(u.get(c)):void 0}if(f==="pointer/get"){let c=ve(d,A,v);return c?xe(c):void 0}if(f.startsWith("math/")){let c=f.slice(5);if(c in Ke)return St(i("a"),Ke[c]);if(c in Ze){let h=/^(mul|div|rem|mod|pow)$/.test(c)?1:0;return Pe(i("a",c==="mul"?1:0),i("b",h),Ze[c])}if(c==="pi")return Math.PI;if(c==="e")return Math.E;if(c==="random")return Math.random();if(c==="clamp")return Pe(Pe(i("a"),i("b",i("min",0)),Math.max),i("c",i("max",1)),Math.min);if(c==="mix"||c==="quatSlerp")return Je(i("a",0),i("b",1),T(i("c",i("t",.5)),.5),c==="quatSlerp");if(c==="dot"){let h=i("a"),P=i("b");return Array.isArray(h)&&Array.isArray(P)?h.reduce((V,k,M)=>V+(k||0)*(P[M]||0),0):T(h)*T(P)}if(c==="cross"){let h=i("a",[0,0,0]),P=i("b",[0,0,0]);return Array.isArray(h)&&Array.isArray(P)?[(h[1]||0)*(P[2]||0)-(h[2]||0)*(P[1]||0),(h[2]||0)*(P[0]||0)-(h[0]||0)*(P[2]||0),(h[0]||0)*(P[1]||0)-(h[1]||0)*(P[0]||0)]:[0,0,0]}if(c==="length"){let h=i("a");return Array.isArray(h)?Math.hypot(...h):Math.abs(T(h))}if(c==="distance"){let h=i("a"),P=i("b");return Array.isArray(h)&&Array.isArray(P)?Math.hypot(...h.map((V,k)=>(V||0)-(P[k]||0))):Math.abs(T(h)-T(P))}if(c==="normalize"){let h=i("a");if(!Array.isArray(h))return T(h)>=0?1:-1;let P=Math.hypot(...h);return P>1e-8?h.map(V=>V/P):h.map(()=>0)}if(c.startsWith("combine"))return["a","b","c","d"].slice(0,Number(c[7])||2).map(h=>T(i(h)));if(c.startsWith("extract")){let h=i("a");return Array.isArray(h)?h[p==="0"||p==="x"?0:p==="1"||p==="y"?1:p==="2"||p==="z"?2:3]??0:0}if(c==="eq")return et(i("a"),i("b"));if(c==="ne")return!et(i("a"),i("b"));if(c==="lt")return T(i("a"))<T(i("b"));if(c==="le")return T(i("a"))<=T(i("b"));if(c==="gt")return T(i("a"))>T(i("b"));if(c==="ge")return T(i("a"))>=T(i("b"));if(c==="isNaN")return Number.isNaN(Number(i("a")));if(c==="isInf"){let h=Number(i("a"));return!Number.isFinite(h)&&!Number.isNaN(h)}return c==="and"?X(i("a",!1))&&X(i("b",!1)):c==="or"?X(i("a",!1))||X(i("b",!1)):c==="xor"?X(i("a",!1))!==X(i("b",!1)):c==="not"?!X(i("a",!1)):c==="select"?W(X(i("condition",!1))?i("a"):i("b")):void 0}return f==="type/boolToInt"||f==="type/boolToFloat"?X(i("a",!1))?1:0:f==="type/intToBool"||f==="type/floatToBool"?T(i("a",0))!==0:f==="type/intToFloat"?T(i("a",0)):f==="type/floatToInt"?Math.trunc(T(i("a",0))):void 0}finally{v.delete(d)}},le=()=>{if(N){N=!1,H=!0;let d=Re(n);if(t){t.worldMatrices=d;for(let p of t.meshes||[])p.nodeIndex>=0&&p.nodeIndex<d.length&&(p.transform.set(d[p.nodeIndex]),re(p.normalMatrix,p.transform))}}if(G){G=!1,H=!0;let d=n?.nodes;if(Array.isArray(t?.meshes)&&Array.isArray(d))for(let p of t.meshes){let v=!0;for(let A=p.nodeIndex,f=0;A!==void 0&&A>=0&&f<128;A=R.get(A),f++){let i=d[A];if(i?.visible===!1||i?.extensions?.KHR_node_visibility?.visible===!1){v=!1;break}}p.visible=v}}H&&(H=!1,t?.render?.())},ee=(d,p={steps:0})=>{if(!d||typeof d.node!="number")return;p.steps===0&&(F=0);let v=[d],A=f=>{v.length+p.steps<de&&v.push(f)};for(;v.length>0&&p.steps<de;){p.steps++;let f=v.shift();if(!f||f.node<0||f.node>=r.length)continue;let i=f.node,c=r[i];if(!c)continue;let h=f.socket||"in",P=O(c),V=(M,_=void 0)=>ce(i,M,_,new Set),k=(M="out")=>{let _=c.flows?.[M];_&&A(_)};switch(P){case"flow/branch":k(X(V("condition",!1))?"true":"false");break;case"flow/sequence":for(let M of Object.keys(c.flows||{}).sort((_,B)=>Number(_)-Number(B)||_.localeCompare(B)))k(M);break;case"flow/switch":{let M=c.flows?.[String(V("selection",V("value",0)))]??c.flows?.default;M&&A(M);break}case"flow/for":{let M=Math.trunc(T(V("startIndex",0))),_=Math.trunc(T(V("endIndex",0))),B=Math.max(1,Math.trunc(T(V("step",1),1))),$=c.flows?.body;if($&&_>M&&L<Rt){let ct=Math.min(Math.ceil((_-M)/B),de);L++;try{for(let Ae=0;Ae<ct&&p.steps<de;Ae++)U(i,"index",M+Ae*B),ee($,p)}finally{L--}}let ze=c.flows?.completed??c.flows?.out;ze&&A(ze);break}case"flow/doN":{let M=h==="reset"?0:(o.get(i)||0)+1;if(o.set(i,M),U(i,"currentCount",M),U(i,"count",M),h!=="reset"){let _=Math.trunc(T(V("n",D(c,"stopIterations")??D(c,"n")??1),1));M<=_&&k()}break}case"flow/multiGate":{if(h==="reset"){w.set(i,0);break}let M=Object.keys(c.flows||{}).sort();if(!M.length)break;let _=D(c,"isRandom")?Math.floor(Math.random()*M.length):w.get(i)||0;_<M.length&&(k(M[_]),w.set(i,D(c,"isLoop")!==!1?(_+1)%M.length:_+1));break}case"flow/waitAll":{if(h==="reset"){b.delete(i);break}let M=b.get(i);M||b.set(i,M=new Set),M.add(h),M.size>=Math.max(1,Math.trunc(Number(D(c,"inputFlows")??2)||2))&&(M.clear(),k("out"),k("completed"));break}case"flow/throttle":{if(h==="reset"){S.delete(i);break}let M=Math.max(0,T(V("duration",0))),_=S.get(i);_===void 0||C-_>=M?(S.set(i,C),U(i,"lastRemainingTime",0),k()):U(i,"lastRemainingTime",Math.max(0,M-(C-_)));break}case"flow/delay":case"flow/setDelay":{if(h==="cancel"){for(let $=x.length-1;$>=0;$--)x[$].nodeIdx===i&&x.splice($,1);U(i,"lastDelayIndex",-1);break}let M=Math.max(0,T(V("duration",D(c,"duration")??0))),_=c.flows?.done??c.flows?.out;if(M<=0){U(i,"lastDelayIndex",-1),_&&A(_);break}x.length>=At&&x.shift();let B=I++;U(i,"lastDelayIndex",B),x.push({id:B,nodeIdx:i,rem:M,done:_}),P==="flow/setDelay"&&c.flows?.out&&c.flows?.done&&k("out");break}case"flow/cancelDelay":{let M=Math.trunc(T(V("delayIndex",-1),-1));if(M<0)x.length=0;else for(let _=x.length-1;_>=0;_--)x[_].id===M&&x.splice(_,1);k();break}case"variable/set":K(D(c,"variable")??D(c,"id"),V("value")),k();break;case"variable/interpolate":{let M=D(c,"variable")??D(c,"id"),_=V("value",V("target")),B=Math.max(0,T(V("duration",D(c,"duration")??.3),.3));M!==void 0&&_!==void 0&&Ue({key:`var:${String(M)}`,varKey:M,from:W(V("from")??u.get(M)??0),to:W(_),dur:B,elapsed:0,quat:!1,linear:D(c,"easing")==="linear",done:c.flows?.done}),k();break}case"pointer/set":{let M=ve(i,c),_=V("value");M&&_!==void 0&&(z(`ptr:${M}`),se(M,_)),k();break}case"pointer/interpolate":{let M=ve(i,c),_=V("value",V("target")),B=Math.max(0,T(V("duration",D(c,"duration")??.3),.3));if(M&&_!==void 0){let $=V("from")??xe(M);$!==void 0&&(B<=0?(se(M,_),k("done")):Ue({key:`ptr:${M}`,ptr:M,from:W($),to:W(_),dur:B,elapsed:0,quat:M.endsWith("/rotation"),linear:D(c,"easing")==="linear",done:c.flows?.done}))}k();break}case"animation/start":{let M=V("animation")??D(c,"animation")??D(c,"clipName"),_=typeof M=="number"?t?.animations?.[M]?.name??n?.animations?.[M]?.name:typeof M=="string"?M:void 0;t?.playAnimation?.(_),H=!0,k();break}case"animation/stop":case"animation/resetAt":t?.pauseAnimation?.(),P==="animation/resetAt"&&t?.evaluateAnimation?.(T(V("time",0))),H=!0,k();break;case"event/send":case"customEvent/send":{let M=q(D(c,"event")??D(c,"id")),_={};for(let B of Object.keys(c.values||{}))Y.has(B)||(_[B]=V(B));M&&(typeof CustomEvent<"u"&&typeof t?.container?.dispatchEvent=="function"&&t.container.dispatchEvent(new CustomEvent("interactivityEvent",{bubbles:!0,composed:!0,detail:{id:M,values:_}})),He(M,_,p)),k();break}default:k();break}}};this.readScenePointer=xe,this.writeScenePointer=se,this.fireOnStart=()=>{r.forEach(d=>{O(d)==="event/onStart"&&ee(d.flows?.out)}),le()},this.fireOnSelect=d=>{if(!d)return;let p=typeof d.meshIndex=="number"?d.meshIndex:-1,v=typeof d.nodeIndex=="number"?d.nodeIndex:t?.meshes?.[p]?.nodeIndex??-1;r.forEach((A,f)=>{if(!/^(pointer|event|scene)\/onSelect$/.test(O(A)))return;let i=D(A,"nodeIndex")??D(A,"node")??ce(f,"nodeIndex",void 0,new Set),c=D(A,"meshName");if(typeof c=="string"&&c?d.meshName===c:i==null||Number(i)<0||Number.isNaN(Number(i))||Z(v,Math.trunc(Number(i)))){if(U(f,"nodeIndex",v),U(f,"meshIndex",p),Array.isArray(d.hitPoint)){let P=[T(d.hitPoint[0]),T(d.hitPoint[1]),T(d.hitPoint[2])];U(f,"hitPoint",P),U(f,"point",P),U(f,"intersectionPoint",P)}if(Array.isArray(d.normal)){let P=[T(d.normal[0]),T(d.normal[1],1),T(d.normal[2])];U(f,"normal",P),U(f,"hitNormal",P)}typeof d.distance=="number"&&U(f,"distance",d.distance),ee(A.flows?.out)}}),le()},this.receiveCustomEvent=(d,p={})=>He(d,p,{steps:0});function He(d,p,v){if(!(E>=Tt)){E++;try{let A=q(d);r.forEach((f,i)=>{if(!/^(customE|e)vent\/receive$/.test(O(f)))return;let c=D(f,"event")??D(f,"id");if(!(q(c)!==A&&String(c)!==String(d))){for(let[h,P]of Object.entries(p))Y.has(h)||U(i,h,W(P));ee(f.flows?.out,v)}}),le()}finally{E--}}}this.tick=d=>{if(!Number.isFinite(d)||d<0)return;let p=Math.min(d,.25);C+=p,r.forEach((A,f)=>{O(A)==="event/onTick"&&(U(f,"timeDelta",p),U(f,"dt",p),U(f,"timeElapsed",C),ee(A.flows?.out))});let v=[];for(let A=g.length-1;A>=0;A--){let f=g[A];f.elapsed+=p;let i=f.dur>1e-6?J(f.elapsed/f.dur):1,c=f.linear?i:i*i*(3-2*i),h=Je(f.from,f.to,c,f.quat);f.ptr?se(f.ptr,h):f.varKey!==void 0&&K(f.varKey,h),i>=1&&(g.splice(A,1),f.done&&v.push(f.done))}for(let A=x.length-1;A>=0;A--){let f=x[A];f.rem-=p,f.rem<=0&&(x.splice(A,1),f.done&&v.push(f.done))}for(let A of v)ee(A);le()},this.dispose=()=>{g.length=0,x.length=0,u.clear(),m.clear(),o.clear(),b.clear(),S.clear(),w.clear()}}},j=new WeakMap,ye=new WeakMap;function wt(e,t){if(!e||typeof e!="object"||!Number.isFinite(t)||t<=0||Be().some(l=>l.name==="xr-live-head-follow"))return;let n=e.gltf,a=n?.nodes;if(!Array.isArray(a)||a.length===0)return;let r=Math.min(t,.1),s=(ye.get(e)||0)+r,y=!1;for(let l=0;l<a.length;l++){let u=a[l],m=je(u?.extras?.xr?.orbit);if(!m)continue;let o=0,b=0,S=0;if(Array.isArray(m.target))o=m.target[0],b=m.target[1],S=m.target[2];else if(typeof m.target=="string"&&m.target!=="head"){let I=a.find(C=>C?.name===m.target);Array.isArray(I?.translation)&&(o=T(I.translation[0]),b=T(I.translation[1]),S=T(I.translation[2]))}let w=m.phase+m.speed*s,g=o+Math.cos(w)*m.radius,x=b+m.height,R=S+Math.sin(w)*m.radius;if(u.translation=[g,x,R],m.faceCenter){let I=Math.atan2(o-g,S-R);u.rotation=[0,Math.sin(I*.5),0,Math.cos(I*.5)]}y=!0}if(y){ye.set(e,s);let l=Re(n);e.worldMatrices=l;for(let u of e.meshes||[])u.nodeIndex>=0&&u.nodeIndex<l.length&&(u.transform.set(l[u.nodeIndex]),re(u.normalMatrix,u.transform))}}function he(e){if(!(!e||typeof e!="object"))return j.get(e)||j.get(e.viewer)||j.get(e._view)}function Le(e,t,n){let a=he(e);return a?(a.receiveCustomEvent(t,n),!0):!1}var Ce={name:"khr-interactivity",sendInteractivityEvent:Le,getInteractivityVM:he,onLoadModel(e,t){if(!e||typeof e!="object")return;j.get(e)?.dispose(),j.delete(e),ye.delete(e);let n=t?.extensions?.KHR_interactivity,a=Array.isArray(n?.graphs)?n.graphs[n.graph??0]:n;if(!a||!Array.isArray(a.nodes))return;let r=new ae(e,t,a);j.set(e,r),r.fireOnStart()},onMeshSelect(e,t){j.get(e)?.fireOnSelect(t)},onUpdate(e,t){j.get(e)?.tick(t),wt(e,t)},onDestroy(e,t){j.get(t)?.dispose(),j.delete(t),ye.delete(t)}};var ie=new Map,Ve=new WeakMap;function nt(e,t){ie.set(e,t)}var Ne={name:"materials",onBuildPrimitiveVAO(e,t,n,a,r){return(((a?.materials&&n.material!==void 0?a.materials[n.material]:null)?.extensions||{}).KHR_materials_transmission?.transmissionFactor??0)>0?{isTransmissive:!0}:null},onBeforeTransmissivePass(e,t){let n=Ve.get(e);n||(n=e.createTexture(),Ve.set(e,n));let a=Math.max(1,t.canvas.width),r=Math.max(1,t.canvas.height);e.activeTexture(33990),e.bindTexture(3553,n),e.copyTexImage2D(3553,0,6408,0,0,a,r,0),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9987),e.texParameteri(3553,10240,9729),e.generateMipmap(3553)},onResolveShader(e,t,n,a){if(!t)return null;if(t.name&&ie.has(t.name)){let g=ie.get(t.name);return{vs:g.vs||n,fs:g.fs||a}}let r=t.extensions||{},s=r.KHR_materials_clearcoat,y=r.KHR_materials_sheen,l=!!r.KHR_materials_transmission,u=!!r.KHR_materials_ior,m=r.KHR_materials_iridescence;if(!s&&!y&&!r.KHR_materials_unlit&&!l&&!r.KHR_materials_volume&&!u&&!r.KHR_materials_dispersion&&!m)return null;if(r.KHR_materials_unlit)return{vs:n,fs:a.replace("fragColor=vec4(color,outAlpha);","fragColor=vec4(base.rgb,outAlpha);").replace("fragColor=vec4(color,base.a);","fragColor=vec4(base.rgb,base.a);")};let o=a;l&&(o=o.replace("out vec4 fragColor;",`uniform sampler2D uTransmissionTex;
|
|
33
|
+
uniform vec2 uViewportSize;
|
|
34
|
+
out vec4 fragColor;`));let b=(g,x,R=0,I=1e6,C=3)=>{let E=Number(g);return(Number.isFinite(E)?Math.min(I,Math.max(R,E)):x).toFixed(C)},S=Number(r.KHR_materials_ior?.ior??1.5),w=Number.isFinite(S)?Math.min(10,Math.max(1,S)):1.5;if(u){let g=Math.pow((w-1)/(w+1),2);o=o.replace("vec3 F0=mix(vec3(0.04),base.rgb,metallic);",`vec3 F0=mix(vec3(${b(g,.04,0,1,4)}),base.rgb,metallic);`)}if(m){let g=b(m.iridescenceFactor,1,0,1),x=b(m.iridescenceIor,1.3,1,10);o=o.replace("vec3 F=F_SchlickRoughness(F0,roughness,NoV);",`vec3 F=F_SchlickRoughness(F0,roughness,NoV);vec3 iridColor=.5+.5*cos(800.*${x}*NoV*vec3(.015,.018,.022));F=mix(F,iridColor,${g}*pow(1.-NoV,2.));`)}if(l){let g=b(r.KHR_materials_transmission?.transmissionFactor,1,0,1),x=r.KHR_materials_volume||{},R=b(x.thicknessFactor,.5,0,1e4),I=b(x.attenuationDistance,1,.001,1e6),C=Array.isArray(x.attenuationColor)?x.attenuationColor:[1,1,1],E=b(r.KHR_materials_dispersion?.dispersion,0,0,10);o=o.replace("vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;",`vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;
|
|
35
|
+
vec2 sUV=gl_FragCoord.xy/max(uViewportSize,vec2(1.));float iorB=${b(w,1.5,1,10)},dV=${E},tV=${R},lod=clamp(roughness*5.,0.,5.),sc=.06*(1.+tV);
|
|
36
|
+
vec3 refractedR=refract(-V,N,1./(iorB-.02*dV)),rG=refract(-V,N,1./iorB),refractedB=refract(-V,N,1./(iorB+.02*dV));
|
|
37
|
+
vec3 tr=vec3(textureLod(uTransmissionTex,clamp(sUV+refractedR.xy*sc,.001,.999),lod).r,textureLod(uTransmissionTex,clamp(sUV+rG.xy*sc,.001,.999),lod).g,textureLod(uTransmissionTex,clamp(sUV+refractedB.xy*sc,.001,.999),lod).b);
|
|
38
|
+
vec3 aCol=vec3(${b(C[0],1,0,1)},${b(C[1],1,0,1)},${b(C[2],1,0,1)});
|
|
39
|
+
vec3 volumeAtten=exp(-tV*(vec3(1.)-aCol)/max(${I},.001));
|
|
40
|
+
diffuseIBL=mix(diffuseIBL,tr*volumeAtten*base.rgb,${g});`)}if(s&&!a.includes("uClearcoat")){let g=b(s.clearcoatFactor,1,0,1),x=b(s.clearcoatRoughnessFactor,0,0,1);o=o.replace("fragColor=vec4(color,base.a);",`vec3 ccF=F_SchlickRoughness(vec3(.04),${x},NoV)*${g};color=color*(vec3(1.)-ccF)+getStudioRadiance(R,${x})*ccF;fragColor=vec4(color,base.a);`)}if(y){let g=Array.isArray(y.sheenColorFactor)?y.sheenColorFactor:[1,1,1],x=`color+=vec3(${b(g[0],1,0,1)},${b(g[1],1,0,1)},${b(g[2],1,0,1)})*pow(1.-NoV,4.)*.5;`;o.includes("color=applyToneMapping(color,uToneMapping);")?o=o.replace("color=applyToneMapping(color,uToneMapping);",`${x}color=applyToneMapping(color,uToneMapping);`):o=o.replace("fragColor=vec4(color,base.a);",`${x}fragColor=vec4(color,base.a);`)}return{vs:n,fs:o}},onBeforeDrawPrimitive(e,t,n,a,r,s){let y=n.materialIndex;if(y!==void 0&&s?.materials){let l=s.materials[y];l?.name&&ie.has(l.name)&&ie.get(l.name).onBindUniforms?.(e,t,n)}if(n.isTransmissive){let l=Ve.get(e);if(l){e.activeTexture(33990),e.bindTexture(3553,l);let u=e.getUniformLocation(t,"uTransmissionTex");u&&e.uniform1i(u,6);let m=e.getUniformLocation(t,"uViewportSize");m&&e.uniform2f(m,e.drawingBufferWidth||1,e.drawingBufferHeight||1)}}}};var Et=`#version 300 es
|
|
41
|
+
layout(location=0) in vec3 aPosition;layout(location=1) in vec2 aUV;uniform mat4 uMVP;out vec2 vUV;void main(){vUV=aUV;gl_Position=uMVP*vec4(aPosition,1.);}`,It=`#version 300 es
|
|
42
|
+
precision highp float;in vec2 vUV;uniform float uShadowIntensity,uShadowSoftness;out vec4 fragColor;void main(){vec2 p=(vUV-.5)*2.;float d=clamp(length(p),0.,1.);fragColor=vec4(0.,0.,0.,pow(1.-d*d,mix(1.2,2.8,uShadowSoftness))*smoothstep(1.,.85-uShadowSoftness*.6,d)*uShadowIntensity);}`,ge=new WeakMap,rt=new Float32Array(20);function ot(e,t){let[n,a,r,s,y,l]=t;return[e[0]*n+e[4]*a+e[8]*r+e[12],e[1]*n+e[5]*a+e[9]*r+e[13],e[2]*n+e[6]*a+e[10]*r+e[14],Math.abs(e[0])*s+Math.abs(e[4])*y+Math.abs(e[8])*l,Math.abs(e[1])*s+Math.abs(e[5])*y+Math.abs(e[9])*l,Math.abs(e[2])*s+Math.abs(e[6])*y+Math.abs(e[10])*l]}function _t(e){if(e._lb!==void 0)return e._lb;let t=1e9,n=1e9,a=1e9,r=-1e9,s=-1e9,y=-1e9;for(let l of e.primitives||[]){let u=l.positions;if(u)for(let m=0;m<u.length;m+=3)u[m]<t&&(t=u[m]),u[m+1]<n&&(n=u[m+1]),u[m+2]<a&&(a=u[m+2]),u[m]>r&&(r=u[m]),u[m+1]>s&&(s=u[m+1]),u[m+2]>y&&(y=u[m+2])}return e._lb=t<=r?[(t+r)*.5,(n+s)*.5,(a+y)*.5,(r-t)*.5,(s-n)*.5,(y-a)*.5]:null}function Ft(e){let t=ge.get(e);if(t)return t;let n=(l,u)=>{let m=e.createShader(l);return e.shaderSource(m,u),e.compileShader(m),m},a=e.createProgram();e.attachShader(a,n(35633,Et)),e.attachShader(a,n(35632,It)),e.linkProgram(a);let r=e.createVertexArray(),s=e.createBuffer(),y=e.createBuffer();return e.bindVertexArray(r),e.bindBuffer(34962,s),e.bufferData(34962,80,35048),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,3,5126,!1,20,0),e.enableVertexAttribArray(1),e.vertexAttribPointer(1,2,5126,!1,20,12),e.bindBuffer(34963,y),e.bufferData(34963,new Uint16Array([0,1,2,0,2,3]),35044),e.bindVertexArray(null),t={prog:a,vao:r,vbo:s,ibo:y,uMVP:e.getUniformLocation(a,"uMVP"),uIntensity:e.getUniformLocation(a,"uShadowIntensity"),uSoftness:e.getUniformLocation(a,"uShadowSoftness")},ge.set(e,t),t}var ke={name:"contact-shadow",onAfterRender(e,t,n){let a=t.shadowIntensity;if(a<=0||!t.bounds)return;let r=Ft(e),s=(t.backdropMeshes?.length??0)>0,y=[],l=[];for(let o of t.meshes||[]){if(!o||o.visible===!1||o.isPluginMesh||o.name==="__xr_reticle__"||o.name?.startsWith("__xr_slot_"))continue;let b=_t(o);if(!b)continue;o.transform&&(b=ot(o.transform,b)),t.modelRootMatrix&&(b=ot(t.modelRootMatrix,b));let[S,w,g,x,R,I]=b,C=[S,g,x,I,w-R,w+R];/floor|table|pedestal|ground|base|plane/i.test(o.name||"")||R<.14&&Math.min(x,I)>.45?l.push(C):y.push(C)}let u=[],m=(t.bounds.min?t.bounds.min[1]:t.bounds.center[1]-t.bounds.radius)+.002;for(let[o,b,S,w,g]of y){let x=-1/0;for(let[I,C,E,F,,L]of l)g>=L-.08&&Math.abs(o-I)<=E&&Math.abs(b-C)<=F&&L+.002>x&&(x=L+.002);s&&(x=Math.max(x,o>=.04&&o<=.36&&b>=-.34&&b<=-.04&&g>=.01?.036:Math.hypot(o,b)<=.66&&g>=-.06?.003:-.477)),isFinite(x)||(x=m);let R=u.find(I=>Math.hypot(o-I[0],b-I[1])<.06&&Math.abs(x-I[5])<.05);R?(R[2]=Math.max(R[2],S*.78),R[3]=Math.max(R[3],w*.78),R[4]=Math.min(R[4],g)):u.push([o,b,S,w,g,x])}if(u.length===0){let o=t.bounds.center,b=Math.max(.1,t.bounds.radius*1.5)/1.45;u.push([o[0],o[2],b,b,m,m])}e.useProgram(r.prog),e.uniformMatrix4fv(r.uMVP,!1,n),e.enable(3042),(e.blendFuncSeparate||e.blendFunc).call(e,770,771,1,771),e.depthMask(!1),e.bindVertexArray(r.vao),e.bindBuffer(34962,r.vbo);for(let[o,b,S,w,g,x]of u){let R=Math.max(0,g-x),I=a/(1+R*2);if(I<.02)continue;let C=1+Math.min(.75,R*.85),E=Math.max(.045,S*1.45*C),F=Math.max(.045,w*1.45*C);rt.set([o-E,x,b-F,0,0,o+E,x,b-F,1,0,o+E,x,b+F,1,1,o-E,x,b+F,0,1]),e.bufferSubData(34962,0,rt),e.uniform1f(r.uIntensity,I),e.uniform1f(r.uSoftness,Math.min(1,t.shadowSoftness+Math.min(.45,R*.6))),e.drawElements(4,6,5123,0)}e.bindVertexArray(null),e.depthMask(!0),e.disable(3042)},onDestroy(e){let t=ge.get(e);t&&(e.deleteVertexArray(t.vao),e.deleteBuffer(t.vbo),e.deleteBuffer(t.ibo),e.deleteProgram(t.prog),ge.delete(e))}};var at=new WeakMap;function Pt(e){let r=new Float32Array(192),s=new Float32Array(32*2*3),y=new Float32Array(32*2*2),l=new Uint16Array(32*6);for(let R=0;R<32;R++){let I=R/32*Math.PI*2,C=Math.cos(I),E=Math.sin(I),F=R*2,L=R*2+1;r[F*3]=C*.12,r[F*3+1]=.002,r[F*3+2]=E*.12,r[L*3]=C*.15,r[L*3+1]=.002,r[L*3+2]=E*.15,s[F*3+1]=1,s[L*3+1]=1;let N=(R+1)%32*2,G=N+1,H=R*6;l[H]=F,l[H+1]=N,l[H+2]=L,l[H+3]=L,l[H+4]=N,l[H+5]=G}let u=e.createVertexArray();e.bindVertexArray(u);let m=(R,I,C)=>{let E=e.createBuffer();return e.bindBuffer(34962,E),e.bufferData(34962,R,35044),e.enableVertexAttribArray(I),e.vertexAttribPointer(I,C,5126,!1,0,0),E},o=m(r,0,3),b=m(s,1,3),S=m(y,2,2),w=e.createBuffer();e.bindBuffer(34963,w),e.bufferData(34963,l,35044),e.bindVertexArray(null);let g=ne(),x=new Float32Array(9);return x[0]=1,x[4]=1,x[8]=1,{name:"__xr_reticle__",nodeIndex:-1,visible:!1,transform:g,normalMatrix:x,primitives:[{vao:u,indexCount:l.length,indexType:5123,baseColor:[1,1,1,.95],metallic:0,roughness:.2,positions:r,indices:l,texture:null,metallicRoughnessTexture:null,normalTexture:null,occlusionTexture:null,normalScale:1,occlusionStrength:1,buffers:[o,b,S,w]}]}}function it(e,t,n){let a=Math.cos(n),r=Math.sin(n);e.set(t),e[0]=a,e[1]=0,e[2]=-r,e[4]=0,e[5]=1,e[6]=0,e[8]=r,e[9]=0,e[10]=a}var De={name:"webxr-suite",onConfigureXRSessionInit(e,t){let n=new Set(t.optionalFeatures||[]);n.add("hit-test"),n.add("light-estimation"),n.add("dom-overlay"),t.optionalFeatures=Array.from(n);let a=e?.querySelector?.('[slot="ar-overlay"]')||e;a&&(t.domOverlay={root:a},a.addEventListener("beforexrselect",r=>{r.preventDefault()}))},onXRFrame(e,t,n,a){if(!e||!t||!n||!a)return;let r=at.get(t);if(!r){r={initialized:!0,hitTestSource:null,lightProbe:null,reticleMesh:Pt(e.gl),lastHitMatrix:null,hasPlaced:!1,rotationY:0,isDragging:!1,lastTouchAngle:null},at.set(t,r),e.meshes.push(r.reticleMesh),typeof t.requestReferenceSpace=="function"&&t.requestReferenceSpace("viewer").then(o=>typeof t.requestHitTestSource=="function"?t.requestHitTestSource({space:o}):null).then(o=>{r&&o&&(r.hitTestSource=o)}).catch(()=>{}),typeof t.requestLightProbe=="function"&&t.requestLightProbe().then(o=>{r&&o&&(r.lightProbe=o)}).catch(()=>{});let s=()=>r?.lastHitMatrix&&it(e.modelRootMatrix,r.lastHitMatrix,r.rotationY),y=o=>Math.atan2(o.touches[1].clientY-o.touches[0].clientY,o.touches[1].clientX-o.touches[0].clientX);t.addEventListener("select",()=>{r?.lastHitMatrix&&(r.hasPlaced=!0,s())});let l=o=>{r&&(o.touches.length===1&&r.hasPlaced?r.isDragging=!0:o.touches.length===2&&(r.isDragging=!1,r.lastTouchAngle=y(o)))},u=o=>{if(r){if(o.touches.length===1&&r.isDragging)s();else if(o.touches.length===2&&r.lastTouchAngle!==null){let b=y(o);r.rotationY+=b-r.lastTouchAngle,r.lastTouchAngle=b,s()}}},m=()=>{r&&(r.isDragging=!1,r.lastTouchAngle=null)};typeof window<"u"&&(window.addEventListener("touchstart",l,{passive:!0}),window.addEventListener("touchmove",u,{passive:!0}),window.addEventListener("touchend",m,{passive:!0})),t.addEventListener("end",()=>{if(r?.reticleMesh){let o=e.meshes.indexOf(r.reticleMesh);o!==-1&&e.meshes.splice(o,1)}e.modelRootMatrix=ne(),typeof window<"u"&&(window.removeEventListener("touchstart",l),window.removeEventListener("touchmove",u),window.removeEventListener("touchend",m))})}if(r.hitTestSource&&typeof n.getHitTestResults=="function"){let s=n.getHitTestResults(r.hitTestSource);if(s&&s.length>0){let y=s[0].getPose(a);if(y?.transform?.matrix){let l=y.transform.matrix;r.lastHitMatrix=l,r.reticleMesh.visible=!r.hasPlaced||r.isDragging,r.reticleMesh.transform.set(l),re(r.reticleMesh.normalMatrix,r.reticleMesh.transform),r.hasPlaced||it(e.modelRootMatrix,l,r.rotationY)}}else r.reticleMesh.visible=!1}if(r.lightProbe&&typeof n.getLightEstimate=="function"){let s=n.getLightEstimate(r.lightProbe);if(s){let y=s.primaryLightDirection,l=s.primaryLightIntensity;if(y&&l&&Array.isArray(e.lights)){let u=e.lights.find(o=>o.type==="directional");u||(u={type:"directional",direction:[.5,1,.8],color:[1,1,1],intensity:1},e.lights.push(u)),u.direction=[y.x,y.y,y.z];let m=Math.max(l.x,l.y,l.z,.001);u.color=[l.x/m,l.y/m,l.z/m],u.intensity=m}s.sphericalHarmonicsCoefficients&&fe(e.gl,s.sphericalHarmonicsCoefficients)}}}};Q(ke);Q(_e);Q(we);Q(Ne);Q(De);Q(Ce);return pt(Lt);})();
|