rayzee 9.4.1 → 9.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -454,7 +454,7 @@ Key settings:
454
454
  | `interactionRenderScale` | `number` | 0.5 | Per-axis render scale while the camera moves (0.5 = a quarter of the pixels); `1` turns the drop off. Ignored while OIDN is the live denoiser |
455
455
  | `renderMode` | `number` | 0 | Internal preview(0)/production(1) flag driving accumulation & ASVGF behavior — normally set via `configureForMode()`, not written directly |
456
456
  | `visMode` | `number` | 0 | Debug visualization mode (0 = off) |
457
- | `environmentMode` | `string` | 'hdri' | Sky mode: `'hdri'` \| `'procedural'` \| `'gradient'` \| `'color'` — not routed through `engine.settings`; use `engine.environmentManager.setMode()` instead |
457
+ | `environmentMode` | `string` | 'hdri' | Sky mode: `'hdri'` \| `'procedural'` \| `'color'` — not routed through `engine.settings`; use `engine.environmentManager.setMode()` instead |
458
458
  | `cameraProjection` | `string` | 'perspective' | `'perspective'` \| `'orthographic'` \| `'equirectangular'` — see [Camera Projection](#camera-projection-orthographic-360-panorama) |
459
459
  | `panoramaLonRange` | `[number, number]` | `[-180, 180]` | Panorama longitude sweep, degrees, left→right |
460
460
  | `panoramaLatRange` | `[number, number]` | `[-90, 90]` | Panorama latitude sweep, degrees, bottom→top |
@@ -678,9 +678,8 @@ engine.environmentManager.params // Current environment parameters
678
678
  engine.environmentManager.texture // The loaded environment texture
679
679
  await engine.loadEnvironment(url) // Load HDR/EXR environment map (method on engine)
680
680
  await engine.environmentManager.setEnvironmentMap(tex) // Set a custom environment texture
681
- await engine.environmentManager.setMode(mode) // 'hdri' | 'procedural' | 'gradient' | 'color'
681
+ await engine.environmentManager.setMode(mode) // 'hdri' | 'procedural' | 'color'
682
682
  await engine.environmentManager.generateProcedural() // Physical sky: spectral, multiple scattering, analytic sun
683
- await engine.environmentManager.generateGradient() // Gradient sky
684
683
  await engine.environmentManager.generateSolid() // Solid color sky
685
684
  engine.environmentManager.markDirty() // Flag environment for GPU re-upload
686
685
  ```
@@ -1121,7 +1120,7 @@ app.dispose();
1121
1120
 
1122
1121
  Measured on this bench's corpus: all 29 scenes match the Chrome goldens (`npm run bench:node`, RMSE
1123
1122
  ≤ 0.0036, no pixel over 0.02 — the readback's tone map accounts for most of it), and a textured glTF with an
1124
- HDR, a PNG sky or a gradient matches Chrome block for block within 0.05 of a level. Not available
1123
+ HDR or a PNG sky matches Chrome block for block within 0.05 of a level. Not available
1125
1124
  without a browser: on-disk storage (OPFS), gobo libraries (they draw on a 2D canvas), and the AI
1126
1125
  upscaler.
1127
1126
 
package/dist/rayzee.es.js CHANGED
@@ -490,9 +490,6 @@ var Q = {
490
490
  groundCatcherHeight: 0,
491
491
  globalIlluminationIntensity: 1,
492
492
  environmentMode: "hdri",
493
- gradientZenithColor: "#0077BE",
494
- gradientHorizonColor: "#87CEEB",
495
- gradientGroundColor: "#654321",
496
493
  solidSkyColor: "#87CEEB",
497
494
  skySunAzimuth: 180 - fi.azimuth,
498
495
  skySunElevation: fi.elevation,
@@ -5568,24 +5565,6 @@ var Ed = class {
5568
5565
  constructor(e = 512, t = 256) {
5569
5566
  this.width = e, this.height = t, this.lastRenderTime = 0, this._pixels = new Float32Array(e * t * 4), this._texture = new Jt(this._pixels, e, t, Vn, nn), this._texture.mapping = $t, this._texture.colorSpace = dn, this._texture.minFilter = Z, this._texture.magFilter = Z, this._texture.wrapS = Yn, this._texture.wrapT = Ht, this._texture.generateMipmaps = !1;
5570
5567
  }
5571
- renderGradient(e) {
5572
- let t = performance.now(), { width: n, height: r } = this, i = this._pixels, a = e.zenithColor.r, o = e.zenithColor.g, s = e.zenithColor.b, c = e.horizonColor.r, l = e.horizonColor.g, u = e.horizonColor.b, d = e.groundColor.r, f = e.groundColor.g, p = e.groundColor.b;
5573
- for (let e = 0; e < r; e++) {
5574
- let t = (e + .5) / r, m, h, g;
5575
- if (t > .5) {
5576
- let e = (t - .5) * 2;
5577
- m = c + (a - c) * e, h = l + (o - l) * e, g = u + (s - u) * e;
5578
- } else {
5579
- let e = t * 2;
5580
- m = d + (c - d) * e, h = f + (l - f) * e, g = p + (u - p) * e;
5581
- }
5582
- for (let t = 0; t < n; t++) {
5583
- let r = (e * n + t) * 4;
5584
- i[r] = m, i[r + 1] = h, i[r + 2] = g, i[r + 3] = 1;
5585
- }
5586
- }
5587
- return this._texture.needsUpdate = !0, delete this._texture.userData?.__rayzeeColorSpace, this.lastRenderTime = performance.now() - t, this._texture;
5588
- }
5589
5568
  renderSolid(e) {
5590
5569
  let t = performance.now(), { width: n, height: r } = this, i = this._pixels, a = e.color.r, o = e.color.g, s = e.color.b;
5591
5570
  for (let e = 0; e < r; e++) for (let t = 0; t < n; t++) {
@@ -7157,9 +7136,6 @@ var zp = a("env"), Bp = 1024, Vp = 512, Hp = Math.PI / 180, Up = new yn(), Wp =
7157
7136
  1
7158
7137
  ]), 1, 1, Vn, nn, void 0, void 0, void 0, Z, Z), this._envPlaceholder.needsUpdate = !0, this.environmentTexture = this._envPlaceholder, this.envTexSize = new lr(), this.envCDFTexture = null, this._initCDFTexture(), this.environmentRotationMatrix = new yn(), this.cdfBuildTime = 0, this.envParams = {
7159
7138
  mode: "hdri",
7160
- gradientZenithColor: new Ut(Q.gradientZenithColor),
7161
- gradientHorizonColor: new Ut(Q.gradientHorizonColor),
7162
- gradientGroundColor: new Ut(Q.gradientGroundColor),
7163
7139
  solidSkyColor: new Ut(Q.solidSkyColor),
7164
7140
  skySunDirection: this._calculateInitialSunDirection(),
7165
7141
  skySunStrength: Q.skySunStrength,
@@ -7173,7 +7149,7 @@ var zp = a("env"), Bp = 1024, Vp = 512, Hp = Math.PI / 180, Up = new yn(), Wp =
7173
7149
  }
7174
7150
  async setMode(e) {
7175
7151
  let t = this.envParams.mode;
7176
- this.envParams.mode = e, e !== "hdri" && t === "hdri" && (this._previousHDRI = this.environmentTexture), e === "gradient" ? await this.generateGradientTexture() : e === "color" ? await this.generateSolidColorTexture() : e === "procedural" ? await this.generateProceduralSkyTexture() : e === "hdri" && this._previousHDRI && (await this.setEnvironmentMap(this._previousHDRI), this._previousHDRI = null), e !== "procedural" && t === "procedural" && this._releaseSky(), this.markDirty(), this.callbacks.onAutoExposureReset?.(), this._notifyReset();
7152
+ this.envParams.mode = e, e !== "hdri" && t === "hdri" && (this._previousHDRI = this.environmentTexture), e === "color" ? await this.generateSolidColorTexture() : e === "procedural" ? await this.generateProceduralSkyTexture() : e === "hdri" && this._previousHDRI && (await this.setEnvironmentMap(this._previousHDRI), this._previousHDRI = null), e !== "procedural" && t === "procedural" && this._releaseSky(), this.markDirty(), this.callbacks.onAutoExposureReset?.(), this._notifyReset();
7177
7153
  }
7178
7154
  markDirty() {
7179
7155
  this.environmentTexture && (this.environmentTexture.needsUpdate = !0);
@@ -7186,9 +7162,6 @@ var zp = a("env"), Bp = 1024, Vp = 512, Hp = Math.PI / 180, Up = new yn(), Wp =
7186
7162
  return {
7187
7163
  mode: e.mode,
7188
7164
  hdri: this.hdriSource,
7189
- gradientZenithColor: e.gradientZenithColor.toArray(),
7190
- gradientHorizonColor: e.gradientHorizonColor.toArray(),
7191
- gradientGroundColor: e.gradientGroundColor.toArray(),
7192
7165
  solidSkyColor: e.solidSkyColor.toArray(),
7193
7166
  skyModel: "atmosphere",
7194
7167
  skySunDirection: e.skySunDirection.toArray(),
@@ -7203,13 +7176,7 @@ var zp = a("env"), Bp = 1024, Vp = 512, Hp = Math.PI / 180, Up = new yn(), Wp =
7203
7176
  }
7204
7177
  async restore(e) {
7205
7178
  if (!e) return;
7206
- let t = this.envParams, n = e.skyModel === "atmosphere", r = [
7207
- "gradientZenithColor",
7208
- "gradientHorizonColor",
7209
- "gradientGroundColor",
7210
- "solidSkyColor",
7211
- "skySunDirection"
7212
- ];
7179
+ let t = this.envParams, n = e.skyModel === "atmosphere", r = ["solidSkyColor", "skySunDirection"];
7213
7180
  for (let i of n ? [...r, "skyGroundAlbedo"] : r) Array.isArray(e[i]) && t[i].fromArray(e[i]);
7214
7181
  if (n) for (let n of [
7215
7182
  "skySunStrength",
@@ -7219,7 +7186,11 @@ var zp = a("env"), Bp = 1024, Vp = 512, Hp = Math.PI / 180, Up = new yn(), Wp =
7219
7186
  "skyAirDensity",
7220
7187
  "skyAltitude"
7221
7188
  ]) typeof e[n] == "number" && (t[n] = e[n]);
7222
- e.mode && (e.mode !== "hdri" || t.mode !== "hdri") && await this.setMode(e.mode);
7189
+ [
7190
+ "hdri",
7191
+ "color",
7192
+ "procedural"
7193
+ ].includes(e.mode) && (e.mode !== "hdri" || t.mode !== "hdri") && await this.setMode(e.mode);
7223
7194
  }
7224
7195
  get params() {
7225
7196
  return this.envParams;
@@ -7227,9 +7198,6 @@ var zp = a("env"), Bp = 1024, Vp = 512, Hp = Math.PI / 180, Up = new yn(), Wp =
7227
7198
  get texture() {
7228
7199
  return this.environmentTexture;
7229
7200
  }
7230
- generateGradient() {
7231
- return this.generateGradientTexture();
7232
- }
7233
7201
  generateSolid() {
7234
7202
  return this.generateSolidColorTexture();
7235
7203
  }
@@ -7303,20 +7271,6 @@ var zp = a("env"), Bp = 1024, Vp = 512, Hp = Math.PI / 180, Up = new yn(), Wp =
7303
7271
  async applyHDRI(e, { buildCDF: t = !0 } = {}) {
7304
7272
  this.beginHDRI(e), await this.setEnvironmentMap(e, { buildCDF: t });
7305
7273
  }
7306
- async generateGradientTexture() {
7307
- this.simpleSkyRenderer ||= new Dd(512, 256);
7308
- let e = {
7309
- zenithColor: this.envParams.gradientZenithColor,
7310
- horizonColor: this.envParams.gradientHorizonColor,
7311
- groundColor: this.envParams.gradientGroundColor
7312
- };
7313
- try {
7314
- let t = this.simpleSkyRenderer.renderGradient(e);
7315
- t._isGeneratedProcedural = !0, await this.setEnvironmentMap(t), this.uniforms.set("hasSun", 0);
7316
- } catch (e) {
7317
- zp.error("gradient sky generation failed:", e);
7318
- }
7319
- }
7320
7274
  async generateSolidColorTexture() {
7321
7275
  this.simpleSkyRenderer ||= new Dd(512, 256);
7322
7276
  let e = { color: this.envParams.solidSkyColor };
@@ -29226,7 +29180,7 @@ function Jv(e, t, n, r) {
29226
29180
  }
29227
29181
  //#endregion
29228
29182
  //#region src/version.js
29229
- var Yv = "9.4.1", Xv = 1e4, Zv = 15e5;
29183
+ var Yv = "9.4.2", Xv = 1e4, Zv = 15e5;
29230
29184
  function Qv(e, t, n = Xv) {
29231
29185
  return e >= n && t / Zv < e / 3;
29232
29186
  }
@@ -29253,7 +29207,7 @@ function ty(e) {
29253
29207
  }
29254
29208
  //#endregion
29255
29209
  //#region src/Processor/Workers/TLASWorker.js?worker&inline
29256
- var ny = "const e=Math.PI/180;function t(e){let t=2*Math.PI*(e-1)/365;return .006918-.399912*Math.cos(t)+.070257*Math.sin(t)-.006758*Math.cos(2*t)+907e-6*Math.sin(2*t)-.002697*Math.cos(3*t)+.00148*Math.sin(3*t)}function n({hours:n,dayOfYear:r,latitude:i}){let a=t(r),o=(n-12)*15*e,s=i*e,c=Math.sin(s)*Math.sin(a)+Math.cos(s)*Math.cos(a)*Math.cos(o),l=Math.asin(Math.min(1,Math.max(-1,c)))/e;return{azimuth:(Math.atan2(Math.sin(o),Math.cos(o)*Math.sin(s)-Math.tan(a)*Math.cos(s))/e+540)%360,elevation:l}}const r=e=>[0,31,59,90,120,151,181,212,243,273,304,334][e-1]+21,i=Object.freeze({time:10,month:3,latitude:40}),a=n({hours:i.time,dayOfYear:r(i.month),latitude:i.latitude}),o=Object.freeze({viewer:Object.freeze({areaLightIntensityScale:.1,environmentRotation:0,toneMapping:6,saturation:1,dofMode:`look`}),physical:Object.freeze({areaLightIntensityScale:1,environmentRotation:0,toneMapping:6,saturation:1,dofMode:`physical`})}),s={resolution:512,canvasWidth:512,canvasHeight:512,maxTextureSize:4096,toneMapping:o.viewer.toneMapping,exposure:1,saturation:o.viewer.saturation,enableEnvironment:!0,showBackground:!0,transparentBackground:!1,environmentIntensity:1,backgroundIntensity:1,backgroundColor:`#000000`,backgroundBlurriness:0,backgroundBlurSamples:8,environmentRotation:o.viewer.environmentRotation,groundProjectionEnabled:!1,groundProjectionRadius:100,groundProjectionHeight:15,groundProjectionLevel:0,enableGroundCatcher:!1,groundCatcherHeight:0,globalIlluminationIntensity:1,environmentMode:`hdri`,gradientZenithColor:`#0077BE`,gradientHorizonColor:`#87CEEB`,gradientGroundColor:`#654321`,solidSkyColor:`#87CEEB`,skySunAzimuth:180-a.azimuth,skySunElevation:a.elevation,skySunStrength:1,skySunSize:.53,skyTurbidity:2,skyOzone:300,skyAirDensity:1,skyGroundAlbedo:`#959595`,skyAltitude:50,skyPreset:`clearDay`,cameraProjection:`perspective`,panoramaLonRange:[-180,180],panoramaLatRange:[-90,90],panoramaLevelHorizon:!0,enableDOF:!1,fov:55,focusDistance:.8,aperture:5.6,focalLength:50,apertureScale:1,anamorphicRatio:1,unitsPerMetre:1,dofMode:o.viewer.dofMode,dofBlur:.05,autoFocusMode:`auto`,afScreenPoint:{x:.5,y:.5},afSmoothingFactor:.15,enablePathTracer:!0,enableAccumulation:!0,pauseRendering:!1,maxSamples:60,bounces:3,transmissiveBounces:5,maxSubsurfaceSteps:8,maxTransparentBounces:32,useAdaptiveSampling:!0,noiseThreshold:.1,adaptiveMinSamples:8,adaptiveStopFraction:.9,usePixelFreeze:!0,pixelFreezeThreshold:.02,pixelFreezeStability:8,convergenceOverlay:!1,samplingTechnique:2,enableEmissiveTriangleSampling:!1,emissiveBoost:1,fireflyThreshold:3,shadowTerminatorOffset:.1,wavefrontSortMaterials:!0,renderLimitMode:`frames`,renderTimeLimit:30,renderMode:0,enableAlphaShadows:!1,tilesHelper:!0,showLightHelper:!1,directionalLightIntensity:0,directionalLightColor:`#ffffff`,directionalLightPosition:[1,1,1],directionalLightAngle:0,filterStrength:1,edgeAtrousIterations:5,edgePhiLuminance:4,edgePhiNormal:64,edgePhiDepth:.1,enableOIDN:!1,oidnQuality:`fast`,continuousDenoise:!1,continuousDenoiseInterval:8,oidnTemporalHistory:!0,enableUpscaler:!1,upscalerScale:2,upscalerQuality:`fast`,upscalerHdr:!0,debugMode:0,debugThreshold:100,debugModel:0,enableBloom:!1,bloomStrength:.2,bloomRadius:.15,bloomThreshold:.85,interactionModeEnabled:!0,interactionRenderScale:.5,debugVisScale:100,denoiserStrategy:`none`,enableASVGF:!1,asvgfTemporalAlpha:.1,asvgfAtrousIterations:8,asvgfPhiColor:10,asvgfPhiNormal:128,asvgfPhiDepth:1,asvgfVarianceBoost:1,asvgfMaxAccumFrames:32,asvgfGradientStrength:1,asvgfGradientSigmaScale:2,asvgfGradientNoiseFloor:0,asvgfDebugMode:0,asvgfQualityPreset:`medium`,showAsvgfHeatmap:!1,nrdQualityPreset:`medium`,nrdDebugMode:0,autoExposure:!1,autoExposureKeyValue:.18,autoExposureMinExposure:.1,autoExposureMaxExposure:20,autoExposureAdaptSpeedBright:3,autoExposureAdaptSpeedDark:.5};Object.freeze({perspective:0,equirectangular:1,orthographic:2}),s.fov,s.focusDistance,s.aperture,s.focalLength,180-a.azimuth,a.elevation,c({color:[1,1,1],emissive:[0,0,0],emissiveIntensity:1,roughness:1,metalness:0,ior:1.5,opacity:1,transmission:0,thickness:0,attenuationColor:[1,1,1],attenuationDistance:1/0,dispersion:0,sheen:0,sheenRoughness:1,sheenColor:[0,0,0],specularIntensity:1,specularColor:[1,1,1],clearcoat:0,clearcoatRoughness:0,iridescence:0,iridescenceIOR:1.3,iridescenceThicknessRange:[100,400],normalScale:[1,1],bumpScale:1,displacementScale:1,transparent:0,alphaTest:0,alphaMode:0,side:0,depthWrite:1,subsurface:0,subsurfaceColor:[1,1,1],subsurfaceRadius:[1,.2,.1],subsurfaceRadiusScale:1,subsurfaceAnisotropy:0,anisotropy:0,anisotropyRotation:0});function c(e){for(let t of Object.values(e))typeof t==`object`&&Object.freeze(t);return Object.freeze(e)}const l={TRIANGLE_LEAF:1073741824,BLAS_POINTER_LEAF:1073741825,FRONTIER:1073741826};function u(e){return new Uint32Array(e.buffer,e.byteOffset,e.length)}function d(e,t){if(e>=1073741824)throw RangeError(`${t} is ${e.toLocaleString()}, at or past the BVH index limit of ${1073741824 .toLocaleString()}. Node indices are stored as u32 bit patterns and the leaf tags occupy everything above that.`);return e}Math.min(typeof navigator<`u`&&navigator.hardwareConcurrency||4,6),s.maxSamples,s.bounces,s.renderMode,s.enableAlphaShadows,s.maxSubsurfaceSteps;const f=Float64Array.from([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);function p(e,t){return e[t]*(e[t+5]*e[t+10]-e[t+6]*e[t+9])-e[t+4]*(e[t+1]*e[t+10]-e[t+2]*e[t+9])+e[t+8]*(e[t+1]*e[t+6]-e[t+2]*e[t+5])}function m(e,t,n){let r=p(e,t);if(!Number.isFinite(r)||Math.abs(r)<1e-20)return n.set(f),n;let i=1/r;return n[0]=(e[t+5]*e[t+10]-e[t+6]*e[t+9])*i,n[1]=(e[t+2]*e[t+9]-e[t+1]*e[t+10])*i,n[2]=(e[t+1]*e[t+6]-e[t+2]*e[t+5])*i,n[3]=0,n[4]=(e[t+6]*e[t+8]-e[t+4]*e[t+10])*i,n[5]=(e[t]*e[t+10]-e[t+2]*e[t+8])*i,n[6]=(e[t+2]*e[t+4]-e[t]*e[t+6])*i,n[7]=0,n[8]=(e[t+4]*e[t+9]-e[t+5]*e[t+8])*i,n[9]=(e[t+1]*e[t+8]-e[t]*e[t+9])*i,n[10]=(e[t]*e[t+5]-e[t+1]*e[t+4])*i,n[11]=0,n[12]=-(n[0]*e[t+12]+n[4]*e[t+13]+n[8]*e[t+14]),n[13]=-(n[1]*e[t+12]+n[5]*e[t+13]+n[9]*e[t+14]),n[14]=-(n[2]*e[t+12]+n[6]*e[t+13]+n[10]*e[t+14]),n[15]=1,n}function h(e,t){for(let n=0;n<16;n++)if(e[t+n]!==f[n])return!1;return!0}const g=e=>e<32?e:32,_=new Float64Array(16);var v=class e{constructor(){this._flatBuffer=null,this._flatBufferCapacity=0,this._binCounts=new Int32Array(96),this._binBounds=new Float64Array(576),this._binSuffix=new Float64Array(32),this._binSuffixCount=new Int32Array(32),this._order=null,this._stackI=null,this._stackB=null,this._stackFrames=0,this._sortScratch=[],this._suffix=null,this._bounds=new Float64Array(12),this._extent=new Float64Array(3),this._cMin=new Float64Array(3)}static nodeCountFor(e){return e>0?e*2-1:0}releaseFlattenBuffer(){this._flatBuffer=null,this._flatBufferCapacity=0}build(t){let n=new Float64Array(t.count*6);t.writeWorldAABBs(n);let r=this.buildStructure(n,t.count);return e.fillLeaves(r.data,r.nodeCount,t),r}buildStructure(t,n){let r=e.nodeCountFor(n);if(n===0)return{data:new Float32Array,nodeCount:0};d(r,`TLAS node count`);let i=r*16;i>this._flatBufferCapacity&&(this._flatBuffer=new Float32Array(i),this._flatBufferCapacity=i);let a=this._flatBuffer,o=u(a);(!this._order||this._order.length<n)&&(this._order=new Int32Array(n));let s=this._order;for(let e=0;e<n;e++)s[e]=e;this._ensureStack(64);let c=0,f=0,p=0,m=n,h=this._bounds;this._rangeBounds(t,s,p,m,h,0);let g=h[0],_=h[1],v=h[2],y=h[3],b=h[4],x=h[5];for(;;){if(m-p===1){let e=f*16;o[e]=0,o[e+1]=s[p],a[e+2]=0,o[e+3]=l.BLAS_POINTER_LEAF}else{let e=this._partition(t,s,p,m,g,_,v,y,b,x),n=e-p,r=f+1,i=r+(n*2-1),l=f*16;a[l]=h[0],a[l+1]=h[1],a[l+2]=h[2],o[l+3]=r,a[l+4]=h[3],a[l+5]=h[4],a[l+6]=h[5],o[l+7]=i,a[l+8]=h[6],a[l+9]=h[7],a[l+10]=h[8],a[l+11]=0,a[l+12]=h[9],a[l+13]=h[10],a[l+14]=h[11],a[l+15]=0;let u=n<=m-e,d=u?0:6,S=u?6:0;c=this._push(c,u?i:r,u?e:p,u?m:e,h,S),f=u?r:i,u?m=e:p=e,g=h[d],_=h[d+1],v=h[d+2],y=h[d+3],b=h[d+4],x=h[d+5];continue}if(c===0)break;c--;let e=c*3,n=c*6;f=this._stackI[e],p=this._stackI[e+1],m=this._stackI[e+2],g=this._stackB[n],_=this._stackB[n+1],v=this._stackB[n+2],y=this._stackB[n+3],b=this._stackB[n+4],x=this._stackB[n+5]}return{data:a.subarray(0,i),nodeCount:r}}_push(e,t,n,r,i,a){e>=this._stackFrames&&this._ensureStack(this._stackFrames*2);let o=e*3,s=e*6;this._stackI[o]=t,this._stackI[o+1]=n,this._stackI[o+2]=r;for(let e=0;e<6;e++)this._stackB[s+e]=i[a+e];return e+1}_ensureStack(e){if(this._stackFrames>=e)return;let t=new Int32Array(e*3),n=new Float64Array(e*6);this._stackI&&(t.set(this._stackI),n.set(this._stackB)),this._stackI=t,this._stackB=n,this._stackFrames=e}static fillLeaves(t,n,r){let i=r.world,a=r.sourceMesh,o=r.tplBlasOffset,s=r.visible,c=r.tlasLeafIndex,d=u(t);for(let r=0;r<n;r++){let n=r*16;if(d[n+3]!==l.BLAS_POINTER_LEAF)continue;let u=d[n+1]&1073741823;d[n]=o[a[u]],t[n+2]=+!!s[u],e.writeLeafMatrix(t,d,n,i,u),c[u]=r}}static writeLeafMatrix(e,t,n,r,i){let a=_;m(r,i*16,a),e[n+4]=a[0],e[n+5]=a[4],e[n+6]=a[8],e[n+7]=a[12],e[n+8]=a[1],e[n+9]=a[5],e[n+10]=a[9],e[n+11]=a[13],e[n+12]=a[2],e[n+13]=a[6],e[n+14]=a[10],e[n+15]=a[14],t[n+1]=(i|(h(r,i*16)?1073741824:0))>>>0}_partition(e,t,n,r,i,a,o,s,c,l){let u=r-n,d=0;if(u===2)d=n+1;else if(u<=8)d=n+(u>>1),this._insertionSortRange(e,t,n,r,this._widestCentroidAxis(e,t,n,r));else{if(d=this._binnedSplit(e,t,n,r,i,a,o,s,c,l),d>n&&d<r)return d;if(d=this._sweepSplit(e,t,n,r,i,a,o,s,c,l),!(d>n&&d<r)){let f=s-i,p=c-a,m=l-o,h=p>f&&p>m?1:m>f?2:0;this._sortRange(e,t,n,r,h),d=n+(u>>1)}}let f=this._bounds;return this._rangeBounds(e,t,n,d,f,0),this._rangeBounds(e,t,d,r,f,6),d}_binnedSplit(e,t,n,r,i,a,o,s,c,l){let u=this._surfaceArea(i,a,o,s,c,l);if(!(u>0)||!isFinite(u))return n;let d=1/0,f=1/0,p=1/0,m=-1/0,h=-1/0,_=-1/0;for(let i=n;i<r;i++){let n=t[i]*6,r=(e[n]+e[n+3])*.5,a=(e[n+1]+e[n+4])*.5,o=(e[n+2]+e[n+5])*.5;r<d&&(d=r),r>m&&(m=r),a<f&&(f=a),a>h&&(h=a),o<p&&(p=o),o>_&&(_=o)}let v=this._extent,y=this._cMin;v[0]=m-d,v[1]=h-f,v[2]=_-p,y[0]=d,y[1]=f,y[2]=p;let b=1/0,x=-1,S=-1,C=this._binCounts,w=this._binBounds,T=v[0]>1e-12,E=v[1]>1e-12,D=v[2]>1e-12;if(!T&&!E&&!D)return n;let O=g(r-n),k=T?O/v[0]:0,A=E?O/v[1]:0,j=D?O/v[2]:0;C.fill(0,0,O*3);for(let e=0;e<O*3;e++){let t=e*6;w[t]=w[t+1]=w[t+2]=1/0,w[t+3]=w[t+4]=w[t+5]=-1/0}for(let i=n;i<r;i++){let n=t[i]*6,r=e[n],a=e[n+1],o=e[n+2],s=e[n+3],c=e[n+4],l=e[n+5];for(let e=0;e<3;e++){let t=e===0?k:e===1?A:j;if(t===0)continue;let n=((e===0?(r+s)*.5:e===1?(a+c)*.5:(o+l)*.5)-y[e])*t|0;n<0?n=0:n>=O&&(n=O-1),n+=e*O,C[n]++;let i=n*6;r<w[i]&&(w[i]=r),a<w[i+1]&&(w[i+1]=a),o<w[i+2]&&(w[i+2]=o),s>w[i+3]&&(w[i+3]=s),c>w[i+4]&&(w[i+4]=c),l>w[i+5]&&(w[i+5]=l)}}for(let e=0;e<3;e++){if(!(v[e]>1e-12))continue;let t=e*O,n=this._binSuffix,r=this._binSuffixCount,i=1/0,a=1/0,o=1/0,s=-1/0,c=-1/0,l=-1/0,d=0;for(let e=O-1;e>=1;e--){let u=(t+e)*6;w[u]<i&&(i=w[u]),w[u+1]<a&&(a=w[u+1]),w[u+2]<o&&(o=w[u+2]),w[u+3]>s&&(s=w[u+3]),w[u+4]>c&&(c=w[u+4]),w[u+5]>l&&(l=w[u+5]),d+=C[t+e],n[e]=d?this._surfaceArea(i,a,o,s,c,l):0,r[e]=d}let f=1/0,p=1/0,m=1/0,h=-1/0,g=-1/0,_=-1/0,y=0;for(let i=1;i<O;i++){let a=(t+i-1)*6;if(w[a]<f&&(f=w[a]),w[a+1]<p&&(p=w[a+1]),w[a+2]<m&&(m=w[a+2]),w[a+3]>h&&(h=w[a+3]),w[a+4]>g&&(g=w[a+4]),w[a+5]>_&&(_=w[a+5]),y+=C[t+i-1],y===0||r[i]===0)continue;let o=1+(this._surfaceArea(f,p,m,h,g,_)*y+n[i]*r[i])/u;o<b&&(b=o,x=e,S=i)}}if(x<0)return n;let M=O/v[x],N=y[x],P=this._bounds;P[0]=P[1]=P[2]=P[6]=P[7]=P[8]=1/0,P[3]=P[4]=P[5]=P[9]=P[10]=P[11]=-1/0;let F=n,I=r-1;for(;F<=I;){let n=t[F]*6,r=((e[n+x]+e[n+3+x])*.5-N)*M|0;r<0?r=0:r>=O&&(r=O-1);let i=r<S?0:6;if(e[n]<P[i]&&(P[i]=e[n]),e[n+1]<P[i+1]&&(P[i+1]=e[n+1]),e[n+2]<P[i+2]&&(P[i+2]=e[n+2]),e[n+3]>P[i+3]&&(P[i+3]=e[n+3]),e[n+4]>P[i+4]&&(P[i+4]=e[n+4]),e[n+5]>P[i+5]&&(P[i+5]=e[n+5]),i===0)F++;else{let e=t[F];t[F]=t[I],t[I]=e,I--}}return F}_sweepSplit(e,t,n,r,i,a,o,s,c,l){let u=r-n,d=this._surfaceArea(i,a,o,s,c,l);if(!(d>0)||!isFinite(d))return n;let f=this._suffixBuffer(u),p=1/0,m=-1,h=-1;for(let i=0;i<3;i++){this._sortRange(e,t,n,r,i);let a=1/0,o=1/0,s=1/0,c=-1/0,l=-1/0,g=-1/0;for(let r=u-1;r>=1;r--){let i=t[n+r]*6;e[i]<a&&(a=e[i]),e[i+1]<o&&(o=e[i+1]),e[i+2]<s&&(s=e[i+2]),e[i+3]>c&&(c=e[i+3]),e[i+4]>l&&(l=e[i+4]),e[i+5]>g&&(g=e[i+5]);let u=r*6;f[u]=a,f[u+1]=o,f[u+2]=s,f[u+3]=c,f[u+4]=l,f[u+5]=g}let _=1/0,v=1/0,y=1/0,b=-1/0,x=-1/0,S=-1/0;for(let r=1;r<u;r++){let a=t[n+r-1]*6;e[a]<_&&(_=e[a]),e[a+1]<v&&(v=e[a+1]),e[a+2]<y&&(y=e[a+2]),e[a+3]>b&&(b=e[a+3]),e[a+4]>x&&(x=e[a+4]),e[a+5]>S&&(S=e[a+5]);let o=r*6,s=this._surfaceArea(_,v,y,b,x,S),c=this._surfaceArea(f[o],f[o+1],f[o+2],f[o+3],f[o+4],f[o+5]),l=1+(s*r+c*(u-r))/d;l<p&&(p=l,m=i,h=r)}}return m<0||h<=0?n:(m!==2&&this._sortRange(e,t,n,r,m),n+h)}_widestCentroidAxis(e,t,n,r){let i=1/0,a=1/0,o=1/0,s=-1/0,c=-1/0,l=-1/0;for(let u=n;u<r;u++){let n=t[u]*6,r=(e[n]+e[n+3])*.5,d=(e[n+1]+e[n+4])*.5,f=(e[n+2]+e[n+5])*.5;r<i&&(i=r),r>s&&(s=r),d<a&&(a=d),d>c&&(c=d),f<o&&(o=f),f>l&&(l=f)}let u=s-i,d=c-a,f=l-o;return d>u&&d>f?1:f>u?2:0}_insertionSortRange(e,t,n,r,i){let a=i,o=3+i;for(let i=n+1;i<r;i++){let r=t[i],s=e[r*6+a]+e[r*6+o],c=i-1;for(;c>=n&&e[t[c]*6+a]+e[t[c]*6+o]>s;)t[c+1]=t[c],c--;t[c+1]=r}}_sortRange(e,t,n,r,i){let a=r-n,o=this._sortScratch;o.length=a;for(let e=0;e<a;e++)o[e]=t[n+e];let s=i,c=3+i;o.sort((t,n)=>e[t*6+s]+e[t*6+c]-(e[n*6+s]+e[n*6+c]));for(let e=0;e<a;e++)t[n+e]=o[e]}_suffixBuffer(e){let t=e*6;return(!this._suffix||this._suffix.length<t)&&(this._suffix=new Float64Array(t)),this._suffix}_rangeBounds(e,t,n,r,i,a){let o=1/0,s=1/0,c=1/0,l=-1/0,u=-1/0,d=-1/0;for(let i=n;i<r;i++){let n=t[i]*6;e[n]<o&&(o=e[n]),e[n+1]<s&&(s=e[n+1]),e[n+2]<c&&(c=e[n+2]),e[n+3]>l&&(l=e[n+3]),e[n+4]>u&&(u=e[n+4]),e[n+5]>d&&(d=e[n+5])}i[a]=o,i[a+1]=s,i[a+2]=c,i[a+3]=l,i[a+4]=u,i[a+5]=d}_surfaceArea(e,t,n,r,i,a){let o=r-e,s=i-t,c=a-n;return 2*(o*s+s*c+c*o)}};const y={silent:0,error:1,warn:2,info:3,debug:4},b=`info`,x=`rayzeeLogLevel`,S=`rayzeeLogNamespaces`,C=`color:#7c8494`,w=`color:inherit`;let T=null,E=null;function D(e){try{return globalThis.localStorage?.getItem(e)??null}catch{return null}}function O(e,t){try{t===null?globalThis.localStorage?.removeItem(e):globalThis.localStorage?.setItem(e,t)}catch{}}function k(){if(T!==null)return T;let e=globalThis.__RAYZEE_LOG_LEVEL__;return e!==void 0&&e in y?(T=y[e],T):(T=y[D(x)]??y[b],T)}function A(){if(E!==null)return E;let e=globalThis.__RAYZEE_LOG_NS__??D(S);return E=e?String(e).split(`,`).map(e=>e.trim()).filter(Boolean):[],E}function j(e,t){if(t<y.debug)return!0;let n=A();return n.length===0||n.some(t=>e===t||e.startsWith(`${t}:`))}function M(e,t,n){if(e>k()||!j(t,e))return;let r=e===y.error?console.error:e===y.warn?console.warn:console.log,i=`[${t}]`;typeof n[0]==`string`?r(`%c${i}%c ${n[0]}`,C,w,...n.slice(1)):r(`%c${i}`,C,...n)}const N={n:e=>Number(e).toLocaleString(`en-US`),ms:e=>e<10?`${Number(e).toFixed(1)} ms`:`${Math.round(e)} ms`,mb:e=>{let t=e/(1024*1024);return t<10?`${t.toFixed(1)} MB`:`${Math.round(t)} MB`},px:(e,t)=>`${e}×${t}`,count:(e,t,n=`${t}s`)=>`${N.n(e)} ${Number(e)===1?t:n}`,list:e=>e.filter(Boolean).join(` · `)},P={levels:y,setLevel(e){return e in y?(globalThis.__RAYZEE_LOG_LEVEL__=e,T=y[e],O(x,e===b?null:e),e):(console.warn(`[log] unknown level '${e}' — expected one of ${Object.keys(y).join(`, `)}`),this.getLevel())},getLevel(){let e=k();return Object.keys(y).find(t=>y[t]===e)},isEnabled(e){return(y[e]??y.debug)<=k()},only(...e){let t=e.flat().filter(Boolean);return E=t,globalThis.__RAYZEE_LOG_NS__=t.join(`,`),O(S,t.length?t.join(`,`):null),t.length&&this.setLevel(`debug`),t},refresh(){return T=null,E=null,this.getLevel()}};function F(e){return{namespace:e,error:(...t)=>M(y.error,e,t),warn:(...t)=>M(y.warn,e,t),info:(...t)=>M(y.info,e,t),debug:(...t)=>M(y.debug,e,t),isEnabled:e=>P.isEnabled(e),summary(t,n=[]){let r=n.filter(Boolean);if(r.length===0||!console.groupCollapsed){M(y.info,e,[t]),r.forEach(t=>M(y.debug,e,[t]));return}y.info>k()||((k()>=y.debug&&console.group?console.group:console.groupCollapsed)(`%c[${e}]%c ${t}`,C,w),r.forEach(e=>console.log(e)),console.groupEnd())}}}function I(e){e&&e in y&&(globalThis.__RAYZEE_LOG_LEVEL__=e,T=y[e])}const L=F(`bvh`);self.onmessage=function(e){let{aabbs:t,count:n,logLevel:r}=e.data;I(r);try{let e=performance.now(),{data:r,nodeCount:i}=new v().buildStructure(new Float64Array(t),n);L.debug(`TLAS ${N.n(i)} nodes in ${N.ms(performance.now()-e)}`),self.postMessage({tlasData:r,nodeCount:i},[r.buffer])}catch(e){L.error(`TLAS build failed:`,e),self.postMessage({error:e.message})}};", ry = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", ny], { type: "text/javascript;charset=utf-8" });
29210
+ var ny = "const e=Math.PI/180;function t(e){let t=2*Math.PI*(e-1)/365;return .006918-.399912*Math.cos(t)+.070257*Math.sin(t)-.006758*Math.cos(2*t)+907e-6*Math.sin(2*t)-.002697*Math.cos(3*t)+.00148*Math.sin(3*t)}function n({hours:n,dayOfYear:r,latitude:i}){let a=t(r),o=(n-12)*15*e,s=i*e,c=Math.sin(s)*Math.sin(a)+Math.cos(s)*Math.cos(a)*Math.cos(o),l=Math.asin(Math.min(1,Math.max(-1,c)))/e;return{azimuth:(Math.atan2(Math.sin(o),Math.cos(o)*Math.sin(s)-Math.tan(a)*Math.cos(s))/e+540)%360,elevation:l}}const r=e=>[0,31,59,90,120,151,181,212,243,273,304,334][e-1]+21,i=Object.freeze({time:10,month:3,latitude:40}),a=n({hours:i.time,dayOfYear:r(i.month),latitude:i.latitude}),o=Object.freeze({viewer:Object.freeze({areaLightIntensityScale:.1,environmentRotation:0,toneMapping:6,saturation:1,dofMode:`look`}),physical:Object.freeze({areaLightIntensityScale:1,environmentRotation:0,toneMapping:6,saturation:1,dofMode:`physical`})}),s={resolution:512,canvasWidth:512,canvasHeight:512,maxTextureSize:4096,toneMapping:o.viewer.toneMapping,exposure:1,saturation:o.viewer.saturation,enableEnvironment:!0,showBackground:!0,transparentBackground:!1,environmentIntensity:1,backgroundIntensity:1,backgroundColor:`#000000`,backgroundBlurriness:0,backgroundBlurSamples:8,environmentRotation:o.viewer.environmentRotation,groundProjectionEnabled:!1,groundProjectionRadius:100,groundProjectionHeight:15,groundProjectionLevel:0,enableGroundCatcher:!1,groundCatcherHeight:0,globalIlluminationIntensity:1,environmentMode:`hdri`,solidSkyColor:`#87CEEB`,skySunAzimuth:180-a.azimuth,skySunElevation:a.elevation,skySunStrength:1,skySunSize:.53,skyTurbidity:2,skyOzone:300,skyAirDensity:1,skyGroundAlbedo:`#959595`,skyAltitude:50,skyPreset:`clearDay`,cameraProjection:`perspective`,panoramaLonRange:[-180,180],panoramaLatRange:[-90,90],panoramaLevelHorizon:!0,enableDOF:!1,fov:55,focusDistance:.8,aperture:5.6,focalLength:50,apertureScale:1,anamorphicRatio:1,unitsPerMetre:1,dofMode:o.viewer.dofMode,dofBlur:.05,autoFocusMode:`auto`,afScreenPoint:{x:.5,y:.5},afSmoothingFactor:.15,enablePathTracer:!0,enableAccumulation:!0,pauseRendering:!1,maxSamples:60,bounces:3,transmissiveBounces:5,maxSubsurfaceSteps:8,maxTransparentBounces:32,useAdaptiveSampling:!0,noiseThreshold:.1,adaptiveMinSamples:8,adaptiveStopFraction:.9,usePixelFreeze:!0,pixelFreezeThreshold:.02,pixelFreezeStability:8,convergenceOverlay:!1,samplingTechnique:2,enableEmissiveTriangleSampling:!1,emissiveBoost:1,fireflyThreshold:3,shadowTerminatorOffset:.1,wavefrontSortMaterials:!0,renderLimitMode:`frames`,renderTimeLimit:30,renderMode:0,enableAlphaShadows:!1,tilesHelper:!0,showLightHelper:!1,directionalLightIntensity:0,directionalLightColor:`#ffffff`,directionalLightPosition:[1,1,1],directionalLightAngle:0,filterStrength:1,edgeAtrousIterations:5,edgePhiLuminance:4,edgePhiNormal:64,edgePhiDepth:.1,enableOIDN:!1,oidnQuality:`fast`,continuousDenoise:!1,continuousDenoiseInterval:8,oidnTemporalHistory:!0,enableUpscaler:!1,upscalerScale:2,upscalerQuality:`fast`,upscalerHdr:!0,debugMode:0,debugThreshold:100,debugModel:0,enableBloom:!1,bloomStrength:.2,bloomRadius:.15,bloomThreshold:.85,interactionModeEnabled:!0,interactionRenderScale:.5,debugVisScale:100,denoiserStrategy:`none`,enableASVGF:!1,asvgfTemporalAlpha:.1,asvgfAtrousIterations:8,asvgfPhiColor:10,asvgfPhiNormal:128,asvgfPhiDepth:1,asvgfVarianceBoost:1,asvgfMaxAccumFrames:32,asvgfGradientStrength:1,asvgfGradientSigmaScale:2,asvgfGradientNoiseFloor:0,asvgfDebugMode:0,asvgfQualityPreset:`medium`,showAsvgfHeatmap:!1,nrdQualityPreset:`medium`,nrdDebugMode:0,autoExposure:!1,autoExposureKeyValue:.18,autoExposureMinExposure:.1,autoExposureMaxExposure:20,autoExposureAdaptSpeedBright:3,autoExposureAdaptSpeedDark:.5};Object.freeze({perspective:0,equirectangular:1,orthographic:2}),s.fov,s.focusDistance,s.aperture,s.focalLength,180-a.azimuth,a.elevation,c({color:[1,1,1],emissive:[0,0,0],emissiveIntensity:1,roughness:1,metalness:0,ior:1.5,opacity:1,transmission:0,thickness:0,attenuationColor:[1,1,1],attenuationDistance:1/0,dispersion:0,sheen:0,sheenRoughness:1,sheenColor:[0,0,0],specularIntensity:1,specularColor:[1,1,1],clearcoat:0,clearcoatRoughness:0,iridescence:0,iridescenceIOR:1.3,iridescenceThicknessRange:[100,400],normalScale:[1,1],bumpScale:1,displacementScale:1,transparent:0,alphaTest:0,alphaMode:0,side:0,depthWrite:1,subsurface:0,subsurfaceColor:[1,1,1],subsurfaceRadius:[1,.2,.1],subsurfaceRadiusScale:1,subsurfaceAnisotropy:0,anisotropy:0,anisotropyRotation:0});function c(e){for(let t of Object.values(e))typeof t==`object`&&Object.freeze(t);return Object.freeze(e)}const l={TRIANGLE_LEAF:1073741824,BLAS_POINTER_LEAF:1073741825,FRONTIER:1073741826};function u(e){return new Uint32Array(e.buffer,e.byteOffset,e.length)}function d(e,t){if(e>=1073741824)throw RangeError(`${t} is ${e.toLocaleString()}, at or past the BVH index limit of ${1073741824 .toLocaleString()}. Node indices are stored as u32 bit patterns and the leaf tags occupy everything above that.`);return e}Math.min(typeof navigator<`u`&&navigator.hardwareConcurrency||4,6),s.maxSamples,s.bounces,s.renderMode,s.enableAlphaShadows,s.maxSubsurfaceSteps;const f=Float64Array.from([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);function p(e,t){return e[t]*(e[t+5]*e[t+10]-e[t+6]*e[t+9])-e[t+4]*(e[t+1]*e[t+10]-e[t+2]*e[t+9])+e[t+8]*(e[t+1]*e[t+6]-e[t+2]*e[t+5])}function m(e,t,n){let r=p(e,t);if(!Number.isFinite(r)||Math.abs(r)<1e-20)return n.set(f),n;let i=1/r;return n[0]=(e[t+5]*e[t+10]-e[t+6]*e[t+9])*i,n[1]=(e[t+2]*e[t+9]-e[t+1]*e[t+10])*i,n[2]=(e[t+1]*e[t+6]-e[t+2]*e[t+5])*i,n[3]=0,n[4]=(e[t+6]*e[t+8]-e[t+4]*e[t+10])*i,n[5]=(e[t]*e[t+10]-e[t+2]*e[t+8])*i,n[6]=(e[t+2]*e[t+4]-e[t]*e[t+6])*i,n[7]=0,n[8]=(e[t+4]*e[t+9]-e[t+5]*e[t+8])*i,n[9]=(e[t+1]*e[t+8]-e[t]*e[t+9])*i,n[10]=(e[t]*e[t+5]-e[t+1]*e[t+4])*i,n[11]=0,n[12]=-(n[0]*e[t+12]+n[4]*e[t+13]+n[8]*e[t+14]),n[13]=-(n[1]*e[t+12]+n[5]*e[t+13]+n[9]*e[t+14]),n[14]=-(n[2]*e[t+12]+n[6]*e[t+13]+n[10]*e[t+14]),n[15]=1,n}function h(e,t){for(let n=0;n<16;n++)if(e[t+n]!==f[n])return!1;return!0}const g=e=>e<32?e:32,_=new Float64Array(16);var v=class e{constructor(){this._flatBuffer=null,this._flatBufferCapacity=0,this._binCounts=new Int32Array(96),this._binBounds=new Float64Array(576),this._binSuffix=new Float64Array(32),this._binSuffixCount=new Int32Array(32),this._order=null,this._stackI=null,this._stackB=null,this._stackFrames=0,this._sortScratch=[],this._suffix=null,this._bounds=new Float64Array(12),this._extent=new Float64Array(3),this._cMin=new Float64Array(3)}static nodeCountFor(e){return e>0?e*2-1:0}releaseFlattenBuffer(){this._flatBuffer=null,this._flatBufferCapacity=0}build(t){let n=new Float64Array(t.count*6);t.writeWorldAABBs(n);let r=this.buildStructure(n,t.count);return e.fillLeaves(r.data,r.nodeCount,t),r}buildStructure(t,n){let r=e.nodeCountFor(n);if(n===0)return{data:new Float32Array,nodeCount:0};d(r,`TLAS node count`);let i=r*16;i>this._flatBufferCapacity&&(this._flatBuffer=new Float32Array(i),this._flatBufferCapacity=i);let a=this._flatBuffer,o=u(a);(!this._order||this._order.length<n)&&(this._order=new Int32Array(n));let s=this._order;for(let e=0;e<n;e++)s[e]=e;this._ensureStack(64);let c=0,f=0,p=0,m=n,h=this._bounds;this._rangeBounds(t,s,p,m,h,0);let g=h[0],_=h[1],v=h[2],y=h[3],b=h[4],x=h[5];for(;;){if(m-p===1){let e=f*16;o[e]=0,o[e+1]=s[p],a[e+2]=0,o[e+3]=l.BLAS_POINTER_LEAF}else{let e=this._partition(t,s,p,m,g,_,v,y,b,x),n=e-p,r=f+1,i=r+(n*2-1),l=f*16;a[l]=h[0],a[l+1]=h[1],a[l+2]=h[2],o[l+3]=r,a[l+4]=h[3],a[l+5]=h[4],a[l+6]=h[5],o[l+7]=i,a[l+8]=h[6],a[l+9]=h[7],a[l+10]=h[8],a[l+11]=0,a[l+12]=h[9],a[l+13]=h[10],a[l+14]=h[11],a[l+15]=0;let u=n<=m-e,d=u?0:6,S=u?6:0;c=this._push(c,u?i:r,u?e:p,u?m:e,h,S),f=u?r:i,u?m=e:p=e,g=h[d],_=h[d+1],v=h[d+2],y=h[d+3],b=h[d+4],x=h[d+5];continue}if(c===0)break;c--;let e=c*3,n=c*6;f=this._stackI[e],p=this._stackI[e+1],m=this._stackI[e+2],g=this._stackB[n],_=this._stackB[n+1],v=this._stackB[n+2],y=this._stackB[n+3],b=this._stackB[n+4],x=this._stackB[n+5]}return{data:a.subarray(0,i),nodeCount:r}}_push(e,t,n,r,i,a){e>=this._stackFrames&&this._ensureStack(this._stackFrames*2);let o=e*3,s=e*6;this._stackI[o]=t,this._stackI[o+1]=n,this._stackI[o+2]=r;for(let e=0;e<6;e++)this._stackB[s+e]=i[a+e];return e+1}_ensureStack(e){if(this._stackFrames>=e)return;let t=new Int32Array(e*3),n=new Float64Array(e*6);this._stackI&&(t.set(this._stackI),n.set(this._stackB)),this._stackI=t,this._stackB=n,this._stackFrames=e}static fillLeaves(t,n,r){let i=r.world,a=r.sourceMesh,o=r.tplBlasOffset,s=r.visible,c=r.tlasLeafIndex,d=u(t);for(let r=0;r<n;r++){let n=r*16;if(d[n+3]!==l.BLAS_POINTER_LEAF)continue;let u=d[n+1]&1073741823;d[n]=o[a[u]],t[n+2]=+!!s[u],e.writeLeafMatrix(t,d,n,i,u),c[u]=r}}static writeLeafMatrix(e,t,n,r,i){let a=_;m(r,i*16,a),e[n+4]=a[0],e[n+5]=a[4],e[n+6]=a[8],e[n+7]=a[12],e[n+8]=a[1],e[n+9]=a[5],e[n+10]=a[9],e[n+11]=a[13],e[n+12]=a[2],e[n+13]=a[6],e[n+14]=a[10],e[n+15]=a[14],t[n+1]=(i|(h(r,i*16)?1073741824:0))>>>0}_partition(e,t,n,r,i,a,o,s,c,l){let u=r-n,d=0;if(u===2)d=n+1;else if(u<=8)d=n+(u>>1),this._insertionSortRange(e,t,n,r,this._widestCentroidAxis(e,t,n,r));else{if(d=this._binnedSplit(e,t,n,r,i,a,o,s,c,l),d>n&&d<r)return d;if(d=this._sweepSplit(e,t,n,r,i,a,o,s,c,l),!(d>n&&d<r)){let f=s-i,p=c-a,m=l-o,h=p>f&&p>m?1:m>f?2:0;this._sortRange(e,t,n,r,h),d=n+(u>>1)}}let f=this._bounds;return this._rangeBounds(e,t,n,d,f,0),this._rangeBounds(e,t,d,r,f,6),d}_binnedSplit(e,t,n,r,i,a,o,s,c,l){let u=this._surfaceArea(i,a,o,s,c,l);if(!(u>0)||!isFinite(u))return n;let d=1/0,f=1/0,p=1/0,m=-1/0,h=-1/0,_=-1/0;for(let i=n;i<r;i++){let n=t[i]*6,r=(e[n]+e[n+3])*.5,a=(e[n+1]+e[n+4])*.5,o=(e[n+2]+e[n+5])*.5;r<d&&(d=r),r>m&&(m=r),a<f&&(f=a),a>h&&(h=a),o<p&&(p=o),o>_&&(_=o)}let v=this._extent,y=this._cMin;v[0]=m-d,v[1]=h-f,v[2]=_-p,y[0]=d,y[1]=f,y[2]=p;let b=1/0,x=-1,S=-1,C=this._binCounts,w=this._binBounds,T=v[0]>1e-12,E=v[1]>1e-12,D=v[2]>1e-12;if(!T&&!E&&!D)return n;let O=g(r-n),k=T?O/v[0]:0,A=E?O/v[1]:0,j=D?O/v[2]:0;C.fill(0,0,O*3);for(let e=0;e<O*3;e++){let t=e*6;w[t]=w[t+1]=w[t+2]=1/0,w[t+3]=w[t+4]=w[t+5]=-1/0}for(let i=n;i<r;i++){let n=t[i]*6,r=e[n],a=e[n+1],o=e[n+2],s=e[n+3],c=e[n+4],l=e[n+5];for(let e=0;e<3;e++){let t=e===0?k:e===1?A:j;if(t===0)continue;let n=((e===0?(r+s)*.5:e===1?(a+c)*.5:(o+l)*.5)-y[e])*t|0;n<0?n=0:n>=O&&(n=O-1),n+=e*O,C[n]++;let i=n*6;r<w[i]&&(w[i]=r),a<w[i+1]&&(w[i+1]=a),o<w[i+2]&&(w[i+2]=o),s>w[i+3]&&(w[i+3]=s),c>w[i+4]&&(w[i+4]=c),l>w[i+5]&&(w[i+5]=l)}}for(let e=0;e<3;e++){if(!(v[e]>1e-12))continue;let t=e*O,n=this._binSuffix,r=this._binSuffixCount,i=1/0,a=1/0,o=1/0,s=-1/0,c=-1/0,l=-1/0,d=0;for(let e=O-1;e>=1;e--){let u=(t+e)*6;w[u]<i&&(i=w[u]),w[u+1]<a&&(a=w[u+1]),w[u+2]<o&&(o=w[u+2]),w[u+3]>s&&(s=w[u+3]),w[u+4]>c&&(c=w[u+4]),w[u+5]>l&&(l=w[u+5]),d+=C[t+e],n[e]=d?this._surfaceArea(i,a,o,s,c,l):0,r[e]=d}let f=1/0,p=1/0,m=1/0,h=-1/0,g=-1/0,_=-1/0,y=0;for(let i=1;i<O;i++){let a=(t+i-1)*6;if(w[a]<f&&(f=w[a]),w[a+1]<p&&(p=w[a+1]),w[a+2]<m&&(m=w[a+2]),w[a+3]>h&&(h=w[a+3]),w[a+4]>g&&(g=w[a+4]),w[a+5]>_&&(_=w[a+5]),y+=C[t+i-1],y===0||r[i]===0)continue;let o=1+(this._surfaceArea(f,p,m,h,g,_)*y+n[i]*r[i])/u;o<b&&(b=o,x=e,S=i)}}if(x<0)return n;let M=O/v[x],N=y[x],P=this._bounds;P[0]=P[1]=P[2]=P[6]=P[7]=P[8]=1/0,P[3]=P[4]=P[5]=P[9]=P[10]=P[11]=-1/0;let F=n,I=r-1;for(;F<=I;){let n=t[F]*6,r=((e[n+x]+e[n+3+x])*.5-N)*M|0;r<0?r=0:r>=O&&(r=O-1);let i=r<S?0:6;if(e[n]<P[i]&&(P[i]=e[n]),e[n+1]<P[i+1]&&(P[i+1]=e[n+1]),e[n+2]<P[i+2]&&(P[i+2]=e[n+2]),e[n+3]>P[i+3]&&(P[i+3]=e[n+3]),e[n+4]>P[i+4]&&(P[i+4]=e[n+4]),e[n+5]>P[i+5]&&(P[i+5]=e[n+5]),i===0)F++;else{let e=t[F];t[F]=t[I],t[I]=e,I--}}return F}_sweepSplit(e,t,n,r,i,a,o,s,c,l){let u=r-n,d=this._surfaceArea(i,a,o,s,c,l);if(!(d>0)||!isFinite(d))return n;let f=this._suffixBuffer(u),p=1/0,m=-1,h=-1;for(let i=0;i<3;i++){this._sortRange(e,t,n,r,i);let a=1/0,o=1/0,s=1/0,c=-1/0,l=-1/0,g=-1/0;for(let r=u-1;r>=1;r--){let i=t[n+r]*6;e[i]<a&&(a=e[i]),e[i+1]<o&&(o=e[i+1]),e[i+2]<s&&(s=e[i+2]),e[i+3]>c&&(c=e[i+3]),e[i+4]>l&&(l=e[i+4]),e[i+5]>g&&(g=e[i+5]);let u=r*6;f[u]=a,f[u+1]=o,f[u+2]=s,f[u+3]=c,f[u+4]=l,f[u+5]=g}let _=1/0,v=1/0,y=1/0,b=-1/0,x=-1/0,S=-1/0;for(let r=1;r<u;r++){let a=t[n+r-1]*6;e[a]<_&&(_=e[a]),e[a+1]<v&&(v=e[a+1]),e[a+2]<y&&(y=e[a+2]),e[a+3]>b&&(b=e[a+3]),e[a+4]>x&&(x=e[a+4]),e[a+5]>S&&(S=e[a+5]);let o=r*6,s=this._surfaceArea(_,v,y,b,x,S),c=this._surfaceArea(f[o],f[o+1],f[o+2],f[o+3],f[o+4],f[o+5]),l=1+(s*r+c*(u-r))/d;l<p&&(p=l,m=i,h=r)}}return m<0||h<=0?n:(m!==2&&this._sortRange(e,t,n,r,m),n+h)}_widestCentroidAxis(e,t,n,r){let i=1/0,a=1/0,o=1/0,s=-1/0,c=-1/0,l=-1/0;for(let u=n;u<r;u++){let n=t[u]*6,r=(e[n]+e[n+3])*.5,d=(e[n+1]+e[n+4])*.5,f=(e[n+2]+e[n+5])*.5;r<i&&(i=r),r>s&&(s=r),d<a&&(a=d),d>c&&(c=d),f<o&&(o=f),f>l&&(l=f)}let u=s-i,d=c-a,f=l-o;return d>u&&d>f?1:f>u?2:0}_insertionSortRange(e,t,n,r,i){let a=i,o=3+i;for(let i=n+1;i<r;i++){let r=t[i],s=e[r*6+a]+e[r*6+o],c=i-1;for(;c>=n&&e[t[c]*6+a]+e[t[c]*6+o]>s;)t[c+1]=t[c],c--;t[c+1]=r}}_sortRange(e,t,n,r,i){let a=r-n,o=this._sortScratch;o.length=a;for(let e=0;e<a;e++)o[e]=t[n+e];let s=i,c=3+i;o.sort((t,n)=>e[t*6+s]+e[t*6+c]-(e[n*6+s]+e[n*6+c]));for(let e=0;e<a;e++)t[n+e]=o[e]}_suffixBuffer(e){let t=e*6;return(!this._suffix||this._suffix.length<t)&&(this._suffix=new Float64Array(t)),this._suffix}_rangeBounds(e,t,n,r,i,a){let o=1/0,s=1/0,c=1/0,l=-1/0,u=-1/0,d=-1/0;for(let i=n;i<r;i++){let n=t[i]*6;e[n]<o&&(o=e[n]),e[n+1]<s&&(s=e[n+1]),e[n+2]<c&&(c=e[n+2]),e[n+3]>l&&(l=e[n+3]),e[n+4]>u&&(u=e[n+4]),e[n+5]>d&&(d=e[n+5])}i[a]=o,i[a+1]=s,i[a+2]=c,i[a+3]=l,i[a+4]=u,i[a+5]=d}_surfaceArea(e,t,n,r,i,a){let o=r-e,s=i-t,c=a-n;return 2*(o*s+s*c+c*o)}};const y={silent:0,error:1,warn:2,info:3,debug:4},b=`info`,x=`rayzeeLogLevel`,S=`rayzeeLogNamespaces`,C=`color:#7c8494`,w=`color:inherit`;let T=null,E=null;function D(e){try{return globalThis.localStorage?.getItem(e)??null}catch{return null}}function O(e,t){try{t===null?globalThis.localStorage?.removeItem(e):globalThis.localStorage?.setItem(e,t)}catch{}}function k(){if(T!==null)return T;let e=globalThis.__RAYZEE_LOG_LEVEL__;return e!==void 0&&e in y?(T=y[e],T):(T=y[D(x)]??y[b],T)}function A(){if(E!==null)return E;let e=globalThis.__RAYZEE_LOG_NS__??D(S);return E=e?String(e).split(`,`).map(e=>e.trim()).filter(Boolean):[],E}function j(e,t){if(t<y.debug)return!0;let n=A();return n.length===0||n.some(t=>e===t||e.startsWith(`${t}:`))}function M(e,t,n){if(e>k()||!j(t,e))return;let r=e===y.error?console.error:e===y.warn?console.warn:console.log,i=`[${t}]`;typeof n[0]==`string`?r(`%c${i}%c ${n[0]}`,C,w,...n.slice(1)):r(`%c${i}`,C,...n)}const N={n:e=>Number(e).toLocaleString(`en-US`),ms:e=>e<10?`${Number(e).toFixed(1)} ms`:`${Math.round(e)} ms`,mb:e=>{let t=e/(1024*1024);return t<10?`${t.toFixed(1)} MB`:`${Math.round(t)} MB`},px:(e,t)=>`${e}×${t}`,count:(e,t,n=`${t}s`)=>`${N.n(e)} ${Number(e)===1?t:n}`,list:e=>e.filter(Boolean).join(` · `)},P={levels:y,setLevel(e){return e in y?(globalThis.__RAYZEE_LOG_LEVEL__=e,T=y[e],O(x,e===b?null:e),e):(console.warn(`[log] unknown level '${e}' — expected one of ${Object.keys(y).join(`, `)}`),this.getLevel())},getLevel(){let e=k();return Object.keys(y).find(t=>y[t]===e)},isEnabled(e){return(y[e]??y.debug)<=k()},only(...e){let t=e.flat().filter(Boolean);return E=t,globalThis.__RAYZEE_LOG_NS__=t.join(`,`),O(S,t.length?t.join(`,`):null),t.length&&this.setLevel(`debug`),t},refresh(){return T=null,E=null,this.getLevel()}};function F(e){return{namespace:e,error:(...t)=>M(y.error,e,t),warn:(...t)=>M(y.warn,e,t),info:(...t)=>M(y.info,e,t),debug:(...t)=>M(y.debug,e,t),isEnabled:e=>P.isEnabled(e),summary(t,n=[]){let r=n.filter(Boolean);if(r.length===0||!console.groupCollapsed){M(y.info,e,[t]),r.forEach(t=>M(y.debug,e,[t]));return}y.info>k()||((k()>=y.debug&&console.group?console.group:console.groupCollapsed)(`%c[${e}]%c ${t}`,C,w),r.forEach(e=>console.log(e)),console.groupEnd())}}}function I(e){e&&e in y&&(globalThis.__RAYZEE_LOG_LEVEL__=e,T=y[e])}const L=F(`bvh`);self.onmessage=function(e){let{aabbs:t,count:n,logLevel:r}=e.data;I(r);try{let e=performance.now(),{data:r,nodeCount:i}=new v().buildStructure(new Float64Array(t),n);L.debug(`TLAS ${N.n(i)} nodes in ${N.ms(performance.now()-e)}`),self.postMessage({tlasData:r,nodeCount:i},[r.buffer])}catch(e){L.error(`TLAS build failed:`,e),self.postMessage({error:e.message})}};", ry = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", ny], { type: "text/javascript;charset=utf-8" });
29257
29211
  function iy(e) {
29258
29212
  let t;
29259
29213
  try {