From d452a6fad4752277ef23e0920bf1dc92b989ae31 Mon Sep 17 00:00:00 2001 From: James Russo Date: Thu, 5 Nov 2026 06:40:37 +0000 Subject: [PATCH] feat(registry): add path-traced-3d example with raster preview and path-traced export (#7219) * feat(registry): add path-traced-3d example with raster preview and path-traced export An opt-in Three.js starter: previews with raster rendering and exports with three-gpu-pathtracer, from one scene file. three 0.180.0, three-gpu-pathtracer 0.0.24 and three-mesh-bvh 0.9.5 ship as one local, pinned ES module with their licences and a rebuild recipe, so renders make no network requests and 2D projects never load the tracer. Setup is one buildReady promise that awaits library readiness promises only and ends with a throwaway frame and a one-pixel readback. Frames are drawn in the hf-seek listener through waitUntil, each time from zero with a fixed sample count. Math.random is seeded while the scene and tracer are built, because object ids order light sampling and the tracer's noise textures come from it. Adds a skill reference and a docs guide for the setup and seek contract, the frozen clock, why scheduler.yield() waits hang, and sample/bounce cost. Co-Authored-By: Claude Opus 5.5 (1M context) * fix(registry): list path-traced-3d in CLI docs and tighten its notes Add the example's section to the CLI examples doc, which docs.test.ts requires for every registry example. Throw if the tracer reports compiling but exposes no compile promise, instead of spinning renderSample(). Say that three's object uuids set the tracer's sort order, that later-created objects need the seed too, and that Date and performance.now read the current seek time during a render rather than staying at 0. Co-Authored-By: Claude Opus 5.5 (1M context) --------- Co-authored-by: Claude Opus 5.5 (1M context) --- .oxlintrc.json | 1 + .prettierignore | 1 + docs/concepts/frame-adapters.mdx | 2 +- docs/guides/path-tracing.mdx | 84 + package.json | 2 +- packages/cli/src/docs/examples.md | 4 + .../examples/path-traced-3d/assets/render.js | 142 + .../examples/path-traced-3d/assets/scene.js | 119 + .../path-traced-3d/assets/vendor/README.md | 20 + .../vendor/three-gpu-pathtracer.LICENSE.txt | 21 + .../assets/vendor/three-mesh-bvh.LICENSE.txt | 21 + .../assets/vendor/three-path-tracer.min.js | 8111 +++++++++++++++++ .../assets/vendor/three.LICENSE.txt | 21 + registry/examples/path-traced-3d/index.html | 57 + .../path-traced-3d/registry-item.json | 55 + .../examples/path-traced-3d/source/README.md | 42 + .../examples/path-traced-3d/source/build.mjs | 23 + .../path-traced-3d/source/package-lock.json | 537 ++ .../path-traced-3d/source/package.json | 14 + .../source/path-traced-3d.test.mjs | 81 + .../path-traced-3d/source/vendor-entry.js | 10 + .../path-traced-3d/source/verify-render.mjs | 211 + skills-manifest.json | 4 +- skills/hyperframes/references/path-tracing.md | 36 + skills/hyperframes/references/runtimes.md | 2 +- skills/hyperframes/references/types/3d.md | 2 +- 26 files changed, 9617 insertions(+), 6 deletions(-) create mode 100644 docs/guides/path-tracing.mdx create mode 100644 registry/examples/path-traced-3d/assets/render.js create mode 100644 registry/examples/path-traced-3d/assets/scene.js create mode 100644 registry/examples/path-traced-3d/assets/vendor/README.md create mode 100644 registry/examples/path-traced-3d/assets/vendor/three-gpu-pathtracer.LICENSE.txt create mode 100644 registry/examples/path-traced-3d/assets/vendor/three-mesh-bvh.LICENSE.txt create mode 100644 registry/examples/path-traced-3d/assets/vendor/three-path-tracer.min.js create mode 100644 registry/examples/path-traced-3d/assets/vendor/three.LICENSE.txt create mode 100644 registry/examples/path-traced-3d/index.html create mode 100644 registry/examples/path-traced-3d/registry-item.json create mode 100644 registry/examples/path-traced-3d/source/README.md create mode 100644 registry/examples/path-traced-3d/source/build.mjs create mode 100644 registry/examples/path-traced-3d/source/package-lock.json create mode 100644 registry/examples/path-traced-3d/source/package.json create mode 100644 registry/examples/path-traced-3d/source/path-traced-3d.test.mjs create mode 100644 registry/examples/path-traced-3d/source/vendor-entry.js create mode 100644 registry/examples/path-traced-3d/source/verify-render.mjs create mode 100644 skills/hyperframes/references/path-tracing.md diff --git a/.oxlintrc.json b/.oxlintrc.json index ef54d6835b..3f9314a4ba 100644 --- a/.oxlintrc.json +++ b/.oxlintrc.json @@ -15,6 +15,7 @@ "registry/blocks/**/lib/*.iife.js", "registry/blocks/{glass-shard-title,code-slice-hero,cuboid-carousel,frost-sequence-camera-orbit,orbit-card}/**/*.{js,mjs}", "registry/blocks/frost-sequence-camera-orbit/source/**", + "registry/examples/path-traced-3d/assets/vendor/*.min.js", "chrome/", "packages/cli/src/media-use/lib/svg-sanitize.mjs" ], diff --git a/.prettierignore b/.prettierignore index e90c71dc47..aad5f080f6 100644 --- a/.prettierignore +++ b/.prettierignore @@ -35,6 +35,7 @@ registry/blocks/cuboid-carousel/assets/addons/**/*.js registry/blocks/orbit-card/assets/three.core.min.js registry/blocks/orbit-card/assets/three.module.min.js registry/blocks/orbit-card/assets/gsap-3.14.2.min.js +registry/examples/path-traced-3d/assets/vendor/three-path-tracer.min.js # generated Lottie data: pretty-printing multiplies its size registry/blocks/lottie-character-walk/assets/mascot.json # repo-native skill examples with intentional pseudo-markup placeholders diff --git a/docs/concepts/frame-adapters.mdx b/docs/concepts/frame-adapters.mdx index 9b2c75be5f..0b45b90b40 100644 --- a/docs/concepts/frame-adapters.mdx +++ b/docs/concepts/frame-adapters.mdx @@ -10,7 +10,7 @@ description: "Connect a seekable animation timeline to a custom HyperFrames host A frame adapter answers one question: what state should an animation have at frame N? -Most composition authors do not implement this interface. HyperFrames already seeks registered GSAP, CSS, Anime.js, Lottie, Three.js, Web Animations, and TypeGPU animation through its browser runtime. Use the [GSAP guide](/guides/gsap-animation) for the normal authoring path. +Most composition authors do not implement this interface. HyperFrames already seeks registered GSAP, CSS, Anime.js, Lottie, Three.js, Web Animations, and TypeGPU animation through its browser runtime. Use the [GSAP guide](/guides/gsap-animation) for the normal authoring path. For a Three.js scene with a raster preview and a path-traced export, start from the [path-traced 3D example](/guides/path-tracing). Use `FrameAdapter` when you are building a custom host around a seekable animation object. diff --git a/docs/guides/path-tracing.mdx b/docs/guides/path-tracing.mdx new file mode 100644 index 0000000000..fe99e475e8 --- /dev/null +++ b/docs/guides/path-tracing.mdx @@ -0,0 +1,84 @@ +--- +title: "Path-Traced 3D" +description: "Preview a Three.js scene with fast raster frames, then export it path traced, with every frame identical however it is seeked." +--- + +Use the `path-traced-3d` example when a 3D shot needs real light: soft shadows, light bouncing between objects and reflections of the scene itself. It previews with ordinary Three.js raster rendering and exports with a path tracer, from the same scene file. + +```bash Terminal +npx hyperframes init my-3d --example path-traced-3d +cd my-3d +npx hyperframes preview +``` + +The tracer is opt-in. A project gets it only by starting from this example, so 2D projects never load it. + +## What is in the project + +| File | Holds | +| --- | --- | +| `index.html` | The 1920×1080, 6-second root and its three variables | +| `assets/scene.js` | The scene and `poseAt(t)`, the only code that moves anything | +| `assets/render.js` | Setup, the seek handler and the tracer settings | +| `assets/vendor/three-path-tracer.min.js` | three 0.180.0, three-gpu-pathtracer 0.0.24 and three-mesh-bvh 0.9.5 as one local ES module, with their licences and a note on how to rebuild it | + +Everything loads from the project folder, so a render never fetches a library from the network. + +## Preview in raster, export path traced + +| Variable | Default | Meaning | +| --- | --- | --- | +| `renderer` | `raster` | `raster` draws a frame in milliseconds. `path` traces it. | +| `samples` | `64` | Path samples per pixel, traced for every frame. | +| `bounces` | `4` | How many times a ray may bounce. | + +Work in raster, then export once with the tracer: + +```bash Terminal +npx hyperframes render --variables '{"renderer":"path","samples":64}' -o final.mp4 +``` + +Path tracing costs far more than raster. Measured on an Apple M4 Max with a hardware GPU, an 8-second 720p clip took 10.8 s rasterized and 810.5 s path traced at 32 samples per pixel and 6 bounces. Noise falls with the square root of the samples, so halving it costs four times the samples, and every extra bounce makes each path longer. + + + Without a hardware GPU, Chrome draws WebGL in software and the tracer is much slower: on SwiftShader its first shader run alone took about a minute at 320×180, longer than the default 45-second readiness wait. Check path mode at a small size with 1 or 2 samples, and raise the wait with `--timeout 170000` for `check` and `snapshot` or `--player-ready-timeout 180000` for `render`. + + +## How it stays deterministic + +HyperFrames seeks frames one by one, in any order and across several workers, so `render.js` follows these rules. Keep them when you change it. + +- **Setup is one `window.__hf.buildReady` promise.** It builds the scene, compiles the shaders, sets up the tracer and draws one throwaway frame, because the first frame a renderer draws differs from later ones. It then reads one pixel back, so the GPU has really finished that first, slowest run before setup resolves. +- **Frames are drawn only in the `hf-seek` listener**, registered with `event.detail.waitUntil(promise)`. Nothing runs a render loop. +- **Each new time starts from zero.** The handler poses the scene for that time, rebuilds the tracer's copy of it and traces exactly `samples` passes. A seek back to the time already on screen does no work. +- **The tracer never waits on time.** `renderDelay` and `fadeDuration` are 0, because the tracer times them with a clock that does not move during a render. +- **Randomness is seeded.** Three's object uuids, which set the order the tracer sorts lights, meshes and textures in, and the tracer's noise textures come from `Math.random`, so the scene and the tracer are built under a fixed seed. Without it, every render worker draws different grain. Anything you add later, such as a model loaded during setup, must also be created under the seed. + +### The frozen clock + +During a render, `Date.now()` and `performance.now()` return the current seek time and do not move between seeks (they read 0 until the first seek), and `requestAnimationFrame` callbacks wait for a seek. The first seek waits for setup. Setup that waits for an animation frame or for the clock to advance never finishes. Composition code uses no timers of its own either. Await the library's readiness promise instead: + +```js assets/render.js +await renderer.compileAsync(scene, camera); +``` + +three-gpu-pathtracer 0.0.24 shows its shader compilation only as the `isCompiling` flag. The promise behind that flag is three's `compileAsync`, so `render.js` awaits it in one helper, `tracerCompiled()`, whenever a `renderSample()` call leaves `isCompiling` set. It decides only when drawing may start, never what is drawn. + +Do not wait with `scheduler.yield()`. Its continuations run ahead of timers, so a loop that yields until a compile finishes starves the timer `compileAsync` polls with, and the page never becomes ready. Do not swap `compileAsync` for the synchronous `compile` to hide that; fix the wait. + +## Check a change + +Seek to a time, an earlier time, then the first time again, and compare the two stills: + +```bash Terminal +npx hyperframes snapshot --at 4,0,4 --no-end +``` + +The two stills at 4 s must be byte-identical. Then render a short clip and look at its frames. In the HyperFrames repository, `registry/examples/path-traced-3d/source/verify-render.mjs` runs these checks in both modes at 320×180 and checks the exported pixels. + +## Related + +- [Frame adapters](/concepts/frame-adapters) for how the runtime seeks Three.js +- [Variables](/concepts/variables) for `--variables` and batch renders +- [Determinism](/concepts/determinism) for the general rules +- [Performance](/guides/performance) for render speed diff --git a/package.json b/package.json index 9376f29557..a5e8f42273 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "player:perf": "bun run --filter @hyperframes/player perf", "format:check": "oxfmt --check .", "knip": "knip", - "test:scripts": "node --import tsx --test scripts/animejs-v4-guidance.test.mjs scripts/check-tracked-artifacts.test.mjs scripts/check-registry-set-delta.test.mjs scripts/check-no-main-deletions.test.mjs scripts/check-pr-captures.test.mjs scripts/check-comment-citations.test.mjs scripts/comments-workflow.test.mjs scripts/comment-ratchet.test.mjs scripts/check-docs-snippet-motion.test.mjs scripts/registry-target-paths.test.mjs scripts/check-workspace-contracts.test.mjs scripts/check-media-use-copy-parity.test.mjs scripts/check-svg-sanitize-parity.test.mjs scripts/check-media-use-svg-sanitize-generated.test.mjs scripts/check-package-cycles.test.mjs scripts/check-cli-process-ownership.test.mjs scripts/check-cli-lazy-deps.test.mjs scripts/file-url-paths.test.mjs scripts/check-studio-copy-dashes.test.mjs scripts/check-large-files.test.mjs scripts/package-subpaths.test.mjs scripts/validate-release-channel.test.mjs scripts/clawhub-sync.test.mjs scripts/clawhub-unlist-retired.test.mjs scripts/publish-workflow.test.mjs scripts/pr-edit-concurrency.test.mjs scripts/merge-queue-workflows.test.mjs scripts/ci-cache-workflows.test.mjs scripts/install-workspace-dependencies.test.mjs scripts/check-edit-accuracy-filter.test.mjs scripts/edit-accuracy-retry.test.mjs scripts/draft-changelog.test.ts scripts/set-version.test.ts scripts/release-prepare.test.ts scripts/cli-options.test.ts scripts/changelog-weekly.test.ts scripts/claude-plugin-compression.test.ts scripts/catalog-payload-assets.test.ts scripts/host-registry-assets.test.ts scripts/catalog-preview-temp.test.ts scripts/backfill-block-previews.test.ts scripts/catalog-hosted-files.test.ts scripts/player-cdn-pin.test.ts scripts/studio-runtime-smoke.test.mjs scripts/verify-packed-manifests.test.mjs scripts/rewrite-relative-import-extensions.test.mjs scripts/lint-skills.test.mjs scripts/check-core-skills.test.mjs scripts/creator-editing-recipes.test.mjs packages/gcp-cloud-run/check-dockerfile-workspaces.test.mjs packages/core/scripts/writeGeneratedFile.test.ts scripts/catalog-publication.test.mjs scripts/ci/resolve-workflow-pr.test.mjs scripts/lefthook-order.test.mjs scripts/inline-gsap.test.mjs scripts/ci/flake-gate.test.mjs scripts/ci/base-file.test.mjs scripts/ci/release-only-diff.test.mjs scripts/check-catalog-source-pr.test.mjs scripts/generate-registry-items.test.ts scripts/catalog-drift.test.ts scripts/catalog-fetch-mirror.test.ts scripts/catalog-script-inlining.test.ts scripts/catalog-detail.test.ts scripts/generate-catalog-pages.test.ts scripts/verify-catalog-payloads.test.ts scripts/registry-theme-fallbacks.test.ts scripts/registry-skill-files.test.ts scripts/creator-editing-capabilities.test.mjs scripts/generate-catalog-previews.test.ts scripts/registry-primitive-payloads.test.ts registry/components/pan-stations/pan-stations.test.mjs registry/components/filmed-screen/filmed-screen.test.mjs registry/components/echo-smear/echo-smear.test.mjs && vitest run scripts/catalog/ scripts/contrastRatchet.test.ts scripts/generate-catalog-payloads.test.ts", + "test:scripts": "node --import tsx --test scripts/animejs-v4-guidance.test.mjs scripts/check-tracked-artifacts.test.mjs scripts/check-registry-set-delta.test.mjs scripts/check-no-main-deletions.test.mjs scripts/check-pr-captures.test.mjs scripts/check-comment-citations.test.mjs scripts/comments-workflow.test.mjs scripts/comment-ratchet.test.mjs scripts/check-docs-snippet-motion.test.mjs scripts/registry-target-paths.test.mjs scripts/check-workspace-contracts.test.mjs scripts/check-media-use-copy-parity.test.mjs scripts/check-svg-sanitize-parity.test.mjs scripts/check-media-use-svg-sanitize-generated.test.mjs scripts/check-package-cycles.test.mjs scripts/check-cli-process-ownership.test.mjs scripts/check-cli-lazy-deps.test.mjs scripts/file-url-paths.test.mjs scripts/check-studio-copy-dashes.test.mjs scripts/check-large-files.test.mjs scripts/package-subpaths.test.mjs scripts/validate-release-channel.test.mjs scripts/clawhub-sync.test.mjs scripts/clawhub-unlist-retired.test.mjs scripts/publish-workflow.test.mjs scripts/pr-edit-concurrency.test.mjs scripts/merge-queue-workflows.test.mjs scripts/ci-cache-workflows.test.mjs scripts/install-workspace-dependencies.test.mjs scripts/check-edit-accuracy-filter.test.mjs scripts/edit-accuracy-retry.test.mjs scripts/draft-changelog.test.ts scripts/set-version.test.ts scripts/release-prepare.test.ts scripts/cli-options.test.ts scripts/changelog-weekly.test.ts scripts/claude-plugin-compression.test.ts scripts/catalog-payload-assets.test.ts scripts/host-registry-assets.test.ts scripts/catalog-preview-temp.test.ts scripts/backfill-block-previews.test.ts scripts/catalog-hosted-files.test.ts scripts/player-cdn-pin.test.ts scripts/studio-runtime-smoke.test.mjs scripts/verify-packed-manifests.test.mjs scripts/rewrite-relative-import-extensions.test.mjs scripts/lint-skills.test.mjs scripts/check-core-skills.test.mjs scripts/creator-editing-recipes.test.mjs packages/gcp-cloud-run/check-dockerfile-workspaces.test.mjs packages/core/scripts/writeGeneratedFile.test.ts scripts/catalog-publication.test.mjs scripts/ci/resolve-workflow-pr.test.mjs scripts/lefthook-order.test.mjs scripts/inline-gsap.test.mjs scripts/ci/flake-gate.test.mjs scripts/ci/base-file.test.mjs scripts/ci/release-only-diff.test.mjs scripts/check-catalog-source-pr.test.mjs scripts/generate-registry-items.test.ts scripts/catalog-drift.test.ts scripts/catalog-fetch-mirror.test.ts scripts/catalog-script-inlining.test.ts scripts/catalog-detail.test.ts scripts/generate-catalog-pages.test.ts scripts/verify-catalog-payloads.test.ts scripts/registry-theme-fallbacks.test.ts scripts/registry-skill-files.test.ts scripts/creator-editing-capabilities.test.mjs scripts/generate-catalog-previews.test.ts scripts/registry-primitive-payloads.test.ts registry/components/pan-stations/pan-stations.test.mjs registry/components/filmed-screen/filmed-screen.test.mjs registry/components/echo-smear/echo-smear.test.mjs registry/examples/path-traced-3d/source/path-traced-3d.test.mjs && vitest run scripts/catalog/ scripts/contrastRatchet.test.ts scripts/generate-catalog-payloads.test.ts", "typecheck:scripts": "tsc --noEmit -p scripts/tsconfig.json", "test:skills": "HYPERFRAMES_MEDIA_HOME_REQUIRED=1 node --import ./packages/cli/scripts/test-home.mjs --test 'skills/**/*.test.mjs' 'packages/cli/src/media-use/**/*.test.mjs'", "generate:previews": "tsx scripts/generate-template-previews.ts", diff --git a/packages/cli/src/docs/examples.md b/packages/cli/src/docs/examples.md index 92d69011e5..9638a463e4 100644 --- a/packages/cli/src/docs/examples.md +++ b/packages/cli/src/docs/examples.md @@ -18,6 +18,10 @@ Bold kinetic typography promo. Animated data chart in print editorial style. +## path-traced-3d + +Three.js scene with a fast raster preview and an opt-in path-traced export. + ## play-mode Playful elastic animations. diff --git a/registry/examples/path-traced-3d/assets/render.js b/registry/examples/path-traced-3d/assets/render.js new file mode 100644 index 0000000000..7f3925e387 --- /dev/null +++ b/registry/examples/path-traced-3d/assets/render.js @@ -0,0 +1,142 @@ +// Draws the scene for HyperFrames, rasterized for quick previews or path traced for export. +// +// - Setup is one `window.__hf.buildReady` promise; the first seek waits for it. +// - Each `hf-seek` registers its frame with `event.detail.waitUntil`, so a frame is captured +// only once every sample for it is done. +// - Every new time starts a fresh accumulation with the same noise, so a time gives the same +// pixels whatever was drawn before it. Seeking again to the time on screen does no work. +import * as THREE from "./vendor/three-path-tracer.min.js"; +import { createScene } from "./scene.js"; + +const READY_KEY = "path-traced-3d"; +const root = document.querySelector("[data-composition-id]"); +const canvas = document.getElementById("pt-canvas"); +const width = Number(root.dataset.width); +const height = Number(root.dataset.height); + +const variables = window.__hyperframes?.getVariables?.() ?? {}; +const mode = variables.renderer === "path" ? "path" : "raster"; +const samples = Math.max(1, Math.round(Number(variables.samples) || 64)); +const bounces = Math.max(1, Math.round(Number(variables.bounces) || 4)); + +// While HyperFrames renders, the clock stands still and requestAnimationFrame callbacks wait +// until the first seek, and that seek waits for setup. So nothing here waits on a frame, the +// clock or a timer of its own, and nothing starts a render loop: setup and seeks only await +// the libraries' own promises, and every frame is drawn from the seek time alone. + +// three-gpu-pathtracer 0.0.24 reports shader compilation only as the `isCompiling` flag. The +// promise behind that flag is three's `renderer.compileAsync`, so await it directly rather than +// polling the flag. It only decides when drawing may start, never what is drawn. +function tracerCompiled() { + const compiling = tracer._pathTracer._compilePromise; + // Waiting on nothing here would spin renderSample() forever; fail loudly if a tracer upgrade + // moves the promise. + if (!compiling) + throw new Error("path-traced-3d: tracer is compiling but exposes no compile promise"); + return compiling; +} + +// Math.random decides two things the tracer bakes in: three's object uuids, which set the order +// lights, meshes and textures are sorted in, and the tracer's noise textures, built when it is +// constructed. With a fixed seed around both, every page (every render worker, every reload) +// draws the same grain. Only synchronous construction is covered: anything created later, such +// as a model loaded during setup, must be built under the seed too. +function withSeededRandom(seed, build) { + const nativeRandom = Math.random; + let state = seed >>> 0; + Math.random = () => { + state = (state + 0x6d2b79f5) >>> 0; + let t = state; + t = Math.imul(t ^ (t >>> 15), t | 1); + t ^= t + Math.imul(t ^ (t >>> 7), t | 61); + return ((t ^ (t >>> 14)) >>> 0) / 4294967296; + }; + try { + return build(); + } finally { + Math.random = nativeRandom; + } +} + +const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, preserveDrawingBuffer: true }); +renderer.setPixelRatio(1); +renderer.setSize(width, height, false); +renderer.toneMapping = THREE.ACESFilmicToneMapping; +renderer.shadowMap.enabled = true; +renderer.shadowMap.type = THREE.PCFSoftShadowMap; + +const { scene, camera, poseAt } = withSeededRandom(1, () => + createScene(THREE, { aspect: width / height }), +); +let tracer = null; +let shownTime = null; +const pixel = new Uint8Array(4); + +// gl.finish() can return before a software GPU has run the queued work; reading one pixel back +// cannot, so the frame (and the first, slowest shader run) is really done when this returns. +function waitForGpu() { + const gl = renderer.getContext(); + renderer.setRenderTarget(null); + gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixel); +} + +// Sampling is driven by an explicit count, never by time: the tracer's own delay and fade +// settings read a clock that does not move during a render. +async function trace(target) { + // Objects moved, so rebuild the tracer's copy of the scene; this also restarts accumulation. + tracer.setScene(scene, camera); + while (tracer.samples < target) { + tracer.renderSample(); + // The first call after a shader change starts a compile and draws nothing; wait for it. + if (tracer.isCompiling) await tracerCompiled(); + } +} + +// The first image a renderer draws differs from later ones (shader warm-up, first uploads), so +// setup draws one throwaway frame and leaves nothing marked as shown. +async function setup() { + poseAt(0); + if (mode === "raster") { + await renderer.compileAsync(scene, camera); + renderer.render(scene, camera); + waitForGpu(); + return; + } + tracer = withSeededRandom(2, () => new THREE.WebGLPathTracer(renderer)); + // No delay, fade or low-resolution stand-in: those depend on elapsed time. + tracer.renderDelay = 0; + tracer.fadeDuration = 0; + tracer.minSamples = 1; + tracer.dynamicLowRes = false; + tracer.rasterizeScene = false; + tracer.stableNoise = true; + tracer.bounces = bounces; + tracer.filterGlossyFactor = 0.5; + await trace(samples); + waitForGpu(); +} + +async function draw(time) { + if (time === shownTime) return; + shownTime = null; + poseAt(time); + if (mode === "path") await trace(samples); + else renderer.render(scene, camera); + waitForGpu(); + shownTime = time; +} + +const ready = setup(); +window.__hf = window.__hf || {}; +window.__hf.buildReady = window.__hf.buildReady || {}; +window.__hf.buildReady[READY_KEY] = ready; + +let queue = ready; +window.addEventListener("hf-seek", (event) => { + const { time } = event.detail; + queue = queue + .catch(() => {}) + .then(() => ready) + .then(() => draw(time)); + event.detail.waitUntil(queue); +}); diff --git a/registry/examples/path-traced-3d/assets/scene.js b/registry/examples/path-traced-3d/assets/scene.js new file mode 100644 index 0000000000..63392ccea5 --- /dev/null +++ b/registry/examples/path-traced-3d/assets/scene.js @@ -0,0 +1,119 @@ +// The scene: a few PBR objects on a plinth under a soft spotlight. Edit freely. +// `poseAt(t)` is the only thing that moves anything, and it reads nothing but `t`, +// so any frame can be drawn on its own and in any order. + +export const DURATION = 6; + +export function createScene(THREE, { aspect }) { + const scene = new THREE.Scene(); + scene.background = new THREE.Color("#0e1115"); + scene.environment = studioEnvironment(THREE); + scene.environmentIntensity = 0.55; + + const camera = new THREE.PerspectiveCamera(30, aspect, 0.1, 200); + + const floorMat = new THREE.MeshStandardMaterial({ color: "#121418", roughness: 0.9 }); + const plinthMat = new THREE.MeshStandardMaterial({ color: "#3a3d42", roughness: 0.6 }); + const gold = new THREE.MeshStandardMaterial({ color: "#d9a94e", metalness: 1, roughness: 0.3 }); + const chrome = new THREE.MeshStandardMaterial({ + color: "#c9ced4", + metalness: 1, + roughness: 0.12, + }); + const ceramic = new THREE.MeshPhysicalMaterial({ + color: "#ece6db", + roughness: 0.4, + clearcoat: 1, + clearcoatRoughness: 0.1, + }); + const lacquer = new THREE.MeshStandardMaterial({ color: "#b23a2e", roughness: 0.45 }); + + function add(geometry, material, x = 0, y = 0, z = 0) { + const mesh = new THREE.Mesh(geometry, material); + mesh.position.set(x, y, z); + mesh.castShadow = true; + mesh.receiveShadow = true; + scene.add(mesh); + return mesh; + } + + const floor = add(new THREE.PlaneGeometry(120, 120), floorMat); + floor.rotation.x = -Math.PI / 2; + add(new THREE.CylinderGeometry(2.1, 2.2, 0.5, 96), plinthMat, 0, 0.25, 0); + + const knot = add(new THREE.TorusKnotGeometry(0.5, 0.17, 220, 32), gold); + const orbiters = [ + { mesh: add(new THREE.SphereGeometry(0.38, 64, 32), ceramic), phase: 0, radius: 1.45, y: 0.88 }, + { + mesh: add(new THREE.BoxGeometry(0.52, 0.52, 0.52), lacquer), + phase: 2.1, + radius: 1.5, + y: 0.76, + }, + { mesh: add(new THREE.SphereGeometry(0.26, 64, 32), chrome), phase: 4.2, radius: 1.4, y: 0.76 }, + ]; + + // PhysicalSpotLight is a three SpotLight with a radius, so the tracer draws soft shadows + // from it and the raster renderer still treats it as an ordinary spotlight. + const key = new THREE.PhysicalSpotLight("#ffe3bd", 140); + key.position.set(-4, 6.5, 3.5); + key.angle = 0.55; + key.penumbra = 0.45; + key.radius = 0.5; + key.castShadow = true; + key.shadow.mapSize.set(1024, 1024); + key.shadow.bias = -0.0002; + key.target.position.set(0, 0.8, 0); + scene.add(key, key.target); + + const rim = new THREE.DirectionalLight("#bcd2ff", 1.1); + rim.position.set(4, 4, -5); + scene.add(rim); + + function poseAt(t) { + const p = Math.min(Math.max(t / DURATION, 0), 1); + const eased = p * p * (3 - 2 * p); + + knot.position.set(0, 1.5 + 0.08 * Math.sin(t * 1.3), 0); + knot.rotation.set(0.35, t * 0.9, 0.15 * Math.sin(t * 0.7)); + for (const { mesh, phase, radius, y } of orbiters) { + const angle = phase + t * 0.55; + mesh.position.set(Math.cos(angle) * radius, y, Math.sin(angle) * radius); + mesh.rotation.set(t * 0.4, angle, 0); + } + + const orbit = -0.55 + 1.0 * eased; + const distance = 7.4 - 1.6 * eased; + camera.position.set(Math.sin(orbit) * distance, 2.7 - 0.6 * eased, Math.cos(orbit) * distance); + camera.lookAt(0, 1.05, 0); + camera.updateMatrixWorld(); + scene.updateMatrixWorld(true); + } + + return { scene, camera, poseAt }; +} + +// A dark studio with two soft light strips, as a float equirect texture both renderers can use. +function studioEnvironment(THREE) { + const width = 256; + const height = 128; + const pixels = new Float32Array(width * height * 4); + for (let y = 0; y < height; y++) { + for (let x = 0; x < width; x++) { + const u = x / width; + const v = y / height; + const warm = Math.exp(-(((u - 0.2) / 0.06) ** 4) - ((v - 0.32) / 0.12) ** 4) * 4; + const cool = Math.exp(-(((u - 0.7) / 0.04) ** 4) - ((v - 0.38) / 0.16) ** 4) * 2.2; + const base = 0.05 + 0.08 * Math.max(0, Math.cos(v * Math.PI)); + const i = (y * width + x) * 4; + pixels[i] = base + warm + cool * 0.7; + pixels[i + 1] = base + warm * 0.86 + cool * 0.85; + pixels[i + 2] = base + warm * 0.66 + cool; + pixels[i + 3] = 1; + } + } + const texture = new THREE.DataTexture(pixels, width, height, THREE.RGBAFormat, THREE.FloatType); + texture.mapping = THREE.EquirectangularReflectionMapping; + texture.needsUpdate = true; + return texture; +} diff --git a/registry/examples/path-traced-3d/assets/vendor/README.md b/registry/examples/path-traced-3d/assets/vendor/README.md new file mode 100644 index 0000000000..f19dec8d48 --- /dev/null +++ b/registry/examples/path-traced-3d/assets/vendor/README.md @@ -0,0 +1,20 @@ +# Vendored 3D libraries + +`three-path-tracer.min.js` is one local ES module, so the project renders without any network +access. It re-exports all of three plus these classes from three-gpu-pathtracer: +`WebGLPathTracer`, `PhysicalSpotLight`, `ShapedAreaLight`, `PhysicalCamera`, `DenoiseMaterial` +and `GradientEquirectTexture`. + +| Package | Version | Licence | +| -------------------- | ------- | --------------------------------------- | +| three | 0.180.0 | MIT, `three.LICENSE.txt` | +| three-gpu-pathtracer | 0.0.24 | MIT, `three-gpu-pathtracer.LICENSE.txt` | +| three-mesh-bvh | 0.9.5 | MIT, `three-mesh-bvh.LICENSE.txt` | + +Built with esbuild 0.25.12 (`--bundle --format=esm --minify --target=es2020`). SHA-256 of the +bundle: `a247cb7f88eff8b1d423a2892e5ca27c7d03d83939fe0ca6fa9a11c7f9f21fc9`. + +To rebuild it, or to change the versions, use the `source/` folder of this example in the +HyperFrames repository +(https://github.com/heygen-com/hyperframes/tree/main/registry/examples/path-traced-3d/source): +`npm ci && npm run build`. The same pinned versions produce the same file. diff --git a/registry/examples/path-traced-3d/assets/vendor/three-gpu-pathtracer.LICENSE.txt b/registry/examples/path-traced-3d/assets/vendor/three-gpu-pathtracer.LICENSE.txt new file mode 100644 index 0000000000..950920d1ed --- /dev/null +++ b/registry/examples/path-traced-3d/assets/vendor/three-gpu-pathtracer.LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Garrett Johnson + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/registry/examples/path-traced-3d/assets/vendor/three-mesh-bvh.LICENSE.txt b/registry/examples/path-traced-3d/assets/vendor/three-mesh-bvh.LICENSE.txt new file mode 100644 index 0000000000..1ef1648d29 --- /dev/null +++ b/registry/examples/path-traced-3d/assets/vendor/three-mesh-bvh.LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Garrett Johnson + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/registry/examples/path-traced-3d/assets/vendor/three-path-tracer.min.js b/registry/examples/path-traced-3d/assets/vendor/three-path-tracer.min.js new file mode 100644 index 0000000000..c8a417edb4 --- /dev/null +++ b/registry/examples/path-traced-3d/assets/vendor/three-path-tracer.min.js @@ -0,0 +1,8111 @@ +var Gv=Object.defineProperty;var Wv=(r,t)=>{for(var e in t)Gv(r,e,{get:t[e],enumerable:!0})};var ca="180",Xv={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2},qv={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},mg=0,Ld=1,gg=2,Yv=3,$v=0,Nd=1,xg=2,oi=3,yn=0,He=1,Sn=2,ke=0,Yn=1,la=2,Ud=3,Bd=4,vg=5,Ni=100,_g=101,yg=102,bg=103,Sg=104,Mg=200,Tg=201,wg=202,Ag=203,Rc=204,Cc=205,Eg=206,Rg=207,Cg=208,Ig=209,Pg=210,Dg=211,Fg=212,Lg=213,Ng=214,zl=0,kl=1,Vl=2,_r=3,Hl=4,Gl=5,Wl=6,Xl=7,ua=0,Ug=1,Bg=2,Zn=0,Og=1,zg=2,kg=3,Vg=4,Hg=5,Gg=6,Wg=7,bf="attached",Xg="detached",ql=300,Si=301,Vi=302,Mi=303,ha=304,Ns=306,Ke=1e3,we=1001,Ao=1002,Vt=1003,Od=1004,Zv=1004,Us=1005,Jv=1005,re=1006,fa=1007,Kv=1007,ai=1008,zd=1008,on=1009,Bs=1010,da=1011,Hi=1012,Gi=1013,an=1014,$t=1015,Ge=1016,Yl=1017,$l=1018,Os=1020,kd=35902,Vd=35899,Hd=1021,Gd=1022,Gt=1023,xs=1026,zs=1027,Jn=1028,Dr=1029,Fr=1030,Wi=1031,Qv=1032,Xi=1033,pa=33776,ma=33777,ga=33778,xa=33779,Zl=35840,Jl=35841,Kl=35842,Ql=35843,jl=36196,tu=37492,eu=37496,nu=37808,iu=37809,ru=37810,su=37811,ou=37812,au=37813,cu=37814,lu=37815,uu=37816,hu=37817,fu=37818,du=37819,pu=37820,mu=37821,gu=36492,xu=36494,vu=36495,_u=36283,yu=36284,bu=36285,Su=36286,qg=2200,Yg=2201,$g=2202,Eo=2300,Ic=2301,Ec=2302,mr=2400,gr=2401,Ro=2402,Mu=2500,Wd=2501,jv=0,t_=1,e_=2,Zg=3200,Jg=3201,n_=3202,i_=3203,qi=0,Kg=1,Ti="",vn="srgb",yr="srgb-linear",Co="linear",me="srgb",r_=0,pr=7680,s_=7681,o_=7682,a_=7683,c_=34055,l_=34056,u_=5386,h_=512,f_=513,d_=514,p_=515,m_=516,g_=517,x_=518,Sf=519,Qg=512,jg=513,t0=514,Xd=515,e0=516,n0=517,i0=518,r0=519,Io=35044,v_=35048,__=35040,y_=35045,b_=35049,S_=35041,M_=35046,T_=35050,w_=35042,A_="100",qd="300 es",Rn=2e3,vs=2001,E_={COMPUTE:"compute",RENDER:"render"},R_={PERSPECTIVE:"perspective",LINEAR:"linear",FLAT:"flat"},C_={NORMAL:"normal",CENTROID:"centroid",SAMPLE:"sample",FIRST:"first",EITHER:"either"},On=class{addEventListener(t,e){this._listeners===void 0&&(this._listeners={});let n=this._listeners;n[t]===void 0&&(n[t]=[]),n[t].indexOf(e)===-1&&n[t].push(e)}hasEventListener(t,e){let n=this._listeners;return n===void 0?!1:n[t]!==void 0&&n[t].indexOf(e)!==-1}removeEventListener(t,e){let n=this._listeners;if(n===void 0)return;let i=n[t];if(i!==void 0){let s=i.indexOf(e);s!==-1&&i.splice(s,1)}}dispatchEvent(t){let e=this._listeners;if(e===void 0)return;let n=e[t.type];if(n!==void 0){t.target=this;let i=n.slice(0);for(let s=0,o=i.length;s>8&255]+en[r>>16&255]+en[r>>24&255]+"-"+en[t&255]+en[t>>8&255]+"-"+en[t>>16&15|64]+en[t>>24&255]+"-"+en[e&63|128]+en[e>>8&255]+"-"+en[e>>16&255]+en[e>>24&255]+en[n&255]+en[n>>8&255]+en[n>>16&255]+en[n>>24&255]).toLowerCase()}function Bt(r,t,e){return Math.max(t,Math.min(e,r))}function Yd(r,t){return(r%t+t)%t}function I_(r,t,e,n,i){return n+(r-t)*(i-n)/(e-t)}function P_(r,t,e){return r!==t?(e-r)/(t-r):0}function Mo(r,t,e){return(1-e)*r+e*t}function D_(r,t,e,n){return Mo(r,t,1-Math.exp(-e*n))}function F_(r,t=1){return t-Math.abs(Yd(r,t*2)-t)}function L_(r,t,e){return r<=t?0:r>=e?1:(r=(r-t)/(e-t),r*r*(3-2*r))}function N_(r,t,e){return r<=t?0:r>=e?1:(r=(r-t)/(e-t),r*r*r*(r*(r*6-15)+10))}function U_(r,t){return r+Math.floor(Math.random()*(t-r+1))}function B_(r,t){return r+Math.random()*(t-r)}function O_(r){return r*(.5-Math.random())}function z_(r){r!==void 0&&(cm=r);let t=cm+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}function k_(r){return r*vr}function V_(r){return r*br}function H_(r){return(r&r-1)===0&&r!==0}function G_(r){return Math.pow(2,Math.ceil(Math.log(r)/Math.LN2))}function W_(r){return Math.pow(2,Math.floor(Math.log(r)/Math.LN2))}function X_(r,t,e,n,i){let s=Math.cos,o=Math.sin,a=s(e/2),c=o(e/2),l=s((t+n)/2),f=o((t+n)/2),h=s((t-n)/2),u=o((t-n)/2),d=s((n-t)/2),g=o((n-t)/2);switch(i){case"XYX":r.set(a*f,c*h,c*u,a*l);break;case"YZY":r.set(c*u,a*f,c*h,a*l);break;case"ZXZ":r.set(c*h,c*u,a*f,a*l);break;case"XZX":r.set(a*f,c*g,c*d,a*l);break;case"YXY":r.set(c*d,a*f,c*g,a*l);break;case"ZYZ":r.set(c*g,c*d,a*f,a*l);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+i)}}function hn(r,t){switch(t.constructor){case Float32Array:return r;case Uint32Array:return r/4294967295;case Uint16Array:return r/65535;case Uint8Array:return r/255;case Int32Array:return Math.max(r/2147483647,-1);case Int16Array:return Math.max(r/32767,-1);case Int8Array:return Math.max(r/127,-1);default:throw new Error("Invalid component type.")}}function Zt(r,t){switch(t.constructor){case Float32Array:return r;case Uint32Array:return Math.round(r*4294967295);case Uint16Array:return Math.round(r*65535);case Uint8Array:return Math.round(r*255);case Int32Array:return Math.round(r*2147483647);case Int16Array:return Math.round(r*32767);case Int8Array:return Math.round(r*127);default:throw new Error("Invalid component type.")}}var q_={DEG2RAD:vr,RAD2DEG:br,generateUUID:Cn,clamp:Bt,euclideanModulo:Yd,mapLinear:I_,inverseLerp:P_,lerp:Mo,damp:D_,pingpong:F_,smoothstep:L_,smootherstep:N_,randInt:U_,randFloat:B_,randFloatSpread:O_,seededRandom:z_,degToRad:k_,radToDeg:V_,isPowerOfTwo:H_,ceilPowerOfTwo:G_,floorPowerOfTwo:W_,setQuaternionFromProperEuler:X_,normalize:Zt,denormalize:hn},q=class r{constructor(t=0,e=0){r.prototype.isVector2=!0,this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){let e=this.x,n=this.y,i=t.elements;return this.x=i[0]*e+i[3]*n+i[6],this.y=i[1]*e+i[4]*n+i[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=Bt(this.x,t.x,e.x),this.y=Bt(this.y,t.y,e.y),this}clampScalar(t,e){return this.x=Bt(this.x,t,e),this.y=Bt(this.y,t,e),this}clampLength(t,e){let n=this.length();return this.divideScalar(n||1).multiplyScalar(Bt(n,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){let e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;let n=this.dot(t)/e;return Math.acos(Bt(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){let e=this.x-t.x,n=this.y-t.y;return e*e+n*n}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){let n=Math.cos(e),i=Math.sin(e),s=this.x-t.x,o=this.y-t.y;return this.x=s*n-o*i+t.x,this.y=s*i+o*n+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}},Ze=class{constructor(t=0,e=0,n=0,i=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=n,this._w=i}static slerpFlat(t,e,n,i,s,o,a){let c=n[i+0],l=n[i+1],f=n[i+2],h=n[i+3],u=s[o+0],d=s[o+1],g=s[o+2],x=s[o+3];if(a===0){t[e+0]=c,t[e+1]=l,t[e+2]=f,t[e+3]=h;return}if(a===1){t[e+0]=u,t[e+1]=d,t[e+2]=g,t[e+3]=x;return}if(h!==x||c!==u||l!==d||f!==g){let p=1-a,m=c*u+l*d+f*g+h*x,v=m>=0?1:-1,_=1-m*m;if(_>Number.EPSILON){let b=Math.sqrt(_),T=Math.atan2(b,m*v);p=Math.sin(p*T)/b,a=Math.sin(a*T)/b}let y=a*v;if(c=c*p+u*y,l=l*p+d*y,f=f*p+g*y,h=h*p+x*y,p===1-a){let b=1/Math.sqrt(c*c+l*l+f*f+h*h);c*=b,l*=b,f*=b,h*=b}}t[e]=c,t[e+1]=l,t[e+2]=f,t[e+3]=h}static multiplyQuaternionsFlat(t,e,n,i,s,o){let a=n[i],c=n[i+1],l=n[i+2],f=n[i+3],h=s[o],u=s[o+1],d=s[o+2],g=s[o+3];return t[e]=a*g+f*h+c*d-l*u,t[e+1]=c*g+f*u+l*h-a*d,t[e+2]=l*g+f*d+a*u-c*h,t[e+3]=f*g-a*h-c*u-l*d,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,n,i){return this._x=t,this._y=e,this._z=n,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){let n=t._x,i=t._y,s=t._z,o=t._order,a=Math.cos,c=Math.sin,l=a(n/2),f=a(i/2),h=a(s/2),u=c(n/2),d=c(i/2),g=c(s/2);switch(o){case"XYZ":this._x=u*f*h+l*d*g,this._y=l*d*h-u*f*g,this._z=l*f*g+u*d*h,this._w=l*f*h-u*d*g;break;case"YXZ":this._x=u*f*h+l*d*g,this._y=l*d*h-u*f*g,this._z=l*f*g-u*d*h,this._w=l*f*h+u*d*g;break;case"ZXY":this._x=u*f*h-l*d*g,this._y=l*d*h+u*f*g,this._z=l*f*g+u*d*h,this._w=l*f*h-u*d*g;break;case"ZYX":this._x=u*f*h-l*d*g,this._y=l*d*h+u*f*g,this._z=l*f*g-u*d*h,this._w=l*f*h+u*d*g;break;case"YZX":this._x=u*f*h+l*d*g,this._y=l*d*h+u*f*g,this._z=l*f*g-u*d*h,this._w=l*f*h-u*d*g;break;case"XZY":this._x=u*f*h-l*d*g,this._y=l*d*h-u*f*g,this._z=l*f*g+u*d*h,this._w=l*f*h+u*d*g;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+o)}return e===!0&&this._onChangeCallback(),this}setFromAxisAngle(t,e){let n=e/2,i=Math.sin(n);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(t){let e=t.elements,n=e[0],i=e[4],s=e[8],o=e[1],a=e[5],c=e[9],l=e[2],f=e[6],h=e[10],u=n+a+h;if(u>0){let d=.5/Math.sqrt(u+1);this._w=.25/d,this._x=(f-c)*d,this._y=(s-l)*d,this._z=(o-i)*d}else if(n>a&&n>h){let d=2*Math.sqrt(1+n-a-h);this._w=(f-c)/d,this._x=.25*d,this._y=(i+o)/d,this._z=(s+l)/d}else if(a>h){let d=2*Math.sqrt(1+a-n-h);this._w=(s-l)/d,this._x=(i+o)/d,this._y=.25*d,this._z=(c+f)/d}else{let d=2*Math.sqrt(1+h-n-a);this._w=(o-i)/d,this._x=(s+l)/d,this._y=(c+f)/d,this._z=.25*d}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let n=t.dot(e)+1;return n<1e-8?(n=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=n):(this._x=0,this._y=-t.z,this._z=t.y,this._w=n)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=n),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(Bt(this.dot(t),-1,1)))}rotateTowards(t,e){let n=this.angleTo(t);if(n===0)return this;let i=Math.min(1,e/n);return this.slerp(t,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return t===0?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){let n=t._x,i=t._y,s=t._z,o=t._w,a=e._x,c=e._y,l=e._z,f=e._w;return this._x=n*f+o*a+i*l-s*c,this._y=i*f+o*c+s*a-n*l,this._z=s*f+o*l+n*c-i*a,this._w=o*f-n*a-i*c-s*l,this._onChangeCallback(),this}slerp(t,e){if(e===0)return this;if(e===1)return this.copy(t);let n=this._x,i=this._y,s=this._z,o=this._w,a=o*t._w+n*t._x+i*t._y+s*t._z;if(a<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,a=-a):this.copy(t),a>=1)return this._w=o,this._x=n,this._y=i,this._z=s,this;let c=1-a*a;if(c<=Number.EPSILON){let d=1-e;return this._w=d*o+e*this._w,this._x=d*n+e*this._x,this._y=d*i+e*this._y,this._z=d*s+e*this._z,this.normalize(),this}let l=Math.sqrt(c),f=Math.atan2(l,a),h=Math.sin((1-e)*f)/l,u=Math.sin(e*f)/l;return this._w=o*h+this._w*u,this._x=n*h+this._x*u,this._y=i*h+this._y*u,this._z=s*h+this._z*u,this._onChangeCallback(),this}slerpQuaternions(t,e,n){return this.copy(t).slerp(e,n)}random(){let t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),n=Math.random(),i=Math.sqrt(1-n),s=Math.sqrt(n);return this.set(i*Math.sin(t),i*Math.cos(t),s*Math.sin(e),s*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}},R=class r{constructor(t=0,e=0,n=0){r.prototype.isVector3=!0,this.x=t,this.y=e,this.z=n}set(t,e,n){return n===void 0&&(n=this.z),this.x=t,this.y=e,this.z=n,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(lm.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(lm.setFromAxisAngle(t,e))}applyMatrix3(t){let e=this.x,n=this.y,i=this.z,s=t.elements;return this.x=s[0]*e+s[3]*n+s[6]*i,this.y=s[1]*e+s[4]*n+s[7]*i,this.z=s[2]*e+s[5]*n+s[8]*i,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){let e=this.x,n=this.y,i=this.z,s=t.elements,o=1/(s[3]*e+s[7]*n+s[11]*i+s[15]);return this.x=(s[0]*e+s[4]*n+s[8]*i+s[12])*o,this.y=(s[1]*e+s[5]*n+s[9]*i+s[13])*o,this.z=(s[2]*e+s[6]*n+s[10]*i+s[14])*o,this}applyQuaternion(t){let e=this.x,n=this.y,i=this.z,s=t.x,o=t.y,a=t.z,c=t.w,l=2*(o*i-a*n),f=2*(a*e-s*i),h=2*(s*n-o*e);return this.x=e+c*l+o*h-a*f,this.y=n+c*f+a*l-s*h,this.z=i+c*h+s*f-o*l,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){let e=this.x,n=this.y,i=this.z,s=t.elements;return this.x=s[0]*e+s[4]*n+s[8]*i,this.y=s[1]*e+s[5]*n+s[9]*i,this.z=s[2]*e+s[6]*n+s[10]*i,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=Bt(this.x,t.x,e.x),this.y=Bt(this.y,t.y,e.y),this.z=Bt(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=Bt(this.x,t,e),this.y=Bt(this.y,t,e),this.z=Bt(this.z,t,e),this}clampLength(t,e){let n=this.length();return this.divideScalar(n||1).multiplyScalar(Bt(n,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this.z=t.z+(e.z-t.z)*n,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){let n=t.x,i=t.y,s=t.z,o=e.x,a=e.y,c=e.z;return this.x=i*c-s*a,this.y=s*o-n*c,this.z=n*a-i*o,this}projectOnVector(t){let e=t.lengthSq();if(e===0)return this.set(0,0,0);let n=t.dot(this)/e;return this.copy(t).multiplyScalar(n)}projectOnPlane(t){return Uh.copy(this).projectOnVector(t),this.sub(Uh)}reflect(t){return this.sub(Uh.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){let e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;let n=this.dot(t)/e;return Math.acos(Bt(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){let e=this.x-t.x,n=this.y-t.y,i=this.z-t.z;return e*e+n*n+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,n){let i=Math.sin(e)*t;return this.x=i*Math.sin(n),this.y=Math.cos(e)*t,this.z=i*Math.cos(n),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,n){return this.x=t*Math.sin(e),this.y=n,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){let e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){let e=this.setFromMatrixColumn(t,0).length(),n=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=n,this.z=i,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,e*4)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,e*3)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){let t=Math.random()*Math.PI*2,e=Math.random()*2-1,n=Math.sqrt(1-e*e);return this.x=n*Math.cos(t),this.y=e,this.z=n*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}},Uh=new R,lm=new Ze,Xt=class r{constructor(t,e,n,i,s,o,a,c,l){r.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,e,n,i,s,o,a,c,l)}set(t,e,n,i,s,o,a,c,l){let f=this.elements;return f[0]=t,f[1]=i,f[2]=a,f[3]=e,f[4]=s,f[5]=c,f[6]=n,f[7]=o,f[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){let e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],this}extractBasis(t,e,n){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),n.setFromMatrix3Column(this,2),this}setFromMatrix4(t){let e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){let n=t.elements,i=e.elements,s=this.elements,o=n[0],a=n[3],c=n[6],l=n[1],f=n[4],h=n[7],u=n[2],d=n[5],g=n[8],x=i[0],p=i[3],m=i[6],v=i[1],_=i[4],y=i[7],b=i[2],T=i[5],w=i[8];return s[0]=o*x+a*v+c*b,s[3]=o*p+a*_+c*T,s[6]=o*m+a*y+c*w,s[1]=l*x+f*v+h*b,s[4]=l*p+f*_+h*T,s[7]=l*m+f*y+h*w,s[2]=u*x+d*v+g*b,s[5]=u*p+d*_+g*T,s[8]=u*m+d*y+g*w,this}multiplyScalar(t){let e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){let t=this.elements,e=t[0],n=t[1],i=t[2],s=t[3],o=t[4],a=t[5],c=t[6],l=t[7],f=t[8];return e*o*f-e*a*l-n*s*f+n*a*c+i*s*l-i*o*c}invert(){let t=this.elements,e=t[0],n=t[1],i=t[2],s=t[3],o=t[4],a=t[5],c=t[6],l=t[7],f=t[8],h=f*o-a*l,u=a*c-f*s,d=l*s-o*c,g=e*h+n*u+i*d;if(g===0)return this.set(0,0,0,0,0,0,0,0,0);let x=1/g;return t[0]=h*x,t[1]=(i*l-f*n)*x,t[2]=(a*n-i*o)*x,t[3]=u*x,t[4]=(f*e-i*c)*x,t[5]=(i*s-a*e)*x,t[6]=d*x,t[7]=(n*c-l*e)*x,t[8]=(o*e-n*s)*x,this}transpose(){let t,e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){let e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,n,i,s,o,a){let c=Math.cos(s),l=Math.sin(s);return this.set(n*c,n*l,-n*(c*o+l*a)+o+t,-i*l,i*c,-i*(-l*o+c*a)+a+e,0,0,1),this}scale(t,e){return this.premultiply(Bh.makeScale(t,e)),this}rotate(t){return this.premultiply(Bh.makeRotation(-t)),this}translate(t,e){return this.premultiply(Bh.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){let e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,n,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){let e=this.elements,n=t.elements;for(let i=0;i<9;i++)if(e[i]!==n[i])return!1;return!0}fromArray(t,e=0){for(let n=0;n<9;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){let n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t}clone(){return new this.constructor().fromArray(this.elements)}},Bh=new Xt;function $d(r){for(let t=r.length-1;t>=0;--t)if(r[t]>=65535)return!0;return!1}var Y_={Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array};function ms(r,t){return new Y_[r](t)}function _s(r){return document.createElementNS("http://www.w3.org/1999/xhtml",r)}function s0(){let r=_s("canvas");return r.style.display="block",r}var um={};function ys(r){r in um||(um[r]=!0,console.warn(r))}function o0(r,t,e){return new Promise(function(n,i){function s(){switch(r.clientWaitSync(t,r.SYNC_FLUSH_COMMANDS_BIT,0)){case r.WAIT_FAILED:i();break;case r.TIMEOUT_EXPIRED:setTimeout(s,e);break;default:n()}}setTimeout(s,e)})}var hm=new Xt().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),fm=new Xt().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function $_(){let r={enabled:!0,workingColorSpace:yr,spaces:{},convert:function(i,s,o){return this.enabled===!1||s===o||!s||!o||(this.spaces[s].transfer===me&&(i.r=vi(i.r),i.g=vi(i.g),i.b=vi(i.b)),this.spaces[s].primaries!==this.spaces[o].primaries&&(i.applyMatrix3(this.spaces[s].toXYZ),i.applyMatrix3(this.spaces[o].fromXYZ)),this.spaces[o].transfer===me&&(i.r=gs(i.r),i.g=gs(i.g),i.b=gs(i.b))),i},workingToColorSpace:function(i,s){return this.convert(i,this.workingColorSpace,s)},colorSpaceToWorking:function(i,s){return this.convert(i,s,this.workingColorSpace)},getPrimaries:function(i){return this.spaces[i].primaries},getTransfer:function(i){return i===Ti?Co:this.spaces[i].transfer},getToneMappingMode:function(i){return this.spaces[i].outputColorSpaceConfig.toneMappingMode||"standard"},getLuminanceCoefficients:function(i,s=this.workingColorSpace){return i.fromArray(this.spaces[s].luminanceCoefficients)},define:function(i){Object.assign(this.spaces,i)},_getMatrix:function(i,s,o){return i.copy(this.spaces[s].toXYZ).multiply(this.spaces[o].fromXYZ)},_getDrawingBufferColorSpace:function(i){return this.spaces[i].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(i=this.workingColorSpace){return this.spaces[i].workingColorSpaceConfig.unpackColorSpace},fromWorkingColorSpace:function(i,s){return ys("THREE.ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),r.workingToColorSpace(i,s)},toWorkingColorSpace:function(i,s){return ys("THREE.ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),r.colorSpaceToWorking(i,s)}},t=[.64,.33,.3,.6,.15,.06],e=[.2126,.7152,.0722],n=[.3127,.329];return r.define({[yr]:{primaries:t,whitePoint:n,transfer:Co,toXYZ:hm,fromXYZ:fm,luminanceCoefficients:e,workingColorSpaceConfig:{unpackColorSpace:vn},outputColorSpaceConfig:{drawingBufferColorSpace:vn}},[vn]:{primaries:t,whitePoint:n,transfer:me,toXYZ:hm,fromXYZ:fm,luminanceCoefficients:e,outputColorSpaceConfig:{drawingBufferColorSpace:vn}}}),r}var ie=$_();function vi(r){return r<.04045?r*.0773993808:Math.pow(r*.9478672986+.0521327014,2.4)}function gs(r){return r<.0031308?r*12.92:1.055*Math.pow(r,.41666)-.055}var Zr,Pc=class{static getDataURL(t,e="image/png"){if(/^data:/i.test(t.src)||typeof HTMLCanvasElement>"u")return t.src;let n;if(t instanceof HTMLCanvasElement)n=t;else{Zr===void 0&&(Zr=_s("canvas")),Zr.width=t.width,Zr.height=t.height;let i=Zr.getContext("2d");t instanceof ImageData?i.putImageData(t,0,0):i.drawImage(t,0,0,t.width,t.height),n=Zr}return n.toDataURL(e)}static sRGBToLinear(t){if(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap){let e=_s("canvas");e.width=t.width,e.height=t.height;let n=e.getContext("2d");n.drawImage(t,0,0,t.width,t.height);let i=n.getImageData(0,0,t.width,t.height),s=i.data;for(let o=0;o1),this.pmremVersion=0}get width(){return this.source.getSize(zh).x}get height(){return this.source.getSize(zh).y}get depth(){return this.source.getSize(zh).z}get image(){return this.source.data}set image(t=null){this.source.data=t}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(t){return this.name=t.name,this.source=t.source,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.channel=t.channel,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.internalFormat=t.internalFormat,this.type=t.type,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.center.copy(t.center),this.rotation=t.rotation,this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrix.copy(t.matrix),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.colorSpace=t.colorSpace,this.renderTarget=t.renderTarget,this.isRenderTargetTexture=t.isRenderTargetTexture,this.isArrayTexture=t.isArrayTexture,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}setValues(t){for(let e in t){let n=t[e];if(n===void 0){console.warn(`THREE.Texture.setValues(): parameter '${e}' has value of undefined.`);continue}let i=this[e];if(i===void 0){console.warn(`THREE.Texture.setValues(): property '${e}' does not exist.`);continue}i&&n&&i.isVector2&&n.isVector2||i&&n&&i.isVector3&&n.isVector3||i&&n&&i.isMatrix3&&n.isMatrix3?i.copy(n):this[e]=n}}toJSON(t){let e=t===void 0||typeof t=="string";if(!e&&t.textures[this.uuid]!==void 0)return t.textures[this.uuid];let n={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(t).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(n.userData=this.userData),e||(t.textures[this.uuid]=n),n}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==ql)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case Ke:t.x=t.x-Math.floor(t.x);break;case we:t.x=t.x<0?0:1;break;case Ao:Math.abs(Math.floor(t.x)%2)===1?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x);break}if(t.y<0||t.y>1)switch(this.wrapT){case Ke:t.y=t.y-Math.floor(t.y);break;case we:t.y=t.y<0?0:1;break;case Ao:Math.abs(Math.floor(t.y)%2)===1?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y);break}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){t===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){t===!0&&this.pmremVersion++}};Oe.DEFAULT_IMAGE=null;Oe.DEFAULT_MAPPING=ql;Oe.DEFAULT_ANISOTROPY=1;var Kt=class r{constructor(t=0,e=0,n=0,i=1){r.prototype.isVector4=!0,this.x=t,this.y=e,this.z=n,this.w=i}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,n,i){return this.x=t,this.y=e,this.z=n,this.w=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w!==void 0?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){let e=this.x,n=this.y,i=this.z,s=this.w,o=t.elements;return this.x=o[0]*e+o[4]*n+o[8]*i+o[12]*s,this.y=o[1]*e+o[5]*n+o[9]*i+o[13]*s,this.z=o[2]*e+o[6]*n+o[10]*i+o[14]*s,this.w=o[3]*e+o[7]*n+o[11]*i+o[15]*s,this}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this.w/=t.w,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);let e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,n,i,s,c=t.elements,l=c[0],f=c[4],h=c[8],u=c[1],d=c[5],g=c[9],x=c[2],p=c[6],m=c[10];if(Math.abs(f-u)<.01&&Math.abs(h-x)<.01&&Math.abs(g-p)<.01){if(Math.abs(f+u)<.1&&Math.abs(h+x)<.1&&Math.abs(g+p)<.1&&Math.abs(l+d+m-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;let _=(l+1)/2,y=(d+1)/2,b=(m+1)/2,T=(f+u)/4,w=(h+x)/4,E=(g+p)/4;return _>y&&_>b?_<.01?(n=0,i=.707106781,s=.707106781):(n=Math.sqrt(_),i=T/n,s=w/n):y>b?y<.01?(n=.707106781,i=0,s=.707106781):(i=Math.sqrt(y),n=T/i,s=E/i):b<.01?(n=.707106781,i=.707106781,s=0):(s=Math.sqrt(b),n=w/s,i=E/s),this.set(n,i,s,e),this}let v=Math.sqrt((p-g)*(p-g)+(h-x)*(h-x)+(u-f)*(u-f));return Math.abs(v)<.001&&(v=1),this.x=(p-g)/v,this.y=(h-x)/v,this.z=(u-f)/v,this.w=Math.acos((l+d+m-1)/2),this}setFromMatrixPosition(t){let e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this.w=e[15],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,e){return this.x=Bt(this.x,t.x,e.x),this.y=Bt(this.y,t.y,e.y),this.z=Bt(this.z,t.z,e.z),this.w=Bt(this.w,t.w,e.w),this}clampScalar(t,e){return this.x=Bt(this.x,t,e),this.y=Bt(this.y,t,e),this.z=Bt(this.z,t,e),this.w=Bt(this.w,t,e),this}clampLength(t,e){let n=this.length();return this.divideScalar(n||1).multiplyScalar(Bt(n,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this.z=t.z+(e.z-t.z)*n,this.w=t.w+(e.w-t.w)*n,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this.w=t.getW(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}},Po=class extends On{constructor(t=1,e=1,n={}){super(),n=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:re,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1,depth:1,multiview:!1},n),this.isRenderTarget=!0,this.width=t,this.height=e,this.depth=n.depth,this.scissor=new Kt(0,0,t,e),this.scissorTest=!1,this.viewport=new Kt(0,0,t,e);let i={width:t,height:e,depth:n.depth},s=new Oe(i);this.textures=[];let o=n.count;for(let a=0;a1;this.dispose()}this.viewport.set(0,0,t,e),this.scissor.set(0,0,t,e)}clone(){return new this.constructor().copy(this)}copy(t){this.width=t.width,this.height=t.height,this.depth=t.depth,this.scissor.copy(t.scissor),this.scissorTest=t.scissorTest,this.viewport.copy(t.viewport),this.textures.length=0;for(let e=0,n=t.textures.length;e=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y&&t.max.z>=this.min.z&&t.min.z<=this.max.z}intersectsSphere(t){return this.clampPoint(t.center,Gn),Gn.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,n;return t.normal.x>0?(e=t.normal.x*this.min.x,n=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,n=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,n+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,n+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,n+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,n+=t.normal.z*this.min.z),e<=-t.constant&&n>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(co),ka.subVectors(this.max,co),Jr.subVectors(t.a,co),Kr.subVectors(t.b,co),Qr.subVectors(t.c,co),Ei.subVectors(Kr,Jr),Ri.subVectors(Qr,Kr),nr.subVectors(Jr,Qr);let e=[0,-Ei.z,Ei.y,0,-Ri.z,Ri.y,0,-nr.z,nr.y,Ei.z,0,-Ei.x,Ri.z,0,-Ri.x,nr.z,0,-nr.x,-Ei.y,Ei.x,0,-Ri.y,Ri.x,0,-nr.y,nr.x,0];return!kh(e,Jr,Kr,Qr,ka)||(e=[1,0,0,0,1,0,0,0,1],!kh(e,Jr,Kr,Qr,ka))?!1:(Va.crossVectors(Ei,Ri),e=[Va.x,Va.y,Va.z],kh(e,Jr,Kr,Qr,ka))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Gn).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=this.getSize(Gn).length()*.5),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()?this:(hi[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),hi[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),hi[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),hi[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),hi[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),hi[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),hi[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),hi[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(hi),this)}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(t){return this.min.fromArray(t.min),this.max.fromArray(t.max),this}},hi=[new R,new R,new R,new R,new R,new R,new R,new R],Gn=new R,za=new se,Jr=new R,Kr=new R,Qr=new R,Ei=new R,Ri=new R,nr=new R,co=new R,ka=new R,Va=new R,ir=new R;function kh(r,t,e,n,i){for(let s=0,o=r.length-3;s<=o;s+=3){ir.fromArray(r,s);let a=i.x*Math.abs(ir.x)+i.y*Math.abs(ir.y)+i.z*Math.abs(ir.z),c=t.dot(ir),l=e.dot(ir),f=n.dot(ir);if(Math.max(-Math.max(c,l,f),Math.min(c,l,f))>a)return!1}return!0}var K_=new se,lo=new R,Vh=new R,Ve=class{constructor(t=new R,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){let n=this.center;e!==void 0?n.copy(e):K_.setFromPoints(t).getCenter(n);let i=0;for(let s=0,o=t.length;sthis.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;lo.subVectors(t,this.center);let e=lo.lengthSq();if(e>this.radius*this.radius){let n=Math.sqrt(e),i=(n-this.radius)*.5;this.center.addScaledVector(lo,i/n),this.radius+=i}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(this.center.equals(t.center)===!0?this.radius=Math.max(this.radius,t.radius):(Vh.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(lo.copy(t.center).add(Vh)),this.expandByPoint(lo.copy(t.center).sub(Vh))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(t){return this.radius=t.radius,this.center.fromArray(t.center),this}},fi=new R,Hh=new R,Ha=new R,Ci=new R,Gh=new R,Ga=new R,Wh=new R,ii=class{constructor(t=new R,e=new R(0,0,-1)){this.origin=t,this.direction=e}set(t,e){return this.origin.copy(t),this.direction.copy(e),this}copy(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this}at(t,e){return e.copy(this.origin).addScaledVector(this.direction,t)}lookAt(t){return this.direction.copy(t).sub(this.origin).normalize(),this}recast(t){return this.origin.copy(this.at(t,fi)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);let n=e.dot(this.direction);return n<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,n)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){let e=fi.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(fi.copy(this.origin).addScaledVector(this.direction,e),fi.distanceToSquared(t))}distanceSqToSegment(t,e,n,i){Hh.copy(t).add(e).multiplyScalar(.5),Ha.copy(e).sub(t).normalize(),Ci.copy(this.origin).sub(Hh);let s=t.distanceTo(e)*.5,o=-this.direction.dot(Ha),a=Ci.dot(this.direction),c=-Ci.dot(Ha),l=Ci.lengthSq(),f=Math.abs(1-o*o),h,u,d,g;if(f>0)if(h=o*c-a,u=o*a-c,g=s*f,h>=0)if(u>=-g)if(u<=g){let x=1/f;h*=x,u*=x,d=h*(h+o*u+2*a)+u*(o*h+u+2*c)+l}else u=s,h=Math.max(0,-(o*u+a)),d=-h*h+u*(u+2*c)+l;else u=-s,h=Math.max(0,-(o*u+a)),d=-h*h+u*(u+2*c)+l;else u<=-g?(h=Math.max(0,-(-o*s+a)),u=h>0?-s:Math.min(Math.max(-s,-c),s),d=-h*h+u*(u+2*c)+l):u<=g?(h=0,u=Math.min(Math.max(-s,-c),s),d=u*(u+2*c)+l):(h=Math.max(0,-(o*s+a)),u=h>0?s:Math.min(Math.max(-s,-c),s),d=-h*h+u*(u+2*c)+l);else u=o>0?-s:s,h=Math.max(0,-(o*u+a)),d=-h*h+u*(u+2*c)+l;return n&&n.copy(this.origin).addScaledVector(this.direction,h),i&&i.copy(Hh).addScaledVector(Ha,u),d}intersectSphere(t,e){fi.subVectors(t.center,this.origin);let n=fi.dot(this.direction),i=fi.dot(fi)-n*n,s=t.radius*t.radius;if(i>s)return null;let o=Math.sqrt(s-i),a=n-o,c=n+o;return c<0?null:a<0?this.at(c,e):this.at(a,e)}intersectsSphere(t){return t.radius<0?!1:this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){let e=t.normal.dot(this.direction);if(e===0)return t.distanceToPoint(this.origin)===0?0:null;let n=-(this.origin.dot(t.normal)+t.constant)/e;return n>=0?n:null}intersectPlane(t,e){let n=this.distanceToPlane(t);return n===null?null:this.at(n,e)}intersectsPlane(t){let e=t.distanceToPoint(this.origin);return e===0||t.normal.dot(this.direction)*e<0}intersectBox(t,e){let n,i,s,o,a,c,l=1/this.direction.x,f=1/this.direction.y,h=1/this.direction.z,u=this.origin;return l>=0?(n=(t.min.x-u.x)*l,i=(t.max.x-u.x)*l):(n=(t.max.x-u.x)*l,i=(t.min.x-u.x)*l),f>=0?(s=(t.min.y-u.y)*f,o=(t.max.y-u.y)*f):(s=(t.max.y-u.y)*f,o=(t.min.y-u.y)*f),n>o||s>i||((s>n||isNaN(n))&&(n=s),(o=0?(a=(t.min.z-u.z)*h,c=(t.max.z-u.z)*h):(a=(t.max.z-u.z)*h,c=(t.min.z-u.z)*h),n>c||a>i)||((a>n||n!==n)&&(n=a),(c=0?n:i,e)}intersectsBox(t){return this.intersectBox(t,fi)!==null}intersectTriangle(t,e,n,i,s){Gh.subVectors(e,t),Ga.subVectors(n,t),Wh.crossVectors(Gh,Ga);let o=this.direction.dot(Wh),a;if(o>0){if(i)return null;a=1}else if(o<0)a=-1,o=-o;else return null;Ci.subVectors(this.origin,t);let c=a*this.direction.dot(Ga.crossVectors(Ci,Ga));if(c<0)return null;let l=a*this.direction.dot(Gh.cross(Ci));if(l<0||c+l>o)return null;let f=-a*Ci.dot(Wh);return f<0?null:this.at(f/o,s)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}},gt=class r{constructor(t,e,n,i,s,o,a,c,l,f,h,u,d,g,x,p){r.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,e,n,i,s,o,a,c,l,f,h,u,d,g,x,p)}set(t,e,n,i,s,o,a,c,l,f,h,u,d,g,x,p){let m=this.elements;return m[0]=t,m[4]=e,m[8]=n,m[12]=i,m[1]=s,m[5]=o,m[9]=a,m[13]=c,m[2]=l,m[6]=f,m[10]=h,m[14]=u,m[3]=d,m[7]=g,m[11]=x,m[15]=p,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new r().fromArray(this.elements)}copy(t){let e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],e[9]=n[9],e[10]=n[10],e[11]=n[11],e[12]=n[12],e[13]=n[13],e[14]=n[14],e[15]=n[15],this}copyPosition(t){let e=this.elements,n=t.elements;return e[12]=n[12],e[13]=n[13],e[14]=n[14],this}setFromMatrix3(t){let e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,n){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this}makeBasis(t,e,n){return this.set(t.x,e.x,n.x,0,t.y,e.y,n.y,0,t.z,e.z,n.z,0,0,0,0,1),this}extractRotation(t){let e=this.elements,n=t.elements,i=1/jr.setFromMatrixColumn(t,0).length(),s=1/jr.setFromMatrixColumn(t,1).length(),o=1/jr.setFromMatrixColumn(t,2).length();return e[0]=n[0]*i,e[1]=n[1]*i,e[2]=n[2]*i,e[3]=0,e[4]=n[4]*s,e[5]=n[5]*s,e[6]=n[6]*s,e[7]=0,e[8]=n[8]*o,e[9]=n[9]*o,e[10]=n[10]*o,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){let e=this.elements,n=t.x,i=t.y,s=t.z,o=Math.cos(n),a=Math.sin(n),c=Math.cos(i),l=Math.sin(i),f=Math.cos(s),h=Math.sin(s);if(t.order==="XYZ"){let u=o*f,d=o*h,g=a*f,x=a*h;e[0]=c*f,e[4]=-c*h,e[8]=l,e[1]=d+g*l,e[5]=u-x*l,e[9]=-a*c,e[2]=x-u*l,e[6]=g+d*l,e[10]=o*c}else if(t.order==="YXZ"){let u=c*f,d=c*h,g=l*f,x=l*h;e[0]=u+x*a,e[4]=g*a-d,e[8]=o*l,e[1]=o*h,e[5]=o*f,e[9]=-a,e[2]=d*a-g,e[6]=x+u*a,e[10]=o*c}else if(t.order==="ZXY"){let u=c*f,d=c*h,g=l*f,x=l*h;e[0]=u-x*a,e[4]=-o*h,e[8]=g+d*a,e[1]=d+g*a,e[5]=o*f,e[9]=x-u*a,e[2]=-o*l,e[6]=a,e[10]=o*c}else if(t.order==="ZYX"){let u=o*f,d=o*h,g=a*f,x=a*h;e[0]=c*f,e[4]=g*l-d,e[8]=u*l+x,e[1]=c*h,e[5]=x*l+u,e[9]=d*l-g,e[2]=-l,e[6]=a*c,e[10]=o*c}else if(t.order==="YZX"){let u=o*c,d=o*l,g=a*c,x=a*l;e[0]=c*f,e[4]=x-u*h,e[8]=g*h+d,e[1]=h,e[5]=o*f,e[9]=-a*f,e[2]=-l*f,e[6]=d*h+g,e[10]=u-x*h}else if(t.order==="XZY"){let u=o*c,d=o*l,g=a*c,x=a*l;e[0]=c*f,e[4]=-h,e[8]=l*f,e[1]=u*h+x,e[5]=o*f,e[9]=d*h-g,e[2]=g*h-d,e[6]=a*f,e[10]=x*h+u}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(Q_,t,j_)}lookAt(t,e,n){let i=this.elements;return An.subVectors(t,e),An.lengthSq()===0&&(An.z=1),An.normalize(),Ii.crossVectors(n,An),Ii.lengthSq()===0&&(Math.abs(n.z)===1?An.x+=1e-4:An.z+=1e-4,An.normalize(),Ii.crossVectors(n,An)),Ii.normalize(),Wa.crossVectors(An,Ii),i[0]=Ii.x,i[4]=Wa.x,i[8]=An.x,i[1]=Ii.y,i[5]=Wa.y,i[9]=An.y,i[2]=Ii.z,i[6]=Wa.z,i[10]=An.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){let n=t.elements,i=e.elements,s=this.elements,o=n[0],a=n[4],c=n[8],l=n[12],f=n[1],h=n[5],u=n[9],d=n[13],g=n[2],x=n[6],p=n[10],m=n[14],v=n[3],_=n[7],y=n[11],b=n[15],T=i[0],w=i[4],E=i[8],M=i[12],S=i[1],I=i[5],P=i[9],L=i[13],N=i[2],z=i[6],V=i[10],j=i[14],W=i[3],ct=i[7],pt=i[11],_t=i[15];return s[0]=o*T+a*S+c*N+l*W,s[4]=o*w+a*I+c*z+l*ct,s[8]=o*E+a*P+c*V+l*pt,s[12]=o*M+a*L+c*j+l*_t,s[1]=f*T+h*S+u*N+d*W,s[5]=f*w+h*I+u*z+d*ct,s[9]=f*E+h*P+u*V+d*pt,s[13]=f*M+h*L+u*j+d*_t,s[2]=g*T+x*S+p*N+m*W,s[6]=g*w+x*I+p*z+m*ct,s[10]=g*E+x*P+p*V+m*pt,s[14]=g*M+x*L+p*j+m*_t,s[3]=v*T+_*S+y*N+b*W,s[7]=v*w+_*I+y*z+b*ct,s[11]=v*E+_*P+y*V+b*pt,s[15]=v*M+_*L+y*j+b*_t,this}multiplyScalar(t){let e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){let t=this.elements,e=t[0],n=t[4],i=t[8],s=t[12],o=t[1],a=t[5],c=t[9],l=t[13],f=t[2],h=t[6],u=t[10],d=t[14],g=t[3],x=t[7],p=t[11],m=t[15];return g*(+s*c*h-i*l*h-s*a*u+n*l*u+i*a*d-n*c*d)+x*(+e*c*d-e*l*u+s*o*u-i*o*d+i*l*f-s*c*f)+p*(+e*l*h-e*a*d-s*o*h+n*o*d+s*a*f-n*l*f)+m*(-i*a*f-e*c*h+e*a*u+i*o*h-n*o*u+n*c*f)}transpose(){let t=this.elements,e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,n){let i=this.elements;return t.isVector3?(i[12]=t.x,i[13]=t.y,i[14]=t.z):(i[12]=t,i[13]=e,i[14]=n),this}invert(){let t=this.elements,e=t[0],n=t[1],i=t[2],s=t[3],o=t[4],a=t[5],c=t[6],l=t[7],f=t[8],h=t[9],u=t[10],d=t[11],g=t[12],x=t[13],p=t[14],m=t[15],v=h*p*l-x*u*l+x*c*d-a*p*d-h*c*m+a*u*m,_=g*u*l-f*p*l-g*c*d+o*p*d+f*c*m-o*u*m,y=f*x*l-g*h*l+g*a*d-o*x*d-f*a*m+o*h*m,b=g*h*c-f*x*c-g*a*u+o*x*u+f*a*p-o*h*p,T=e*v+n*_+i*y+s*b;if(T===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);let w=1/T;return t[0]=v*w,t[1]=(x*u*s-h*p*s-x*i*d+n*p*d+h*i*m-n*u*m)*w,t[2]=(a*p*s-x*c*s+x*i*l-n*p*l-a*i*m+n*c*m)*w,t[3]=(h*c*s-a*u*s-h*i*l+n*u*l+a*i*d-n*c*d)*w,t[4]=_*w,t[5]=(f*p*s-g*u*s+g*i*d-e*p*d-f*i*m+e*u*m)*w,t[6]=(g*c*s-o*p*s-g*i*l+e*p*l+o*i*m-e*c*m)*w,t[7]=(o*u*s-f*c*s+f*i*l-e*u*l-o*i*d+e*c*d)*w,t[8]=y*w,t[9]=(g*h*s-f*x*s-g*n*d+e*x*d+f*n*m-e*h*m)*w,t[10]=(o*x*s-g*a*s+g*n*l-e*x*l-o*n*m+e*a*m)*w,t[11]=(f*a*s-o*h*s-f*n*l+e*h*l+o*n*d-e*a*d)*w,t[12]=b*w,t[13]=(f*x*i-g*h*i+g*n*u-e*x*u-f*n*p+e*h*p)*w,t[14]=(g*a*i-o*x*i-g*n*c+e*x*c+o*n*p-e*a*p)*w,t[15]=(o*h*i-f*a*i+f*n*c-e*h*c-o*n*u+e*a*u)*w,this}scale(t){let e=this.elements,n=t.x,i=t.y,s=t.z;return e[0]*=n,e[4]*=i,e[8]*=s,e[1]*=n,e[5]*=i,e[9]*=s,e[2]*=n,e[6]*=i,e[10]*=s,e[3]*=n,e[7]*=i,e[11]*=s,this}getMaxScaleOnAxis(){let t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],n=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],i=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,n,i))}makeTranslation(t,e,n){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,n,0,0,0,1),this}makeRotationX(t){let e=Math.cos(t),n=Math.sin(t);return this.set(1,0,0,0,0,e,-n,0,0,n,e,0,0,0,0,1),this}makeRotationY(t){let e=Math.cos(t),n=Math.sin(t);return this.set(e,0,n,0,0,1,0,0,-n,0,e,0,0,0,0,1),this}makeRotationZ(t){let e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,0,n,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){let n=Math.cos(e),i=Math.sin(e),s=1-n,o=t.x,a=t.y,c=t.z,l=s*o,f=s*a;return this.set(l*o+n,l*a-i*c,l*c+i*a,0,l*a+i*c,f*a+n,f*c-i*o,0,l*c-i*a,f*c+i*o,s*c*c+n,0,0,0,0,1),this}makeScale(t,e,n){return this.set(t,0,0,0,0,e,0,0,0,0,n,0,0,0,0,1),this}makeShear(t,e,n,i,s,o){return this.set(1,n,s,0,t,1,o,0,e,i,1,0,0,0,0,1),this}compose(t,e,n){let i=this.elements,s=e._x,o=e._y,a=e._z,c=e._w,l=s+s,f=o+o,h=a+a,u=s*l,d=s*f,g=s*h,x=o*f,p=o*h,m=a*h,v=c*l,_=c*f,y=c*h,b=n.x,T=n.y,w=n.z;return i[0]=(1-(x+m))*b,i[1]=(d+y)*b,i[2]=(g-_)*b,i[3]=0,i[4]=(d-y)*T,i[5]=(1-(u+m))*T,i[6]=(p+v)*T,i[7]=0,i[8]=(g+_)*w,i[9]=(p-v)*w,i[10]=(1-(u+x))*w,i[11]=0,i[12]=t.x,i[13]=t.y,i[14]=t.z,i[15]=1,this}decompose(t,e,n){let i=this.elements,s=jr.set(i[0],i[1],i[2]).length(),o=jr.set(i[4],i[5],i[6]).length(),a=jr.set(i[8],i[9],i[10]).length();this.determinant()<0&&(s=-s),t.x=i[12],t.y=i[13],t.z=i[14],Wn.copy(this);let l=1/s,f=1/o,h=1/a;return Wn.elements[0]*=l,Wn.elements[1]*=l,Wn.elements[2]*=l,Wn.elements[4]*=f,Wn.elements[5]*=f,Wn.elements[6]*=f,Wn.elements[8]*=h,Wn.elements[9]*=h,Wn.elements[10]*=h,e.setFromRotationMatrix(Wn),n.x=s,n.y=o,n.z=a,this}makePerspective(t,e,n,i,s,o,a=Rn,c=!1){let l=this.elements,f=2*s/(e-t),h=2*s/(n-i),u=(e+t)/(e-t),d=(n+i)/(n-i),g,x;if(c)g=s/(o-s),x=o*s/(o-s);else if(a===Rn)g=-(o+s)/(o-s),x=-2*o*s/(o-s);else if(a===vs)g=-o/(o-s),x=-o*s/(o-s);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return l[0]=f,l[4]=0,l[8]=u,l[12]=0,l[1]=0,l[5]=h,l[9]=d,l[13]=0,l[2]=0,l[6]=0,l[10]=g,l[14]=x,l[3]=0,l[7]=0,l[11]=-1,l[15]=0,this}makeOrthographic(t,e,n,i,s,o,a=Rn,c=!1){let l=this.elements,f=2/(e-t),h=2/(n-i),u=-(e+t)/(e-t),d=-(n+i)/(n-i),g,x;if(c)g=1/(o-s),x=o/(o-s);else if(a===Rn)g=-2/(o-s),x=-(o+s)/(o-s);else if(a===vs)g=-1/(o-s),x=-s/(o-s);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return l[0]=f,l[4]=0,l[8]=0,l[12]=u,l[1]=0,l[5]=h,l[9]=0,l[13]=d,l[2]=0,l[6]=0,l[10]=g,l[14]=x,l[3]=0,l[7]=0,l[11]=0,l[15]=1,this}equals(t){let e=this.elements,n=t.elements;for(let i=0;i<16;i++)if(e[i]!==n[i])return!1;return!0}fromArray(t,e=0){for(let n=0;n<16;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){let n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t[e+9]=n[9],t[e+10]=n[10],t[e+11]=n[11],t[e+12]=n[12],t[e+13]=n[13],t[e+14]=n[14],t[e+15]=n[15],t}},jr=new R,Wn=new gt,Q_=new R(0,0,0),j_=new R(1,1,1),Ii=new R,Wa=new R,An=new R,dm=new gt,pm=new Ze,In=class r{constructor(t=0,e=0,n=0,i=r.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=n,this._order=i}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,n,i=this._order){return this._x=t,this._y=e,this._z=n,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,n=!0){let i=t.elements,s=i[0],o=i[4],a=i[8],c=i[1],l=i[5],f=i[9],h=i[2],u=i[6],d=i[10];switch(e){case"XYZ":this._y=Math.asin(Bt(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-f,d),this._z=Math.atan2(-o,s)):(this._x=Math.atan2(u,l),this._z=0);break;case"YXZ":this._x=Math.asin(-Bt(f,-1,1)),Math.abs(f)<.9999999?(this._y=Math.atan2(a,d),this._z=Math.atan2(c,l)):(this._y=Math.atan2(-h,s),this._z=0);break;case"ZXY":this._x=Math.asin(Bt(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(-h,d),this._z=Math.atan2(-o,l)):(this._y=0,this._z=Math.atan2(c,s));break;case"ZYX":this._y=Math.asin(-Bt(h,-1,1)),Math.abs(h)<.9999999?(this._x=Math.atan2(u,d),this._z=Math.atan2(c,s)):(this._x=0,this._z=Math.atan2(-o,l));break;case"YZX":this._z=Math.asin(Bt(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(-f,l),this._y=Math.atan2(-h,s)):(this._x=0,this._y=Math.atan2(a,d));break;case"XZY":this._z=Math.asin(-Bt(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(u,l),this._y=Math.atan2(a,s)):(this._x=Math.atan2(-f,d),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,n===!0&&this._onChangeCallback(),this}setFromQuaternion(t,e,n){return dm.makeRotationFromQuaternion(t),this.setFromRotationMatrix(dm,e,n)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return pm.setFromEuler(this),this.setFromQuaternion(pm,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],t[3]!==void 0&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}};In.DEFAULT_ORDER="XYZ";var Ss=class{constructor(){this.mask=1}set(t){this.mask=(1<>>0}enable(t){this.mask|=1<1){for(let e=0;e1){for(let n=0;n0&&(i.userData=this.userData),i.layers=this.layers.mask,i.matrix=this.matrix.toArray(),i.up=this.up.toArray(),this.matrixAutoUpdate===!1&&(i.matrixAutoUpdate=!1),this.isInstancedMesh&&(i.type="InstancedMesh",i.count=this.count,i.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(i.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(i.type="BatchedMesh",i.perObjectFrustumCulled=this.perObjectFrustumCulled,i.sortObjects=this.sortObjects,i.drawRanges=this._drawRanges,i.reservedRanges=this._reservedRanges,i.geometryInfo=this._geometryInfo.map(a=>({...a,boundingBox:a.boundingBox?a.boundingBox.toJSON():void 0,boundingSphere:a.boundingSphere?a.boundingSphere.toJSON():void 0})),i.instanceInfo=this._instanceInfo.map(a=>({...a})),i.availableInstanceIds=this._availableInstanceIds.slice(),i.availableGeometryIds=this._availableGeometryIds.slice(),i.nextIndexStart=this._nextIndexStart,i.nextVertexStart=this._nextVertexStart,i.geometryCount=this._geometryCount,i.maxInstanceCount=this._maxInstanceCount,i.maxVertexCount=this._maxVertexCount,i.maxIndexCount=this._maxIndexCount,i.geometryInitialized=this._geometryInitialized,i.matricesTexture=this._matricesTexture.toJSON(t),i.indirectTexture=this._indirectTexture.toJSON(t),this._colorsTexture!==null&&(i.colorsTexture=this._colorsTexture.toJSON(t)),this.boundingSphere!==null&&(i.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(i.boundingBox=this.boundingBox.toJSON()));function s(a,c){return a[c.uuid]===void 0&&(a[c.uuid]=c.toJSON(t)),c.uuid}if(this.isScene)this.background&&(this.background.isColor?i.background=this.background.toJSON():this.background.isTexture&&(i.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(i.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){i.geometry=s(t.geometries,this.geometry);let a=this.geometry.parameters;if(a!==void 0&&a.shapes!==void 0){let c=a.shapes;if(Array.isArray(c))for(let l=0,f=c.length;l0){i.children=[];for(let a=0;a0){i.animations=[];for(let a=0;a0&&(n.geometries=a),c.length>0&&(n.materials=c),l.length>0&&(n.textures=l),f.length>0&&(n.images=f),h.length>0&&(n.shapes=h),u.length>0&&(n.skeletons=u),d.length>0&&(n.animations=d),g.length>0&&(n.nodes=g)}return n.object=i,n;function o(a){let c=[];for(let l in a){let f=a[l];delete f.metadata,c.push(f)}return c}}clone(t){return new this.constructor().copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),e===!0)for(let n=0;n0?i.multiplyScalar(1/Math.sqrt(s)):i.set(0,0,0)}static getBarycoord(t,e,n,i,s){Xn.subVectors(i,e),pi.subVectors(n,e),qh.subVectors(t,e);let o=Xn.dot(Xn),a=Xn.dot(pi),c=Xn.dot(qh),l=pi.dot(pi),f=pi.dot(qh),h=o*l-a*a;if(h===0)return s.set(0,0,0),null;let u=1/h,d=(l*c-a*f)*u,g=(o*f-a*c)*u;return s.set(1-d-g,g,d)}static containsPoint(t,e,n,i){return this.getBarycoord(t,e,n,i,mi)===null?!1:mi.x>=0&&mi.y>=0&&mi.x+mi.y<=1}static getInterpolation(t,e,n,i,s,o,a,c){return this.getBarycoord(t,e,n,i,mi)===null?(c.x=0,c.y=0,"z"in c&&(c.z=0),"w"in c&&(c.w=0),null):(c.setScalar(0),c.addScaledVector(s,mi.x),c.addScaledVector(o,mi.y),c.addScaledVector(a,mi.z),c)}static getInterpolatedAttribute(t,e,n,i,s,o){return Jh.setScalar(0),Kh.setScalar(0),Qh.setScalar(0),Jh.fromBufferAttribute(t,e),Kh.fromBufferAttribute(t,n),Qh.fromBufferAttribute(t,i),o.setScalar(0),o.addScaledVector(Jh,s.x),o.addScaledVector(Kh,s.y),o.addScaledVector(Qh,s.z),o}static isFrontFacing(t,e,n,i){return Xn.subVectors(n,e),pi.subVectors(t,e),Xn.cross(pi).dot(i)<0}set(t,e,n){return this.a.copy(t),this.b.copy(e),this.c.copy(n),this}setFromPointsAndIndices(t,e,n,i){return this.a.copy(t[e]),this.b.copy(t[n]),this.c.copy(t[i]),this}setFromAttributeAndIndices(t,e,n,i){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,n),this.c.fromBufferAttribute(t,i),this}clone(){return new this.constructor().copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return Xn.subVectors(this.c,this.b),pi.subVectors(this.a,this.b),Xn.cross(pi).length()*.5}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return r.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return r.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,n,i,s){return r.getInterpolation(t,this.a,this.b,this.c,e,n,i,s)}containsPoint(t){return r.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return r.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){let n=this.a,i=this.b,s=this.c,o,a;ns.subVectors(i,n),is.subVectors(s,n),Yh.subVectors(t,n);let c=ns.dot(Yh),l=is.dot(Yh);if(c<=0&&l<=0)return e.copy(n);$h.subVectors(t,i);let f=ns.dot($h),h=is.dot($h);if(f>=0&&h<=f)return e.copy(i);let u=c*h-f*l;if(u<=0&&c>=0&&f<=0)return o=c/(c-f),e.copy(n).addScaledVector(ns,o);Zh.subVectors(t,s);let d=ns.dot(Zh),g=is.dot(Zh);if(g>=0&&d<=g)return e.copy(s);let x=d*l-c*g;if(x<=0&&l>=0&&g<=0)return a=l/(l-g),e.copy(n).addScaledVector(is,a);let p=f*g-d*h;if(p<=0&&h-f>=0&&d-g>=0)return ym.subVectors(s,i),a=(h-f)/(h-f+(d-g)),e.copy(i).addScaledVector(ym,a);let m=1/(p+x+u);return o=x*m,a=u*m,e.copy(n).addScaledVector(ns,o).addScaledVector(is,a)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}},a0={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},Pi={h:0,s:0,l:0},qa={h:0,s:0,l:0};function jh(r,t,e){return e<0&&(e+=1),e>1&&(e-=1),e<1/6?r+(t-r)*6*e:e<1/2?t:e<2/3?r+(t-r)*6*(2/3-e):r}var ft=class{constructor(t,e,n){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,n)}set(t,e,n){if(e===void 0&&n===void 0){let i=t;i&&i.isColor?this.copy(i):typeof i=="number"?this.setHex(i):typeof i=="string"&&this.setStyle(i)}else this.setRGB(t,e,n);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=vn){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(t&255)/255,ie.colorSpaceToWorking(this,e),this}setRGB(t,e,n,i=ie.workingColorSpace){return this.r=t,this.g=e,this.b=n,ie.colorSpaceToWorking(this,i),this}setHSL(t,e,n,i=ie.workingColorSpace){if(t=Yd(t,1),e=Bt(e,0,1),n=Bt(n,0,1),e===0)this.r=this.g=this.b=n;else{let s=n<=.5?n*(1+e):n+e-n*e,o=2*n-s;this.r=jh(o,s,t+1/3),this.g=jh(o,s,t),this.b=jh(o,s,t-1/3)}return ie.colorSpaceToWorking(this,i),this}setStyle(t,e=vn){function n(s){s!==void 0&&parseFloat(s)<1&&console.warn("THREE.Color: Alpha component of "+t+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(t)){let s,o=i[1],a=i[2];switch(o){case"rgb":case"rgba":if(s=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(s[4]),this.setRGB(Math.min(255,parseInt(s[1],10))/255,Math.min(255,parseInt(s[2],10))/255,Math.min(255,parseInt(s[3],10))/255,e);if(s=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(s[4]),this.setRGB(Math.min(100,parseInt(s[1],10))/100,Math.min(100,parseInt(s[2],10))/100,Math.min(100,parseInt(s[3],10))/100,e);break;case"hsl":case"hsla":if(s=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(s[4]),this.setHSL(parseFloat(s[1])/360,parseFloat(s[2])/100,parseFloat(s[3])/100,e);break;default:console.warn("THREE.Color: Unknown color model "+t)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(t)){let s=i[1],o=s.length;if(o===3)return this.setRGB(parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,e);if(o===6)return this.setHex(parseInt(s,16),e);console.warn("THREE.Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=vn){let n=a0[t.toLowerCase()];return n!==void 0?this.setHex(n,e):console.warn("THREE.Color: Unknown color "+t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}copySRGBToLinear(t){return this.r=vi(t.r),this.g=vi(t.g),this.b=vi(t.b),this}copyLinearToSRGB(t){return this.r=gs(t.r),this.g=gs(t.g),this.b=gs(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=vn){return ie.workingToColorSpace(nn.copy(this),t),Math.round(Bt(nn.r*255,0,255))*65536+Math.round(Bt(nn.g*255,0,255))*256+Math.round(Bt(nn.b*255,0,255))}getHexString(t=vn){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=ie.workingColorSpace){ie.workingToColorSpace(nn.copy(this),e);let n=nn.r,i=nn.g,s=nn.b,o=Math.max(n,i,s),a=Math.min(n,i,s),c,l,f=(a+o)/2;if(a===o)c=0,l=0;else{let h=o-a;switch(l=f<=.5?h/(o+a):h/(2-o-a),o){case n:c=(i-s)/h+(i0!=t>0&&this.version++,this._alphaTest=t}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(t!==void 0)for(let e in t){let n=t[e];if(n===void 0){console.warn(`THREE.Material: parameter '${e}' has value of undefined.`);continue}let i=this[e];if(i===void 0){console.warn(`THREE.Material: '${e}' is not a property of THREE.${this.type}.`);continue}i&&i.isColor?i.set(n):i&&i.isVector3&&n&&n.isVector3?i.copy(n):this[e]=n}}toJSON(t){let e=t===void 0||typeof t=="string";e&&(t={textures:{},images:{}});let n={metadata:{version:4.7,type:"Material",generator:"Material.toJSON"}};n.uuid=this.uuid,n.type=this.type,this.name!==""&&(n.name=this.name),this.color&&this.color.isColor&&(n.color=this.color.getHex()),this.roughness!==void 0&&(n.roughness=this.roughness),this.metalness!==void 0&&(n.metalness=this.metalness),this.sheen!==void 0&&(n.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(n.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(n.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(n.emissive=this.emissive.getHex()),this.emissiveIntensity!==void 0&&this.emissiveIntensity!==1&&(n.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(n.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(n.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(n.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(n.shininess=this.shininess),this.clearcoat!==void 0&&(n.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(n.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(n.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(n.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(n.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,n.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(n.sheenColorMap=this.sheenColorMap.toJSON(t).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(n.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(t).uuid),this.dispersion!==void 0&&(n.dispersion=this.dispersion),this.iridescence!==void 0&&(n.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(n.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(n.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(n.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(n.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),this.anisotropy!==void 0&&(n.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(n.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(n.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(n.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(n.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(n.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(n.lightMap=this.lightMap.toJSON(t).uuid,n.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(n.aoMap=this.aoMap.toJSON(t).uuid,n.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(n.bumpMap=this.bumpMap.toJSON(t).uuid,n.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(n.normalMap=this.normalMap.toJSON(t).uuid,n.normalMapType=this.normalMapType,n.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(n.displacementMap=this.displacementMap.toJSON(t).uuid,n.displacementScale=this.displacementScale,n.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(n.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(n.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(n.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(n.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(n.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(n.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(n.envMap=this.envMap.toJSON(t).uuid,this.combine!==void 0&&(n.combine=this.combine)),this.envMapRotation!==void 0&&(n.envMapRotation=this.envMapRotation.toArray()),this.envMapIntensity!==void 0&&(n.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(n.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(n.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(n.gradientMap=this.gradientMap.toJSON(t).uuid),this.transmission!==void 0&&(n.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(n.transmissionMap=this.transmissionMap.toJSON(t).uuid),this.thickness!==void 0&&(n.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(n.thicknessMap=this.thicknessMap.toJSON(t).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(n.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(n.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(n.size=this.size),this.shadowSide!==null&&(n.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(n.sizeAttenuation=this.sizeAttenuation),this.blending!==Yn&&(n.blending=this.blending),this.side!==yn&&(n.side=this.side),this.vertexColors===!0&&(n.vertexColors=!0),this.opacity<1&&(n.opacity=this.opacity),this.transparent===!0&&(n.transparent=!0),this.blendSrc!==Rc&&(n.blendSrc=this.blendSrc),this.blendDst!==Cc&&(n.blendDst=this.blendDst),this.blendEquation!==Ni&&(n.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(n.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(n.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(n.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(n.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(n.blendAlpha=this.blendAlpha),this.depthFunc!==_r&&(n.depthFunc=this.depthFunc),this.depthTest===!1&&(n.depthTest=this.depthTest),this.depthWrite===!1&&(n.depthWrite=this.depthWrite),this.colorWrite===!1&&(n.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(n.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==Sf&&(n.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(n.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(n.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==pr&&(n.stencilFail=this.stencilFail),this.stencilZFail!==pr&&(n.stencilZFail=this.stencilZFail),this.stencilZPass!==pr&&(n.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(n.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(n.rotation=this.rotation),this.polygonOffset===!0&&(n.polygonOffset=!0),this.polygonOffsetFactor!==0&&(n.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(n.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(n.linewidth=this.linewidth),this.dashSize!==void 0&&(n.dashSize=this.dashSize),this.gapSize!==void 0&&(n.gapSize=this.gapSize),this.scale!==void 0&&(n.scale=this.scale),this.dithering===!0&&(n.dithering=!0),this.alphaTest>0&&(n.alphaTest=this.alphaTest),this.alphaHash===!0&&(n.alphaHash=!0),this.alphaToCoverage===!0&&(n.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(n.premultipliedAlpha=!0),this.forceSinglePass===!0&&(n.forceSinglePass=!0),this.wireframe===!0&&(n.wireframe=!0),this.wireframeLinewidth>1&&(n.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!=="round"&&(n.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!=="round"&&(n.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(n.flatShading=!0),this.visible===!1&&(n.visible=!1),this.toneMapped===!1&&(n.toneMapped=!1),this.fog===!1&&(n.fog=!1),Object.keys(this.userData).length>0&&(n.userData=this.userData);function i(s){let o=[];for(let a in s){let c=s[a];delete c.metadata,o.push(c)}return o}if(e){let s=i(t.textures),o=i(t.images);s.length>0&&(n.textures=s),o.length>0&&(n.images=o)}return n}clone(){return new this.constructor().copy(this)}copy(t){this.name=t.name,this.blending=t.blending,this.side=t.side,this.vertexColors=t.vertexColors,this.opacity=t.opacity,this.transparent=t.transparent,this.blendSrc=t.blendSrc,this.blendDst=t.blendDst,this.blendEquation=t.blendEquation,this.blendSrcAlpha=t.blendSrcAlpha,this.blendDstAlpha=t.blendDstAlpha,this.blendEquationAlpha=t.blendEquationAlpha,this.blendColor.copy(t.blendColor),this.blendAlpha=t.blendAlpha,this.depthFunc=t.depthFunc,this.depthTest=t.depthTest,this.depthWrite=t.depthWrite,this.stencilWriteMask=t.stencilWriteMask,this.stencilFunc=t.stencilFunc,this.stencilRef=t.stencilRef,this.stencilFuncMask=t.stencilFuncMask,this.stencilFail=t.stencilFail,this.stencilZFail=t.stencilZFail,this.stencilZPass=t.stencilZPass,this.stencilWrite=t.stencilWrite;let e=t.clippingPlanes,n=null;if(e!==null){let i=e.length;n=new Array(i);for(let s=0;s!==i;++s)n[s]=e[s].clone()}return this.clippingPlanes=n,this.clipIntersection=t.clipIntersection,this.clipShadows=t.clipShadows,this.shadowSide=t.shadowSide,this.colorWrite=t.colorWrite,this.precision=t.precision,this.polygonOffset=t.polygonOffset,this.polygonOffsetFactor=t.polygonOffsetFactor,this.polygonOffsetUnits=t.polygonOffsetUnits,this.dithering=t.dithering,this.alphaTest=t.alphaTest,this.alphaHash=t.alphaHash,this.alphaToCoverage=t.alphaToCoverage,this.premultipliedAlpha=t.premultipliedAlpha,this.forceSinglePass=t.forceSinglePass,this.visible=t.visible,this.toneMapped=t.toneMapped,this.userData=JSON.parse(JSON.stringify(t.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){t===!0&&this.version++}},zn=class extends Je{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new ft(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new In,this.combine=ua,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}},xi=sy();function sy(){let r=new ArrayBuffer(4),t=new Float32Array(r),e=new Uint32Array(r),n=new Uint32Array(512),i=new Uint32Array(512);for(let c=0;c<256;++c){let l=c-127;l<-27?(n[c]=0,n[c|256]=32768,i[c]=24,i[c|256]=24):l<-14?(n[c]=1024>>-l-14,n[c|256]=1024>>-l-14|32768,i[c]=-l-1,i[c|256]=-l-1):l<=15?(n[c]=l+15<<10,n[c|256]=l+15<<10|32768,i[c]=13,i[c|256]=13):l<128?(n[c]=31744,n[c|256]=64512,i[c]=24,i[c|256]=24):(n[c]=31744,n[c|256]=64512,i[c]=13,i[c|256]=13)}let s=new Uint32Array(2048),o=new Uint32Array(64),a=new Uint32Array(64);for(let c=1;c<1024;++c){let l=c<<13,f=0;for(;(l&8388608)===0;)l<<=1,f-=8388608;l&=-8388609,f+=947912704,s[c]=l|f}for(let c=1024;c<2048;++c)s[c]=939524096+(c-1024<<13);for(let c=1;c<31;++c)o[c]=c<<23;o[31]=1199570944,o[32]=2147483648;for(let c=33;c<63;++c)o[c]=2147483648+(c-32<<23);o[63]=3347054592;for(let c=1;c<64;++c)c!==32&&(a[c]=1024);return{floatView:t,uint32View:e,baseTable:n,shiftTable:i,mantissaTable:s,exponentTable:o,offsetTable:a}}function xn(r){Math.abs(r)>65504&&console.warn("THREE.DataUtils.toHalfFloat(): Value out of range."),r=Bt(r,-65504,65504),xi.floatView[0]=r;let t=xi.uint32View[0],e=t>>23&511;return xi.baseTable[e]+((t&8388607)>>xi.shiftTable[e])}function bo(r){let t=r>>10;return xi.uint32View[0]=xi.mantissaTable[xi.offsetTable[t]+(r&1023)]+xi.exponentTable[t],xi.floatView[0]}var fn=class{static toHalfFloat(t){return xn(t)}static fromHalfFloat(t){return bo(t)}},Be=new R,Ya=new q,oy=0,Ot=class{constructor(t,e,n=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:oy++}),this.name="",this.array=t,this.itemSize=e,this.count=t!==void 0?t.length/e:0,this.normalized=n,this.usage=Io,this.updateRanges=[],this.gpuType=$t,this.version=0}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,n){t*=this.itemSize,n*=e.itemSize;for(let i=0,s=this.itemSize;ie.count&&console.warn("THREE.BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),e.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new se);let t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){console.error("THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new R(-1/0,-1/0,-1/0),new R(1/0,1/0,1/0));return}if(t!==void 0){if(this.boundingBox.setFromBufferAttribute(t),e)for(let n=0,i=e.length;n0&&(t.userData=this.userData),this.parameters!==void 0){let c=this.parameters;for(let l in c)c[l]!==void 0&&(t[l]=c[l]);return t}t.data={attributes:{}};let e=this.index;e!==null&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});let n=this.attributes;for(let c in n){let l=n[c];t.data.attributes[c]=l.toJSON(t.data)}let i={},s=!1;for(let c in this.morphAttributes){let l=this.morphAttributes[c],f=[];for(let h=0,u=l.length;h0&&(i[c]=f,s=!0)}s&&(t.data.morphAttributes=i,t.data.morphTargetsRelative=this.morphTargetsRelative);let o=this.groups;o.length>0&&(t.data.groups=JSON.parse(JSON.stringify(o)));let a=this.boundingSphere;return a!==null&&(t.data.boundingSphere=a.toJSON()),t}clone(){return new this.constructor().copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;let e={};this.name=t.name;let n=t.index;n!==null&&this.setIndex(n.clone());let i=t.attributes;for(let l in i){let f=i[l];this.setAttribute(l,f.clone(e))}let s=t.morphAttributes;for(let l in s){let f=[],h=s[l];for(let u=0,d=h.length;u0){let i=e[n[0]];if(i!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,o=i.length;s(t.far-t.near)**2))&&(bm.copy(s).invert(),rr.copy(t.ray).applyMatrix4(bm),!(n.boundingBox!==null&&rr.intersectsBox(n.boundingBox)===!1)&&this._computeIntersections(t,e,rr)))}_computeIntersections(t,e,n){let i,s=this.geometry,o=this.material,a=s.index,c=s.attributes.position,l=s.attributes.uv,f=s.attributes.uv1,h=s.attributes.normal,u=s.groups,d=s.drawRange;if(a!==null)if(Array.isArray(o))for(let g=0,x=u.length;ge.far?null:{distance:l,point:ja.clone(),object:r}}function tc(r,t,e,n,i,s,o,a,c,l){r.getVertexPosition(a,Za),r.getVertexPosition(c,Ja),r.getVertexPosition(l,Ka);let f=cy(r,t,e,n,Za,Ja,Ka,Mm);if(f){let h=new R;$e.getBarycoord(Mm,Za,Ja,Ka,h),i&&(f.uv=$e.getInterpolatedAttribute(i,a,c,l,h,new q)),s&&(f.uv1=$e.getInterpolatedAttribute(s,a,c,l,h,new q)),o&&(f.normal=$e.getInterpolatedAttribute(o,a,c,l,h,new R),f.normal.dot(n.direction)>0&&f.normal.multiplyScalar(-1));let u={a,b:c,c:l,normal:new R,materialIndex:0};$e.getNormal(Za,Ja,Ka,u.normal),f.face=u,f.barycoord=h}return f}var Sr=class r extends Ft{constructor(t=1,e=1,n=1,i=1,s=1,o=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:n,widthSegments:i,heightSegments:s,depthSegments:o};let a=this;i=Math.floor(i),s=Math.floor(s),o=Math.floor(o);let c=[],l=[],f=[],h=[],u=0,d=0;g("z","y","x",-1,-1,n,e,t,o,s,0),g("z","y","x",1,-1,n,e,-t,o,s,1),g("x","z","y",1,1,t,n,e,i,o,2),g("x","z","y",1,-1,t,n,-e,i,o,3),g("x","y","z",1,-1,t,e,n,i,s,4),g("x","y","z",-1,-1,t,e,-n,i,s,5),this.setIndex(c),this.setAttribute("position",new bt(l,3)),this.setAttribute("normal",new bt(f,3)),this.setAttribute("uv",new bt(h,2));function g(x,p,m,v,_,y,b,T,w,E,M){let S=y/w,I=b/E,P=y/2,L=b/2,N=T/2,z=w+1,V=E+1,j=0,W=0,ct=new R;for(let pt=0;pt0?1:-1,f.push(ct.x,ct.y,ct.z),h.push(Ht/w),h.push(1-pt/E),j+=1}}for(let pt=0;pt0&&(e.defines=this.defines),e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader,e.lights=this.lights,e.clipping=this.clipping;let n={};for(let i in this.extensions)this.extensions[i]===!0&&(n[i]=!0);return Object.keys(n).length>0&&(e.extensions=n),e}},Ms=class extends ue{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new gt,this.projectionMatrix=new gt,this.projectionMatrixInverse=new gt,this.coordinateSystem=Rn,this._reversedDepth=!1}get reversedDepth(){return this._reversedDepth}copy(t,e){return super.copy(t,e),this.matrixWorldInverse.copy(t.matrixWorldInverse),this.projectionMatrix.copy(t.projectionMatrix),this.projectionMatrixInverse.copy(t.projectionMatrixInverse),this.coordinateSystem=t.coordinateSystem,this}getWorldDirection(t){return super.getWorldDirection(t).negate()}updateMatrixWorld(t){super.updateMatrixWorld(t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(t,e){super.updateWorldMatrix(t,e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return new this.constructor().copy(this)}},Di=new R,Tm=new q,wm=new q,Re=class extends Ms{constructor(t=50,e=1,n=.1,i=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=t,this.zoom=1,this.near=n,this.far=i,this.focus=10,this.aspect=e,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.fov=t.fov,this.zoom=t.zoom,this.near=t.near,this.far=t.far,this.focus=t.focus,this.aspect=t.aspect,this.view=t.view===null?null:Object.assign({},t.view),this.filmGauge=t.filmGauge,this.filmOffset=t.filmOffset,this}setFocalLength(t){let e=.5*this.getFilmHeight()/t;this.fov=br*2*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){let t=Math.tan(vr*.5*this.fov);return .5*this.getFilmHeight()/t}getEffectiveFOV(){return br*2*Math.atan(Math.tan(vr*.5*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(t,e,n){Di.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),e.set(Di.x,Di.y).multiplyScalar(-t/Di.z),Di.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),n.set(Di.x,Di.y).multiplyScalar(-t/Di.z)}getViewSize(t,e){return this.getViewBounds(t,Tm,wm),e.subVectors(wm,Tm)}setViewOffset(t,e,n,i,s,o){this.aspect=t/e,this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=n,this.view.offsetY=i,this.view.width=s,this.view.height=o,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){let t=this.near,e=t*Math.tan(vr*.5*this.fov)/this.zoom,n=2*e,i=this.aspect*n,s=-.5*i,o=this.view;if(this.view!==null&&this.view.enabled){let c=o.fullWidth,l=o.fullHeight;s+=o.offsetX*i/c,e-=o.offsetY*n/l,i*=o.width/c,n*=o.height/l}let a=this.filmOffset;a!==0&&(s+=t*a/this.getFilmWidth()),this.projectionMatrix.makePerspective(s,s+i,e,e-n,t,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){let e=super.toJSON(t);return e.object.fov=this.fov,e.object.zoom=this.zoom,e.object.near=this.near,e.object.far=this.far,e.object.focus=this.focus,e.object.aspect=this.aspect,this.view!==null&&(e.object.view=Object.assign({},this.view)),e.object.filmGauge=this.filmGauge,e.object.filmOffset=this.filmOffset,e}},ss=-90,os=1,Dc=class extends ue{constructor(t,e,n){super(),this.type="CubeCamera",this.renderTarget=n,this.coordinateSystem=null,this.activeMipmapLevel=0;let i=new Re(ss,os,t,e);i.layers=this.layers,this.add(i);let s=new Re(ss,os,t,e);s.layers=this.layers,this.add(s);let o=new Re(ss,os,t,e);o.layers=this.layers,this.add(o);let a=new Re(ss,os,t,e);a.layers=this.layers,this.add(a);let c=new Re(ss,os,t,e);c.layers=this.layers,this.add(c);let l=new Re(ss,os,t,e);l.layers=this.layers,this.add(l)}updateCoordinateSystem(){let t=this.coordinateSystem,e=this.children.concat(),[n,i,s,o,a,c]=e;for(let l of e)this.remove(l);if(t===Rn)n.up.set(0,1,0),n.lookAt(1,0,0),i.up.set(0,1,0),i.lookAt(-1,0,0),s.up.set(0,0,-1),s.lookAt(0,1,0),o.up.set(0,0,1),o.lookAt(0,-1,0),a.up.set(0,1,0),a.lookAt(0,0,1),c.up.set(0,1,0),c.lookAt(0,0,-1);else if(t===vs)n.up.set(0,-1,0),n.lookAt(-1,0,0),i.up.set(0,-1,0),i.lookAt(1,0,0),s.up.set(0,0,1),s.lookAt(0,1,0),o.up.set(0,0,-1),o.lookAt(0,-1,0),a.up.set(0,-1,0),a.lookAt(0,0,1),c.up.set(0,-1,0),c.lookAt(0,0,-1);else throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+t);for(let l of e)this.add(l),l.updateMatrixWorld()}update(t,e){this.parent===null&&this.updateMatrixWorld();let{renderTarget:n,activeMipmapLevel:i}=this;this.coordinateSystem!==t.coordinateSystem&&(this.coordinateSystem=t.coordinateSystem,this.updateCoordinateSystem());let[s,o,a,c,l,f]=this.children,h=t.getRenderTarget(),u=t.getActiveCubeFace(),d=t.getActiveMipmapLevel(),g=t.xr.enabled;t.xr.enabled=!1;let x=n.texture.generateMipmaps;n.texture.generateMipmaps=!1,t.setRenderTarget(n,0,i),t.render(e,s),t.setRenderTarget(n,1,i),t.render(e,o),t.setRenderTarget(n,2,i),t.render(e,a),t.setRenderTarget(n,3,i),t.render(e,c),t.setRenderTarget(n,4,i),t.render(e,l),n.texture.generateMipmaps=x,t.setRenderTarget(n,5,i),t.render(e,f),t.setRenderTarget(h,u,d),t.xr.enabled=g,n.texture.needsPMREMUpdate=!0}},Mr=class extends Oe{constructor(t=[],e=Si,n,i,s,o,a,c,l,f){super(t,e,n,i,s,o,a,c,l,f),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}},Fc=class extends ze{constructor(t=1,e={}){super(t,t,e),this.isWebGLCubeRenderTarget=!0;let n={width:t,height:t,depth:1},i=[n,n,n,n,n,n];this.texture=new Mr(i),this._setTextureOptions(e),this.texture.isRenderTargetTexture=!0}fromEquirectangularTexture(t,e){this.texture.type=e.type,this.texture.colorSpace=e.colorSpace,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;let n={uniforms:{tEquirect:{value:null}},vertexShader:` + + varying vec3 vWorldDirection; + + vec3 transformDirection( in vec3 dir, in mat4 matrix ) { + + return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz ); + + } + + void main() { + + vWorldDirection = transformDirection( position, modelMatrix ); + + #include + #include + + } + `,fragmentShader:` + + uniform sampler2D tEquirect; + + varying vec3 vWorldDirection; + + #include + + void main() { + + vec3 direction = normalize( vWorldDirection ); + + vec2 sampleUV = equirectUv( direction ); + + gl_FragColor = texture2D( tEquirect, sampleUV ); + + } + `},i=new Sr(5,5,5),s=new Ue({name:"CubemapFromEquirect",uniforms:Lr(n.uniforms),vertexShader:n.vertexShader,fragmentShader:n.fragmentShader,side:He,blending:ke});s.uniforms.tEquirect.value=e;let o=new Me(i,s),a=e.minFilter;return e.minFilter===ai&&(e.minFilter=re),new Dc(1,10,this).update(t,o),e.minFilter=a,o.geometry.dispose(),o.material.dispose(),this}clear(t,e=!0,n=!0,i=!0){let s=t.getRenderTarget();for(let o=0;o<6;o++)t.setRenderTarget(this,o),t.clear(e,n,i);t.setRenderTarget(s)}},Li=class extends ue{constructor(){super(),this.isGroup=!0,this.type="Group"}},fy={type:"move"},Ts=class{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new Li,this._hand.matrixAutoUpdate=!1,this._hand.visible=!1,this._hand.joints={},this._hand.inputState={pinching:!1}),this._hand}getTargetRaySpace(){return this._targetRay===null&&(this._targetRay=new Li,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new R,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new R),this._targetRay}getGripSpace(){return this._grip===null&&(this._grip=new Li,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new R,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new R),this._grip}dispatchEvent(t){return this._targetRay!==null&&this._targetRay.dispatchEvent(t),this._grip!==null&&this._grip.dispatchEvent(t),this._hand!==null&&this._hand.dispatchEvent(t),this}connect(t){if(t&&t.hand){let e=this._hand;if(e)for(let n of t.hand.values())this._getHandJoint(e,n)}return this.dispatchEvent({type:"connected",data:t}),this}disconnect(t){return this.dispatchEvent({type:"disconnected",data:t}),this._targetRay!==null&&(this._targetRay.visible=!1),this._grip!==null&&(this._grip.visible=!1),this._hand!==null&&(this._hand.visible=!1),this}update(t,e,n){let i=null,s=null,o=null,a=this._targetRay,c=this._grip,l=this._hand;if(t&&e.session.visibilityState!=="visible-blurred"){if(l&&t.hand){o=!0;for(let x of t.hand.values()){let p=e.getJointPose(x,n),m=this._getHandJoint(l,x);p!==null&&(m.matrix.fromArray(p.transform.matrix),m.matrix.decompose(m.position,m.rotation,m.scale),m.matrixWorldNeedsUpdate=!0,m.jointRadius=p.radius),m.visible=p!==null}let f=l.joints["index-finger-tip"],h=l.joints["thumb-tip"],u=f.position.distanceTo(h.position),d=.02,g=.005;l.inputState.pinching&&u>d+g?(l.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:t.handedness,target:this})):!l.inputState.pinching&&u<=d-g&&(l.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:t.handedness,target:this}))}else c!==null&&t.gripSpace&&(s=e.getPose(t.gripSpace,n),s!==null&&(c.matrix.fromArray(s.transform.matrix),c.matrix.decompose(c.position,c.rotation,c.scale),c.matrixWorldNeedsUpdate=!0,s.linearVelocity?(c.hasLinearVelocity=!0,c.linearVelocity.copy(s.linearVelocity)):c.hasLinearVelocity=!1,s.angularVelocity?(c.hasAngularVelocity=!0,c.angularVelocity.copy(s.angularVelocity)):c.hasAngularVelocity=!1));a!==null&&(i=e.getPose(t.targetRaySpace,n),i===null&&s!==null&&(i=s),i!==null&&(a.matrix.fromArray(i.transform.matrix),a.matrix.decompose(a.position,a.rotation,a.scale),a.matrixWorldNeedsUpdate=!0,i.linearVelocity?(a.hasLinearVelocity=!0,a.linearVelocity.copy(i.linearVelocity)):a.hasLinearVelocity=!1,i.angularVelocity?(a.hasAngularVelocity=!0,a.angularVelocity.copy(i.angularVelocity)):a.hasAngularVelocity=!1,this.dispatchEvent(fy)))}return a!==null&&(a.visible=i!==null),c!==null&&(c.visible=s!==null),l!==null&&(l.visible=o!==null),this}_getHandJoint(t,e){if(t.joints[e.jointName]===void 0){let n=new Li;n.matrixAutoUpdate=!1,n.visible=!1,t.joints[e.jointName]=n,t.add(n)}return t.joints[e.jointName]}},Lc=class r{constructor(t,e=25e-5){this.isFogExp2=!0,this.name="",this.color=new ft(t),this.density=e}clone(){return new r(this.color,this.density)}toJSON(){return{type:"FogExp2",name:this.name,color:this.color.getHex(),density:this.density}}},Nc=class r{constructor(t,e=1,n=1e3){this.isFog=!0,this.name="",this.color=new ft(t),this.near=e,this.far=n}clone(){return new r(this.color,this.near,this.far)}toJSON(){return{type:"Fog",name:this.name,color:this.color.getHex(),near:this.near,far:this.far}}},ws=class extends ue{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,this.backgroundRotation=new In,this.environmentIntensity=1,this.environmentRotation=new In,this.overrideMaterial=null,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(t,e){return super.copy(t,e),t.background!==null&&(this.background=t.background.clone()),t.environment!==null&&(this.environment=t.environment.clone()),t.fog!==null&&(this.fog=t.fog.clone()),this.backgroundBlurriness=t.backgroundBlurriness,this.backgroundIntensity=t.backgroundIntensity,this.backgroundRotation.copy(t.backgroundRotation),this.environmentIntensity=t.environmentIntensity,this.environmentRotation.copy(t.environmentRotation),t.overrideMaterial!==null&&(this.overrideMaterial=t.overrideMaterial.clone()),this.matrixAutoUpdate=t.matrixAutoUpdate,this}toJSON(t){let e=super.toJSON(t);return this.fog!==null&&(e.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(e.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(e.object.backgroundIntensity=this.backgroundIntensity),e.object.backgroundRotation=this.backgroundRotation.toArray(),this.environmentIntensity!==1&&(e.object.environmentIntensity=this.environmentIntensity),e.object.environmentRotation=this.environmentRotation.toArray(),e}},As=class{constructor(t,e){this.isInterleavedBuffer=!0,this.array=t,this.stride=e,this.count=t!==void 0?t.length/e:0,this.usage=Io,this.updateRanges=[],this.version=0,this.uuid=Cn()}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.array=new t.array.constructor(t.array),this.count=t.count,this.stride=t.stride,this.usage=t.usage,this}copyAt(t,e,n){t*=this.stride,n*=e.stride;for(let i=0,s=this.stride;it.far||e.push({distance:c,point:fo.clone(),uv:$e.getInterpolation(fo,ec,mo,nc,Am,nf,Em,new q),face:null,object:this})}copy(t,e){return super.copy(t,e),t.center!==void 0&&this.center.copy(t.center),this.material=t.material,this}};function ic(r,t,e,n,i,s){us.subVectors(r,e).addScalar(.5).multiply(n),i!==void 0?(po.x=s*us.x-i*us.y,po.y=i*us.x+s*us.y):po.copy(us),r.copy(t),r.x+=po.x,r.y+=po.y,r.applyMatrix4(l0)}var rc=new R,Rm=new R,Bc=class extends ue{constructor(){super(),this.isLOD=!0,this._currentLevel=0,this.type="LOD",Object.defineProperties(this,{levels:{enumerable:!0,value:[]}}),this.autoUpdate=!0}copy(t){super.copy(t,!1);let e=t.levels;for(let n=0,i=e.length;n0){let n,i;for(n=1,i=e.length;n0){rc.setFromMatrixPosition(this.matrixWorld);let i=t.ray.origin.distanceTo(rc);this.getObjectForDistance(i).raycast(t,e)}}update(t){let e=this.levels;if(e.length>1){rc.setFromMatrixPosition(t.matrixWorld),Rm.setFromMatrixPosition(this.matrixWorld);let n=rc.distanceTo(Rm)/t.zoom;e[0].object.visible=!0;let i,s;for(i=1,s=e.length;i=o)e[i-1].object.visible=!1,e[i].object.visible=!0;else break}for(this._currentLevel=i-1;i1?null:e.copy(t.start).addScaledVector(n,s)}intersectsLine(t){let e=this.distanceToPoint(t.start),n=this.distanceToPoint(t.end);return e<0&&n>0||n<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){let n=e||xy.getNormalMatrix(t),i=this.coplanarPoint(of).applyMatrix4(t),s=this.normal.applyMatrix3(n).normalize();return this.constant=-i.dot(s),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return new this.constructor().copy(this)}},sr=new Ve,vy=new q(.5,.5),ac=new R,Oi=class{constructor(t=new _n,e=new _n,n=new _n,i=new _n,s=new _n,o=new _n){this.planes=[t,e,n,i,s,o]}set(t,e,n,i,s,o){let a=this.planes;return a[0].copy(t),a[1].copy(e),a[2].copy(n),a[3].copy(i),a[4].copy(s),a[5].copy(o),this}copy(t){let e=this.planes;for(let n=0;n<6;n++)e[n].copy(t.planes[n]);return this}setFromProjectionMatrix(t,e=Rn,n=!1){let i=this.planes,s=t.elements,o=s[0],a=s[1],c=s[2],l=s[3],f=s[4],h=s[5],u=s[6],d=s[7],g=s[8],x=s[9],p=s[10],m=s[11],v=s[12],_=s[13],y=s[14],b=s[15];if(i[0].setComponents(l-o,d-f,m-g,b-v).normalize(),i[1].setComponents(l+o,d+f,m+g,b+v).normalize(),i[2].setComponents(l+a,d+h,m+x,b+_).normalize(),i[3].setComponents(l-a,d-h,m-x,b-_).normalize(),n)i[4].setComponents(c,u,p,y).normalize(),i[5].setComponents(l-c,d-u,m-p,b-y).normalize();else if(i[4].setComponents(l-c,d-u,m-p,b-y).normalize(),e===Rn)i[5].setComponents(l+c,d+u,m+p,b+y).normalize();else if(e===vs)i[5].setComponents(c,u,p,y).normalize();else throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+e);return this}intersectsObject(t){if(t.boundingSphere!==void 0)t.boundingSphere===null&&t.computeBoundingSphere(),sr.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{let e=t.geometry;e.boundingSphere===null&&e.computeBoundingSphere(),sr.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(sr)}intersectsSprite(t){sr.center.set(0,0,0);let e=vy.distanceTo(t.center);return sr.radius=.7071067811865476+e,sr.applyMatrix4(t.matrixWorld),this.intersectsSphere(sr)}intersectsSphere(t){let e=this.planes,n=t.center,i=-t.radius;for(let s=0;s<6;s++)if(e[s].distanceToPoint(n)0?t.max.x:t.min.x,ac.y=i.normal.y>0?t.max.y:t.min.y,ac.z=i.normal.z>0?t.max.z:t.min.z,i.distanceToPoint(ac)<0)return!1}return!0}containsPoint(t){let e=this.planes;for(let n=0;n<6;n++)if(e[n].distanceToPoint(t)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}},ti=new gt,ei=new Oi,Vc=class r{constructor(){this.coordinateSystem=Rn}intersectsObject(t,e){if(!e.isArrayCamera||e.cameras.length===0)return!1;for(let n=0;n=s.length&&s.push({start:-1,count:-1,z:-1,index:-1});let a=s[this.index];o.push(a),this.index++,a.start=t,a.count=e,a.z=n,a.index=i}reset(){this.list.length=0,this.index=0}},gn=new gt,by=new ft(1,1,1),Bm=new Oi,Sy=new Vc,cc=new se,or=new Ve,vo=new R,Om=new R,My=new R,cf=new If,rn=new Me,lc=[];function Ty(r,t,e=0){let n=t.itemSize;if(r.isInterleavedBufferAttribute||r.array.constructor!==t.array.constructor){let i=r.count;for(let s=0;s65535?new Uint32Array(i):new Uint16Array(i);e.setIndex(new Ot(s,1))}this._geometryInitialized=!0}}_validateGeometry(t){let e=this.geometry;if(!!t.getIndex()!=!!e.getIndex())throw new Error('THREE.BatchedMesh: All geometries must consistently have "index".');for(let n in e.attributes){if(!t.hasAttribute(n))throw new Error(`THREE.BatchedMesh: Added geometry missing "${n}". All geometries must have consistent attributes.`);let i=t.getAttribute(n),s=e.getAttribute(n);if(i.itemSize!==s.itemSize||i.normalized!==s.normalized)throw new Error("THREE.BatchedMesh: All attributes must have a consistent itemSize and normalized value.")}}validateInstanceId(t){let e=this._instanceInfo;if(t<0||t>=e.length||e[t].active===!1)throw new Error(`THREE.BatchedMesh: Invalid instanceId ${t}. Instance is either out of range or has been deleted.`)}validateGeometryId(t){let e=this._geometryInfo;if(t<0||t>=e.length||e[t].active===!1)throw new Error(`THREE.BatchedMesh: Invalid geometryId ${t}. Geometry is either out of range or has been deleted.`)}setCustomSort(t){return this.customSort=t,this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new se);let t=this.boundingBox,e=this._instanceInfo;t.makeEmpty();for(let n=0,i=e.length;n=this.maxInstanceCount&&this._availableInstanceIds.length===0)throw new Error("THREE.BatchedMesh: Maximum item count reached.");let n={visible:!0,active:!0,geometryIndex:t},i=null;this._availableInstanceIds.length>0?(this._availableInstanceIds.sort(af),i=this._availableInstanceIds.shift(),this._instanceInfo[i]=n):(i=this._instanceInfo.length,this._instanceInfo.push(n));let s=this._matricesTexture;gn.identity().toArray(s.image.data,i*16),s.needsUpdate=!0;let o=this._colorsTexture;return o&&(by.toArray(o.image.data,i*4),o.needsUpdate=!0),this._visibilityChanged=!0,i}addGeometry(t,e=-1,n=-1){this._initializeGeometry(t),this._validateGeometry(t);let i={vertexStart:-1,vertexCount:-1,reservedVertexCount:-1,indexStart:-1,indexCount:-1,reservedIndexCount:-1,start:-1,count:-1,boundingBox:null,boundingSphere:null,active:!0},s=this._geometryInfo;i.vertexStart=this._nextVertexStart,i.reservedVertexCount=e===-1?t.getAttribute("position").count:e;let o=t.getIndex();if(o!==null&&(i.indexStart=this._nextIndexStart,i.reservedIndexCount=n===-1?o.count:n),i.indexStart!==-1&&i.indexStart+i.reservedIndexCount>this._maxIndexCount||i.vertexStart+i.reservedVertexCount>this._maxVertexCount)throw new Error("THREE.BatchedMesh: Reserved space request exceeds the maximum buffer size.");let c;return this._availableGeometryIds.length>0?(this._availableGeometryIds.sort(af),c=this._availableGeometryIds.shift(),s[c]=i):(c=this._geometryCount,this._geometryCount++,s.push(i)),this.setGeometryAt(c,t),this._nextIndexStart=i.indexStart+i.reservedIndexCount,this._nextVertexStart=i.vertexStart+i.reservedVertexCount,c}setGeometryAt(t,e){if(t>=this._geometryCount)throw new Error("THREE.BatchedMesh: Maximum geometry count reached.");this._validateGeometry(e);let n=this.geometry,i=n.getIndex()!==null,s=n.getIndex(),o=e.getIndex(),a=this._geometryInfo[t];if(i&&o.count>a.reservedIndexCount||e.attributes.position.count>a.reservedVertexCount)throw new Error("THREE.BatchedMesh: Reserved space not large enough for provided geometry.");let c=a.vertexStart,l=a.reservedVertexCount;a.vertexCount=e.getAttribute("position").count;for(let f in n.attributes){let h=e.getAttribute(f),u=n.getAttribute(f);Ty(h,u,c);let d=h.itemSize;for(let g=h.count,x=l;g=e.length||e[t].active===!1)return this;let n=this._instanceInfo;for(let i=0,s=n.length;ia).sort((o,a)=>n[o].vertexStart-n[a].vertexStart),s=this.geometry;for(let o=0,a=n.length;o=this._geometryCount)return null;let n=this.geometry,i=this._geometryInfo[t];if(i.boundingBox===null){let s=new se,o=n.index,a=n.attributes.position;for(let c=i.start,l=i.start+i.count;c=this._geometryCount)return null;let n=this.geometry,i=this._geometryInfo[t];if(i.boundingSphere===null){let s=new Ve;this.getBoundingBoxAt(t,cc),cc.getCenter(s.center);let o=n.index,a=n.attributes.position,c=0;for(let l=i.start,f=i.start+i.count;la.active);if(Math.max(...n.map(a=>a.vertexStart+a.reservedVertexCount))>t)throw new Error(`BatchedMesh: Geometry vertex values are being used outside the range ${e}. Cannot shrink further.`);if(this.geometry.index&&Math.max(...n.map(c=>c.indexStart+c.reservedIndexCount))>e)throw new Error(`BatchedMesh: Geometry index values are being used outside the range ${e}. Cannot shrink further.`);let s=this.geometry;s.dispose(),this._maxVertexCount=t,this._maxIndexCount=e,this._geometryInitialized&&(this._geometryInitialized=!1,this.geometry=new Ft,this._initializeGeometry(s));let o=this.geometry;s.index&&ar(s.index.array,o.index.array);for(let a in s.attributes)ar(s.attributes[a].array,o.attributes[a].array)}raycast(t,e){let n=this._instanceInfo,i=this._geometryInfo,s=this.matrixWorld,o=this.geometry;rn.material=this.material,rn.geometry.index=o.index,rn.geometry.attributes=o.attributes,rn.geometry.boundingBox===null&&(rn.geometry.boundingBox=new se),rn.geometry.boundingSphere===null&&(rn.geometry.boundingSphere=new Ve);for(let a=0,c=n.length;a({...e,boundingBox:e.boundingBox!==null?e.boundingBox.clone():null,boundingSphere:e.boundingSphere!==null?e.boundingSphere.clone():null})),this._instanceInfo=t._instanceInfo.map(e=>({...e})),this._availableInstanceIds=t._availableInstanceIds.slice(),this._availableGeometryIds=t._availableGeometryIds.slice(),this._nextIndexStart=t._nextIndexStart,this._nextVertexStart=t._nextVertexStart,this._geometryCount=t._geometryCount,this._maxInstanceCount=t._maxInstanceCount,this._maxVertexCount=t._maxVertexCount,this._maxIndexCount=t._maxIndexCount,this._geometryInitialized=t._geometryInitialized,this._multiDrawCounts=t._multiDrawCounts.slice(),this._multiDrawStarts=t._multiDrawStarts.slice(),this._indirectTexture=t._indirectTexture.clone(),this._indirectTexture.image.data=this._indirectTexture.image.data.slice(),this._matricesTexture=t._matricesTexture.clone(),this._matricesTexture.image.data=this._matricesTexture.image.data.slice(),this._colorsTexture!==null&&(this._colorsTexture=t._colorsTexture.clone(),this._colorsTexture.image.data=this._colorsTexture.image.data.slice()),this}dispose(){this.geometry.dispose(),this._matricesTexture.dispose(),this._matricesTexture=null,this._indirectTexture.dispose(),this._indirectTexture=null,this._colorsTexture!==null&&(this._colorsTexture.dispose(),this._colorsTexture=null)}onBeforeRender(t,e,n,i,s){if(!this._visibilityChanged&&!this.perObjectFrustumCulled&&!this.sortObjects)return;let o=i.getIndex(),a=o===null?1:o.array.BYTES_PER_ELEMENT,c=this._instanceInfo,l=this._multiDrawStarts,f=this._multiDrawCounts,h=this._geometryInfo,u=this.perObjectFrustumCulled,d=this._indirectTexture,g=d.image.data,x=n.isArrayCamera?Sy:Bm;u&&!n.isArrayCamera&&(gn.multiplyMatrices(n.projectionMatrix,n.matrixWorldInverse).multiply(this.matrixWorld),Bm.setFromProjectionMatrix(gn,n.coordinateSystem,n.reversedDepth));let p=0;if(this.sortObjects){gn.copy(this.matrixWorld).invert(),vo.setFromMatrixPosition(n.matrixWorld).applyMatrix4(gn),Om.set(0,0,-1).transformDirection(n.matrixWorld).transformDirection(gn);for(let _=0,y=c.length;_0){let i=e[n[0]];if(i!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,o=i.length;sn)return;lf.applyMatrix4(r.matrixWorld);let l=t.ray.origin.distanceTo(lf);if(!(lt.far))return{distance:l,point:km.clone().applyMatrix4(r.matrixWorld),index:o,face:null,faceIndex:null,barycoord:null,object:r}}var Vm=new R,Hm=new R,kn=class extends ri{constructor(t,e){super(t,e),this.isLineSegments=!0,this.type="LineSegments"}computeLineDistances(){let t=this.geometry;if(t.index===null){let e=t.attributes.position,n=[];for(let i=0,s=e.count;i0){let i=e[n[0]];if(i!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,o=i.length;si.far)return;s.push({distance:l,distanceToRay:Math.sqrt(a),point:c,index:t,face:null,faceIndex:null,barycoord:null,object:o})}}var Yc=class extends Oe{constructor(t,e,n,i,s=re,o=re,a,c,l){super(t,e,n,i,s,o,a,c,l),this.isVideoTexture=!0,this.generateMipmaps=!1,this._requestVideoFrameCallbackId=0;let f=this;function h(){f.needsUpdate=!0,f._requestVideoFrameCallbackId=t.requestVideoFrameCallback(h)}"requestVideoFrameCallback"in t&&(this._requestVideoFrameCallbackId=t.requestVideoFrameCallback(h))}clone(){return new this.constructor(this.image).copy(this)}update(){let t=this.image;"requestVideoFrameCallback"in t===!1&&t.readyState>=t.HAVE_CURRENT_DATA&&(this.needsUpdate=!0)}dispose(){this._requestVideoFrameCallbackId!==0&&this.source.data.cancelVideoFrameCallback(this._requestVideoFrameCallbackId),super.dispose()}},Df=class extends Yc{constructor(t,e,n,i,s,o,a,c){super({},t,e,n,i,s,o,a,c),this.isVideoFrameTexture=!0}update(){}clone(){return new this.constructor().copy(this)}setFrame(t){this.image=t,this.needsUpdate=!0}},Ff=class extends Oe{constructor(t,e){super({width:t,height:e}),this.isFramebufferTexture=!0,this.magFilter=Vt,this.minFilter=Vt,this.generateMipmaps=!1,this.needsUpdate=!0}},Es=class extends Oe{constructor(t,e,n,i,s,o,a,c,l,f,h,u){super(null,o,a,c,l,f,i,s,h,u),this.isCompressedTexture=!0,this.image={width:e,height:n},this.mipmaps=t,this.flipY=!1,this.generateMipmaps=!1}},Lf=class extends Es{constructor(t,e,n,i,s,o){super(t,e,n,s,o),this.isCompressedArrayTexture=!0,this.image.depth=i,this.wrapR=we,this.layerUpdates=new Set}addLayerUpdate(t){this.layerUpdates.add(t)}clearLayerUpdates(){this.layerUpdates.clear()}},Nf=class extends Es{constructor(t,e,n){super(void 0,t[0].width,t[0].height,e,n,Si),this.isCompressedCubeTexture=!0,this.isCubeTexture=!0,this.image=t}},Uf=class extends Oe{constructor(t,e,n,i,s,o,a,c,l){super(t,e,n,i,s,o,a,c,l),this.isCanvasTexture=!0,this.needsUpdate=!0}},Oo=class extends Oe{constructor(t,e,n=an,i,s,o,a=Vt,c=Vt,l,f=xs,h=1){if(f!==xs&&f!==zs)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");let u={width:t,height:e,depth:h};super(u,i,s,o,a,c,f,n,l),this.isDepthTexture=!0,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(t){return super.copy(t),this.source=new Bn(Object.assign({},t.image)),this.compareFunction=t.compareFunction,this}toJSON(t){let e=super.toJSON(t);return this.compareFunction!==null&&(e.compareFunction=this.compareFunction),e}},zo=class extends Oe{constructor(t=null){super(),this.sourceTexture=t,this.isExternalTexture=!0}copy(t){return super.copy(t),this.sourceTexture=t.sourceTexture,this}},$c=class r extends Ft{constructor(t=1,e=1,n=4,i=8,s=1){super(),this.type="CapsuleGeometry",this.parameters={radius:t,height:e,capSegments:n,radialSegments:i,heightSegments:s},e=Math.max(0,e),n=Math.max(1,Math.floor(n)),i=Math.max(3,Math.floor(i)),s=Math.max(1,Math.floor(s));let o=[],a=[],c=[],l=[],f=e/2,h=Math.PI/2*t,u=e,d=2*h+u,g=n*2+s,x=i+1,p=new R,m=new R;for(let v=0;v<=g;v++){let _=0,y=0,b=0,T=0;if(v<=n){let M=v/n,S=M*Math.PI/2;y=-f-t*Math.cos(S),b=t*Math.sin(S),T=-t*Math.cos(S),_=M*h}else if(v<=n+s){let M=(v-n)/s;y=-f+M*e,b=t,T=0,_=h+M*u}else{let M=(v-n-s)/n,S=M*Math.PI/2;y=f+t*Math.sin(S),b=t*Math.cos(S),T=t*Math.sin(S),_=h+u+M*h}let w=Math.max(0,Math.min(1,_/d)),E=0;v===0?E=.5/i:v===g&&(E=-.5/i);for(let M=0;M<=i;M++){let S=M/i,I=S*Math.PI*2,P=Math.sin(I),L=Math.cos(I);m.x=-b*L,m.y=y,m.z=b*P,a.push(m.x,m.y,m.z),p.set(-b*L,T,b*P),p.normalize(),c.push(p.x,p.y,p.z),l.push(S+E,w)}if(v>0){let M=(v-1)*x;for(let S=0;S0&&_(!0),e>0&&_(!1)),this.setIndex(f),this.setAttribute("position",new bt(h,3)),this.setAttribute("normal",new bt(u,3)),this.setAttribute("uv",new bt(d,2));function v(){let y=new R,b=new R,T=0,w=(e-t)/n;for(let E=0;E<=s;E++){let M=[],S=E/s,I=S*(e-t)+t;for(let P=0;P<=i;P++){let L=P/i,N=L*c+a,z=Math.sin(N),V=Math.cos(N);b.x=I*z,b.y=-S*n+p,b.z=I*V,h.push(b.x,b.y,b.z),y.set(z,w,V).normalize(),u.push(y.x,y.y,y.z),d.push(L,1-S),M.push(g++)}x.push(M)}for(let E=0;E0||M!==0)&&(f.push(S,I,L),T+=3),(e>0||M!==s-1)&&(f.push(I,P,L),T+=3)}l.addGroup(m,T,0),m+=T}function _(y){let b=g,T=new q,w=new R,E=0,M=y===!0?t:e,S=y===!0?1:-1;for(let P=1;P<=i;P++)h.push(0,p*S,0),u.push(0,S,0),d.push(.5,.5),g++;let I=g;for(let P=0;P<=i;P++){let N=P/i*c+a,z=Math.cos(N),V=Math.sin(N);w.x=M*V,w.y=p*S,w.z=M*z,h.push(w.x,w.y,w.z),u.push(0,S,0),T.x=z*.5+.5,T.y=V*.5*S+.5,d.push(T.x,T.y),g++}for(let P=0;P.9&&w<.1&&(_<.2&&(o[v+0]+=1),y<.2&&(o[v+2]+=1),b<.2&&(o[v+4]+=1))}}function u(v){s.push(v.x,v.y,v.z)}function d(v,_){let y=v*3;_.x=t[y+0],_.y=t[y+1],_.z=t[y+2]}function g(){let v=new R,_=new R,y=new R,b=new R,T=new q,w=new q,E=new q;for(let M=0,S=0;M0)c=i-1;else{c=i;break}if(i=c,n[i]===o)return i/(s-1);let f=n[i],u=n[i+1]-f,d=(o-f)/u;return(i+d)/(s-1)}getTangent(t,e){let i=t-1e-4,s=t+1e-4;i<0&&(i=0),s>1&&(s=1);let o=this.getPoint(i),a=this.getPoint(s),c=e||(o.isVector2?new q:new R);return c.copy(a).sub(o).normalize(),c}getTangentAt(t,e){let n=this.getUtoTmapping(t);return this.getTangent(n,e)}computeFrenetFrames(t,e=!1){let n=new R,i=[],s=[],o=[],a=new R,c=new gt;for(let d=0;d<=t;d++){let g=d/t;i[d]=this.getTangentAt(g,new R)}s[0]=new R,o[0]=new R;let l=Number.MAX_VALUE,f=Math.abs(i[0].x),h=Math.abs(i[0].y),u=Math.abs(i[0].z);f<=l&&(l=f,n.set(1,0,0)),h<=l&&(l=h,n.set(0,1,0)),u<=l&&n.set(0,0,1),a.crossVectors(i[0],n).normalize(),s[0].crossVectors(i[0],a),o[0].crossVectors(i[0],s[0]);for(let d=1;d<=t;d++){if(s[d]=s[d-1].clone(),o[d]=o[d-1].clone(),a.crossVectors(i[d-1],i[d]),a.length()>Number.EPSILON){a.normalize();let g=Math.acos(Bt(i[d-1].dot(i[d]),-1,1));s[d].applyMatrix4(c.makeRotationAxis(a,g))}o[d].crossVectors(i[d],s[d])}if(e===!0){let d=Math.acos(Bt(s[0].dot(s[t]),-1,1));d/=t,i[0].dot(a.crossVectors(s[0],s[t]))>0&&(d=-d);for(let g=1;g<=t;g++)s[g].applyMatrix4(c.makeRotationAxis(i[g],d*g)),o[g].crossVectors(i[g],s[g])}return{tangents:i,normals:s,binormals:o}}clone(){return new this.constructor().copy(this)}copy(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}toJSON(){let t={metadata:{version:4.7,type:"Curve",generator:"Curve.toJSON"}};return t.arcLengthDivisions=this.arcLengthDivisions,t.type=this.type,t}fromJSON(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}},Rs=class extends Pn{constructor(t=0,e=0,n=1,i=1,s=0,o=Math.PI*2,a=!1,c=0){super(),this.isEllipseCurve=!0,this.type="EllipseCurve",this.aX=t,this.aY=e,this.xRadius=n,this.yRadius=i,this.aStartAngle=s,this.aEndAngle=o,this.aClockwise=a,this.aRotation=c}getPoint(t,e=new q){let n=e,i=Math.PI*2,s=this.aEndAngle-this.aStartAngle,o=Math.abs(s)i;)s-=i;s0?0:(Math.floor(Math.abs(a)/s)+1)*s:c===0&&a===s-1&&(a=s-2,c=1);let l,f;this.closed||a>0?l=i[(a-1)%s]:(xc.subVectors(i[0],i[1]).add(i[0]),l=xc);let h=i[a%s],u=i[(a+1)%s];if(this.closed||a+2i.length-2?i.length-1:o+1],h=i[o>i.length-3?i.length-1:o+2];return n.set(Xm(a,c.x,l.x,f.x,h.x),Xm(a,c.y,l.y,f.y,h.y)),n}copy(t){super.copy(t),this.points=[];for(let e=0,n=t.points.length;e=n){let o=i[s]-n,a=this.curves[s],c=a.getLength(),l=c===0?0:1-o/c;return a.getPointAt(l,e)}s++}return null}getLength(){let t=this.getCurveLengths();return t[t.length-1]}updateArcLengths(){this.needsUpdate=!0,this.cacheLengths=null,this.getCurveLengths()}getCurveLengths(){if(this.cacheLengths&&this.cacheLengths.length===this.curves.length)return this.cacheLengths;let t=[],e=0;for(let n=0,i=this.curves.length;n1&&!e[e.length-1].equals(e[0])&&e.push(e[0]),e}copy(t){super.copy(t),this.curves=[];for(let e=0,n=t.curves.length;e0){let h=l.getPoint(0);h.equals(this.currentPoint)||this.lineTo(h.x,h.y)}this.curves.push(l);let f=l.getPoint(1);return this.currentPoint.copy(f),this}copy(t){return super.copy(t),this.currentPoint.copy(t.currentPoint),this}toJSON(){let t=super.toJSON();return t.currentPoint=this.currentPoint.toArray(),t}fromJSON(t){return super.fromJSON(t),this.currentPoint.fromArray(t.currentPoint),this}},_i=class extends Cs{constructor(t){super(t),this.uuid=Cn(),this.type="Shape",this.holes=[]}getPointsHoles(t){let e=[];for(let n=0,i=this.holes.length;n80*e){a=1/0,c=1/0;let f=-1/0,h=-1/0;for(let u=e;uf&&(f=d),g>h&&(h=g)}l=Math.max(f-a,h-c),l=l!==0?32767/l:0}return Yo(s,o,e,a,c,l,0),o}function u0(r,t,e,n,i){let s;if(i===$y(r,t,e,n)>0)for(let o=t;o=t;o-=n)s=qm(o/n|0,r[o],r[o+1],s);return s&&Is(s,s.next)&&(Zo(s),s=s.next),s}function wr(r,t){if(!r)return r;t||(t=r);let e=r,n;do if(n=!1,!e.steiner&&(Is(e,e.next)||Ce(e.prev,e,e.next)===0)){if(Zo(e),e=t=e.prev,e===e.next)break;n=!0}else e=e.next;while(n||e!==t);return t}function Yo(r,t,e,n,i,s,o){if(!r)return;!o&&s&&Hy(r,n,i,s);let a=r;for(;r.prev!==r.next;){let c=r.prev,l=r.next;if(s?Ly(r,n,i,s):Fy(r)){t.push(c.i,r.i,l.i),Zo(r),r=l.next,a=l.next;continue}if(r=l,r===a){o?o===1?(r=Ny(wr(r),t),Yo(r,t,e,n,i,s,2)):o===2&&Uy(r,t,e,n,i,s):Yo(wr(r),t,e,n,i,s,1);break}}}function Fy(r){let t=r.prev,e=r,n=r.next;if(Ce(t,e,n)>=0)return!1;let i=t.x,s=e.x,o=n.x,a=t.y,c=e.y,l=n.y,f=Math.min(i,s,o),h=Math.min(a,c,l),u=Math.max(i,s,o),d=Math.max(a,c,l),g=n.next;for(;g!==t;){if(g.x>=f&&g.x<=u&&g.y>=h&&g.y<=d&&So(i,a,s,c,o,l,g.x,g.y)&&Ce(g.prev,g,g.next)>=0)return!1;g=g.next}return!0}function Ly(r,t,e,n){let i=r.prev,s=r,o=r.next;if(Ce(i,s,o)>=0)return!1;let a=i.x,c=s.x,l=o.x,f=i.y,h=s.y,u=o.y,d=Math.min(a,c,l),g=Math.min(f,h,u),x=Math.max(a,c,l),p=Math.max(f,h,u),m=Bf(d,g,t,e,n),v=Bf(x,p,t,e,n),_=r.prevZ,y=r.nextZ;for(;_&&_.z>=m&&y&&y.z<=v;){if(_.x>=d&&_.x<=x&&_.y>=g&&_.y<=p&&_!==i&&_!==o&&So(a,f,c,h,l,u,_.x,_.y)&&Ce(_.prev,_,_.next)>=0||(_=_.prevZ,y.x>=d&&y.x<=x&&y.y>=g&&y.y<=p&&y!==i&&y!==o&&So(a,f,c,h,l,u,y.x,y.y)&&Ce(y.prev,y,y.next)>=0))return!1;y=y.nextZ}for(;_&&_.z>=m;){if(_.x>=d&&_.x<=x&&_.y>=g&&_.y<=p&&_!==i&&_!==o&&So(a,f,c,h,l,u,_.x,_.y)&&Ce(_.prev,_,_.next)>=0)return!1;_=_.prevZ}for(;y&&y.z<=v;){if(y.x>=d&&y.x<=x&&y.y>=g&&y.y<=p&&y!==i&&y!==o&&So(a,f,c,h,l,u,y.x,y.y)&&Ce(y.prev,y,y.next)>=0)return!1;y=y.nextZ}return!0}function Ny(r,t){let e=r;do{let n=e.prev,i=e.next.next;!Is(n,i)&&f0(n,e,e.next,i)&&$o(n,i)&&$o(i,n)&&(t.push(n.i,e.i,i.i),Zo(e),Zo(e.next),e=r=i),e=e.next}while(e!==r);return wr(e)}function Uy(r,t,e,n,i,s){let o=r;do{let a=o.next.next;for(;a!==o.prev;){if(o.i!==a.i&&Xy(o,a)){let c=d0(o,a);o=wr(o,o.next),c=wr(c,c.next),Yo(o,t,e,n,i,s,0),Yo(c,t,e,n,i,s,0);return}a=a.next}o=o.next}while(o!==r)}function By(r,t,e,n){let i=[];for(let s=0,o=t.length;s=e.next.y&&e.next.y!==e.y){let h=e.x+(i-e.y)*(e.next.x-e.x)/(e.next.y-e.y);if(h<=n&&h>s&&(s=h,o=e.x=e.x&&e.x>=c&&n!==e.x&&h0(io.x||e.x===o.x&&Vy(o,e)))&&(o=e,f=h)}e=e.next}while(e!==a);return o}function Vy(r,t){return Ce(r.prev,r,t.prev)<0&&Ce(t.next,r,r.next)<0}function Hy(r,t,e,n){let i=r;do i.z===0&&(i.z=Bf(i.x,i.y,t,e,n)),i.prevZ=i.prev,i.nextZ=i.next,i=i.next;while(i!==r);i.prevZ.nextZ=null,i.prevZ=null,Gy(i)}function Gy(r){let t,e=1;do{let n=r,i;r=null;let s=null;for(t=0;n;){t++;let o=n,a=0;for(let l=0;l0||c>0&&o;)a!==0&&(c===0||!o||n.z<=o.z)?(i=n,n=n.nextZ,a--):(i=o,o=o.nextZ,c--),s?s.nextZ=i:r=i,i.prevZ=s,s=i;n=o}s.nextZ=null,e*=2}while(t>1);return r}function Bf(r,t,e,n,i){return r=(r-e)*i|0,t=(t-n)*i|0,r=(r|r<<8)&16711935,r=(r|r<<4)&252645135,r=(r|r<<2)&858993459,r=(r|r<<1)&1431655765,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,r|t<<1}function Wy(r){let t=r,e=r;do(t.x=(r-o)*(s-a)&&(r-o)*(n-a)>=(e-o)*(t-a)&&(e-o)*(s-a)>=(i-o)*(n-a)}function So(r,t,e,n,i,s,o,a){return!(r===o&&t===a)&&h0(r,t,e,n,i,s,o,a)}function Xy(r,t){return r.next.i!==t.i&&r.prev.i!==t.i&&!qy(r,t)&&($o(r,t)&&$o(t,r)&&Yy(r,t)&&(Ce(r.prev,r,t.prev)||Ce(r,t.prev,t))||Is(r,t)&&Ce(r.prev,r,r.next)>0&&Ce(t.prev,t,t.next)>0)}function Ce(r,t,e){return(t.y-r.y)*(e.x-t.x)-(t.x-r.x)*(e.y-t.y)}function Is(r,t){return r.x===t.x&&r.y===t.y}function f0(r,t,e,n){let i=_c(Ce(r,t,e)),s=_c(Ce(r,t,n)),o=_c(Ce(e,n,r)),a=_c(Ce(e,n,t));return!!(i!==s&&o!==a||i===0&&vc(r,e,t)||s===0&&vc(r,n,t)||o===0&&vc(e,r,n)||a===0&&vc(e,t,n))}function vc(r,t,e){return t.x<=Math.max(r.x,e.x)&&t.x>=Math.min(r.x,e.x)&&t.y<=Math.max(r.y,e.y)&&t.y>=Math.min(r.y,e.y)}function _c(r){return r>0?1:r<0?-1:0}function qy(r,t){let e=r;do{if(e.i!==r.i&&e.next.i!==r.i&&e.i!==t.i&&e.next.i!==t.i&&f0(e,e.next,r,t))return!0;e=e.next}while(e!==r);return!1}function $o(r,t){return Ce(r.prev,r,r.next)<0?Ce(r,t,r.next)>=0&&Ce(r,r.prev,t)>=0:Ce(r,t,r.prev)<0||Ce(r,r.next,t)<0}function Yy(r,t){let e=r,n=!1,i=(r.x+t.x)/2,s=(r.y+t.y)/2;do e.y>s!=e.next.y>s&&e.next.y!==e.y&&i<(e.next.x-e.x)*(s-e.y)/(e.next.y-e.y)+e.x&&(n=!n),e=e.next;while(e!==r);return n}function d0(r,t){let e=Of(r.i,r.x,r.y),n=Of(t.i,t.x,t.y),i=r.next,s=t.prev;return r.next=t,t.prev=r,e.next=i,i.prev=e,n.next=e,e.prev=n,s.next=n,n.prev=s,n}function qm(r,t,e,n){let i=Of(r,t,e);return n?(i.next=n.next,i.prev=n,n.next.prev=i,n.next=i):(i.prev=i,i.next=i),i}function Zo(r){r.next.prev=r.prev,r.prev.next=r.next,r.prevZ&&(r.prevZ.nextZ=r.nextZ),r.nextZ&&(r.nextZ.prevZ=r.prevZ)}function Of(r,t,e){return{i:r,x:t,y:e,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}function $y(r,t,e,n){let i=0;for(let s=t,o=e-n;s2&&r[t-1].equals(r[0])&&r.pop()}function $m(r,t){for(let e=0;eNumber.EPSILON){let X=Math.sqrt(A),et=Math.sqrt(Wt*Wt+D*D),Y=K.x-qt/X,It=K.y+ht/X,lt=J.x-D/et,Et=J.y+Wt/et,Rt=((lt-Y)*D-(Et-It)*Wt)/(ht*D-qt*Wt);Z=Y+ht*Rt-nt.x,ut=It+qt*Rt-nt.y;let rt=Z*Z+ut*ut;if(rt<=2)return new q(Z,ut);it=Math.sqrt(rt/2)}else{let X=!1;ht>Number.EPSILON?Wt>Number.EPSILON&&(X=!0):ht<-Number.EPSILON?Wt<-Number.EPSILON&&(X=!0):Math.sign(qt)===Math.sign(D)&&(X=!0),X?(Z=-qt,ut=ht,it=Math.sqrt(A)):(Z=ht,ut=qt,it=Math.sqrt(A/2))}return new q(Z/it,ut/it)}let ct=[];for(let nt=0,K=z.length,J=K-1,Z=nt+1;nt=0;nt--){let K=nt/p,J=d*Math.cos(K*Math.PI/2),Z=g*Math.sin(K*Math.PI/2)+x;for(let ut=0,it=z.length;ut=0;){let Z=J,ut=J-1;ut<0&&(ut=nt.length-1);for(let it=0,ht=f+p*2;it0)&&d.push(_,y,T),(m!==n-1||c0!=t>0&&this.version++,this._anisotropy=t}get clearcoat(){return this._clearcoat}set clearcoat(t){this._clearcoat>0!=t>0&&this.version++,this._clearcoat=t}get iridescence(){return this._iridescence}set iridescence(t){this._iridescence>0!=t>0&&this.version++,this._iridescence=t}get dispersion(){return this._dispersion}set dispersion(t){this._dispersion>0!=t>0&&this.version++,this._dispersion=t}get sheen(){return this._sheen}set sheen(t){this._sheen>0!=t>0&&this.version++,this._sheen=t}get transmission(){return this._transmission}set transmission(t){this._transmission>0!=t>0&&this.version++,this._transmission=t}copy(t){return super.copy(t),this.defines={STANDARD:"",PHYSICAL:""},this.anisotropy=t.anisotropy,this.anisotropyRotation=t.anisotropyRotation,this.anisotropyMap=t.anisotropyMap,this.clearcoat=t.clearcoat,this.clearcoatMap=t.clearcoatMap,this.clearcoatRoughness=t.clearcoatRoughness,this.clearcoatRoughnessMap=t.clearcoatRoughnessMap,this.clearcoatNormalMap=t.clearcoatNormalMap,this.clearcoatNormalScale.copy(t.clearcoatNormalScale),this.dispersion=t.dispersion,this.ior=t.ior,this.iridescence=t.iridescence,this.iridescenceMap=t.iridescenceMap,this.iridescenceIOR=t.iridescenceIOR,this.iridescenceThicknessRange=[...t.iridescenceThicknessRange],this.iridescenceThicknessMap=t.iridescenceThicknessMap,this.sheen=t.sheen,this.sheenColor.copy(t.sheenColor),this.sheenColorMap=t.sheenColorMap,this.sheenRoughness=t.sheenRoughness,this.sheenRoughnessMap=t.sheenRoughnessMap,this.transmission=t.transmission,this.transmissionMap=t.transmissionMap,this.thickness=t.thickness,this.thicknessMap=t.thicknessMap,this.attenuationDistance=t.attenuationDistance,this.attenuationColor.copy(t.attenuationColor),this.specularIntensity=t.specularIntensity,this.specularIntensityMap=t.specularIntensityMap,this.specularColor.copy(t.specularColor),this.specularColorMap=t.specularColorMap,this}},xl=class extends Je{constructor(t){super(),this.isMeshPhongMaterial=!0,this.type="MeshPhongMaterial",this.color=new ft(16777215),this.specular=new ft(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new ft(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=qi,this.normalScale=new q(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new In,this.combine=ua,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.specular.copy(t.specular),this.shininess=t.shininess,this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this.fog=t.fog,this}},vl=class extends Je{constructor(t){super(),this.isMeshToonMaterial=!0,this.defines={TOON:""},this.type="MeshToonMaterial",this.color=new ft(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new ft(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=qi,this.normalScale=new q(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.gradientMap=t.gradientMap,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.alphaMap=t.alphaMap,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}},_l=class extends Je{constructor(t){super(),this.isMeshNormalMaterial=!0,this.type="MeshNormalMaterial",this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=qi,this.normalScale=new q(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.flatShading=!1,this.setValues(t)}copy(t){return super.copy(t),this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.flatShading=t.flatShading,this}},yl=class extends Je{constructor(t){super(),this.isMeshLambertMaterial=!0,this.type="MeshLambertMaterial",this.color=new ft(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new ft(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=qi,this.normalScale=new q(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new In,this.combine=ua,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this.fog=t.fog,this}},jo=class extends Je{constructor(t){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=Zg,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(t)}copy(t){return super.copy(t),this.depthPacking=t.depthPacking,this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this}},ta=class extends Je{constructor(t){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(t)}copy(t){return super.copy(t),this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this}},bl=class extends Je{constructor(t){super(),this.isMeshMatcapMaterial=!0,this.defines={MATCAP:""},this.type="MeshMatcapMaterial",this.color=new ft(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=qi,this.normalScale=new q(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.defines={MATCAP:""},this.color.copy(t.color),this.matcap=t.matcap,this.map=t.map,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.alphaMap=t.alphaMap,this.flatShading=t.flatShading,this.fog=t.fog,this}},Sl=class extends Qe{constructor(t){super(),this.isLineDashedMaterial=!0,this.type="LineDashedMaterial",this.scale=1,this.dashSize=3,this.gapSize=1,this.setValues(t)}copy(t){return super.copy(t),this.scale=t.scale,this.dashSize=t.dashSize,this.gapSize=t.gapSize,this}};function xr(r,t){return!r||r.constructor===t?r:typeof t.BYTES_PER_ELEMENT=="number"?new t(r):Array.prototype.slice.call(r)}function p0(r){return ArrayBuffer.isView(r)&&!(r instanceof DataView)}function m0(r){function t(i,s){return r[i]-r[s]}let e=r.length,n=new Array(e);for(let i=0;i!==e;++i)n[i]=i;return n.sort(t),n}function kf(r,t,e){let n=r.length,i=new r.constructor(n);for(let s=0,o=0;o!==n;++s){let a=e[s]*t;for(let c=0;c!==t;++c)i[o++]=r[a+c]}return i}function Kd(r,t,e,n){let i=1,s=r[0];for(;s!==void 0&&s[n]===void 0;)s=r[i++];if(s===void 0)return;let o=s[n];if(o!==void 0)if(Array.isArray(o))do o=s[n],o!==void 0&&(t.push(s.time),e.push(...o)),s=r[i++];while(s!==void 0);else if(o.toArray!==void 0)do o=s[n],o!==void 0&&(t.push(s.time),o.toArray(e,e.length)),s=r[i++];while(s!==void 0);else do o=s[n],o!==void 0&&(t.push(s.time),e.push(o)),s=r[i++];while(s!==void 0)}function Qy(r,t,e,n,i=30){let s=r.clone();s.name=t;let o=[];for(let c=0;c=n)){h.push(l.times[d]);for(let x=0;xs.tracks[c].times[0]&&(a=s.tracks[c].times[0]);for(let c=0;c=a.times[g]){let m=g*h+f,v=m+h-f;x=a.values.slice(m,v)}else{let m=a.createInterpolant(),v=f,_=h-f;m.evaluate(s),x=m.resultBuffer.slice(v,_)}c==="quaternion"&&new Ze().fromArray(x).normalize().conjugate().toArray(x);let p=l.times.length;for(let m=0;m=s)){let a=e[1];t=s)break e}o=n,n=0;break n}break t}for(;n>>1;te;)--o;if(++o,s!==0||o!==i){s>=o&&(o=Math.max(o,1),s=o-1);let a=this.getValueSize();this.times=n.slice(s,o),this.values=this.values.slice(s*a,o*a)}return this}validate(){let t=!0,e=this.getValueSize();e-Math.floor(e)!==0&&(console.error("THREE.KeyframeTrack: Invalid value size in track.",this),t=!1);let n=this.times,i=this.values,s=n.length;s===0&&(console.error("THREE.KeyframeTrack: Track is empty.",this),t=!1);let o=null;for(let a=0;a!==s;a++){let c=n[a];if(typeof c=="number"&&isNaN(c)){console.error("THREE.KeyframeTrack: Time is not a valid number.",this,a,c),t=!1;break}if(o!==null&&o>c){console.error("THREE.KeyframeTrack: Out of order keys.",this,a,c,o),t=!1;break}o=c}if(i!==void 0&&p0(i))for(let a=0,c=i.length;a!==c;++a){let l=i[a];if(isNaN(l)){console.error("THREE.KeyframeTrack: Value is not a valid number.",this,a,l),t=!1;break}}return t}optimize(){let t=this.times.slice(),e=this.values.slice(),n=this.getValueSize(),i=this.getInterpolation()===Ec,s=t.length-1,o=1;for(let a=1;a0){t[o]=t[s];for(let a=s*n,c=o*n,l=0;l!==n;++l)e[c+l]=e[a+l];++o}return o!==t.length?(this.times=t.slice(0,o),this.values=e.slice(0,o*n)):(this.times=t,this.values=e),this}clone(){let t=this.times.slice(),e=this.values.slice(),n=this.constructor,i=new n(this.name,t,e);return i.createInterpolant=this.createInterpolant,i}};bn.prototype.ValueTypeName="";bn.prototype.TimeBufferType=Float32Array;bn.prototype.ValueBufferType=Float32Array;bn.prototype.DefaultInterpolation=Ic;var yi=class extends bn{constructor(t,e,n){super(t,e,n)}};yi.prototype.ValueTypeName="bool";yi.prototype.ValueBufferType=Array;yi.prototype.DefaultInterpolation=Eo;yi.prototype.InterpolantFactoryMethodLinear=void 0;yi.prototype.InterpolantFactoryMethodSmooth=void 0;var na=class extends bn{constructor(t,e,n,i){super(t,e,n,i)}};na.prototype.ValueTypeName="color";var Er=class extends bn{constructor(t,e,n,i){super(t,e,n,i)}};Er.prototype.ValueTypeName="number";var wl=class extends Ar{constructor(t,e,n,i){super(t,e,n,i)}interpolate_(t,e,n,i){let s=this.resultBuffer,o=this.sampleValues,a=this.valueSize,c=(n-e)/(i-e),l=t*a;for(let f=l+a;l!==f;l+=4)Ze.slerpFlat(s,0,o,l-a,o,l,c);return s}},Rr=class extends bn{constructor(t,e,n,i){super(t,e,n,i)}InterpolantFactoryMethodLinear(t){return new wl(this.times,this.values,this.getValueSize(),t)}};Rr.prototype.ValueTypeName="quaternion";Rr.prototype.InterpolantFactoryMethodSmooth=void 0;var bi=class extends bn{constructor(t,e,n){super(t,e,n)}};bi.prototype.ValueTypeName="string";bi.prototype.ValueBufferType=Array;bi.prototype.DefaultInterpolation=Eo;bi.prototype.InterpolantFactoryMethodLinear=void 0;bi.prototype.InterpolantFactoryMethodSmooth=void 0;var Cr=class extends bn{constructor(t,e,n,i){super(t,e,n,i)}};Cr.prototype.ValueTypeName="vector";var Ir=class{constructor(t="",e=-1,n=[],i=Mu){this.name=t,this.tracks=n,this.duration=e,this.blendMode=i,this.uuid=Cn(),this.userData={},this.duration<0&&this.resetDuration()}static parse(t){let e=[],n=t.tracks,i=1/(t.fps||1);for(let o=0,a=n.length;o!==a;++o)e.push(eb(n[o]).scale(i));let s=new this(t.name,t.duration,e,t.blendMode);return s.uuid=t.uuid,s.userData=JSON.parse(t.userData||"{}"),s}static toJSON(t){let e=[],n=t.tracks,i={name:t.name,duration:t.duration,tracks:e,uuid:t.uuid,blendMode:t.blendMode,userData:JSON.stringify(t.userData)};for(let s=0,o=n.length;s!==o;++s)e.push(bn.toJSON(n[s]));return i}static CreateFromMorphTargetSequence(t,e,n,i){let s=e.length,o=[];for(let a=0;a1){let h=f[1],u=i[h];u||(i[h]=u=[]),u.push(l)}}let o=[];for(let a in i)o.push(this.CreateFromMorphTargetSequence(a,i[a],e,n));return o}static parseAnimation(t,e){if(console.warn("THREE.AnimationClip: parseAnimation() is deprecated and will be removed with r185"),!t)return console.error("THREE.AnimationClip: No animation in JSONLoader data."),null;let n=function(h,u,d,g,x){if(d.length!==0){let p=[],m=[];Kd(d,p,m,g),p.length!==0&&x.push(new h(u,p,m))}},i=[],s=t.name||"default",o=t.fps||30,a=t.blendMode,c=t.length||-1,l=t.hierarchy||[];for(let h=0;h{e&&e(s),this.manager.itemEnd(t)},0),s;if(gi[t]!==void 0){gi[t].push({onLoad:e,onProgress:n,onError:i});return}gi[t]=[],gi[t].push({onLoad:e,onProgress:n,onError:i});let o=new Request(t,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin",signal:typeof AbortSignal.any=="function"?AbortSignal.any([this._abortController.signal,this.manager.abortController.signal]):this._abortController.signal}),a=this.mimeType,c=this.responseType;fetch(o).then(l=>{if(l.status===200||l.status===0){if(l.status===0&&console.warn("THREE.FileLoader: HTTP Status 0 received."),typeof ReadableStream>"u"||l.body===void 0||l.body.getReader===void 0)return l;let f=gi[t],h=l.body.getReader(),u=l.headers.get("X-File-Size")||l.headers.get("Content-Length"),d=u?parseInt(u):0,g=d!==0,x=0,p=new ReadableStream({start(m){v();function v(){h.read().then(({done:_,value:y})=>{if(_)m.close();else{x+=y.byteLength;let b=new ProgressEvent("progress",{lengthComputable:g,loaded:x,total:d});for(let T=0,w=f.length;T{m.error(_)})}}});return new Response(p)}else throw new Hf(`fetch for "${l.url}" responded with ${l.status}: ${l.statusText}`,l)}).then(l=>{switch(c){case"arraybuffer":return l.arrayBuffer();case"blob":return l.blob();case"document":return l.text().then(f=>new DOMParser().parseFromString(f,a));case"json":return l.json();default:if(a==="")return l.text();{let h=/charset="?([^;"\s]*)"?/i.exec(a),u=h&&h[1]?h[1].toLowerCase():void 0,d=new TextDecoder(u);return l.arrayBuffer().then(g=>d.decode(g))}}}).then(l=>{ni.add(`file:${t}`,l);let f=gi[t];delete gi[t];for(let h=0,u=f.length;h{let f=gi[t];if(f===void 0)throw this.manager.itemError(t),l;delete gi[t];for(let h=0,u=f.length;h{this.manager.itemEnd(t)}),this.manager.itemStart(t)}setResponseType(t){return this.responseType=t,this}setMimeType(t){return this.mimeType=t,this}abort(){return this._abortController.abort(),this._abortController=new AbortController,this}},Gf=class extends sn{constructor(t){super(t)}load(t,e,n,i){let s=this,o=new $n(this.manager);o.setPath(this.path),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(t,function(a){try{e(s.parse(JSON.parse(a)))}catch(c){i?i(c):console.error(c),s.manager.itemError(t)}},n,i)}parse(t){let e=[];for(let n=0;n0:i.vertexColors=t.vertexColors),t.uniforms!==void 0)for(let s in t.uniforms){let o=t.uniforms[s];switch(i.uniforms[s]={},o.type){case"t":i.uniforms[s].value=n(o.value);break;case"c":i.uniforms[s].value=new ft().setHex(o.value);break;case"v2":i.uniforms[s].value=new q().fromArray(o.value);break;case"v3":i.uniforms[s].value=new R().fromArray(o.value);break;case"v4":i.uniforms[s].value=new Kt().fromArray(o.value);break;case"m3":i.uniforms[s].value=new Xt().fromArray(o.value);break;case"m4":i.uniforms[s].value=new gt().fromArray(o.value);break;default:i.uniforms[s].value=o.value}}if(t.defines!==void 0&&(i.defines=t.defines),t.vertexShader!==void 0&&(i.vertexShader=t.vertexShader),t.fragmentShader!==void 0&&(i.fragmentShader=t.fragmentShader),t.glslVersion!==void 0&&(i.glslVersion=t.glslVersion),t.extensions!==void 0)for(let s in t.extensions)i.extensions[s]=t.extensions[s];if(t.lights!==void 0&&(i.lights=t.lights),t.clipping!==void 0&&(i.clipping=t.clipping),t.size!==void 0&&(i.size=t.size),t.sizeAttenuation!==void 0&&(i.sizeAttenuation=t.sizeAttenuation),t.map!==void 0&&(i.map=n(t.map)),t.matcap!==void 0&&(i.matcap=n(t.matcap)),t.alphaMap!==void 0&&(i.alphaMap=n(t.alphaMap)),t.bumpMap!==void 0&&(i.bumpMap=n(t.bumpMap)),t.bumpScale!==void 0&&(i.bumpScale=t.bumpScale),t.normalMap!==void 0&&(i.normalMap=n(t.normalMap)),t.normalMapType!==void 0&&(i.normalMapType=t.normalMapType),t.normalScale!==void 0){let s=t.normalScale;Array.isArray(s)===!1&&(s=[s,s]),i.normalScale=new q().fromArray(s)}return t.displacementMap!==void 0&&(i.displacementMap=n(t.displacementMap)),t.displacementScale!==void 0&&(i.displacementScale=t.displacementScale),t.displacementBias!==void 0&&(i.displacementBias=t.displacementBias),t.roughnessMap!==void 0&&(i.roughnessMap=n(t.roughnessMap)),t.metalnessMap!==void 0&&(i.metalnessMap=n(t.metalnessMap)),t.emissiveMap!==void 0&&(i.emissiveMap=n(t.emissiveMap)),t.emissiveIntensity!==void 0&&(i.emissiveIntensity=t.emissiveIntensity),t.specularMap!==void 0&&(i.specularMap=n(t.specularMap)),t.specularIntensityMap!==void 0&&(i.specularIntensityMap=n(t.specularIntensityMap)),t.specularColorMap!==void 0&&(i.specularColorMap=n(t.specularColorMap)),t.envMap!==void 0&&(i.envMap=n(t.envMap)),t.envMapRotation!==void 0&&i.envMapRotation.fromArray(t.envMapRotation),t.envMapIntensity!==void 0&&(i.envMapIntensity=t.envMapIntensity),t.reflectivity!==void 0&&(i.reflectivity=t.reflectivity),t.refractionRatio!==void 0&&(i.refractionRatio=t.refractionRatio),t.lightMap!==void 0&&(i.lightMap=n(t.lightMap)),t.lightMapIntensity!==void 0&&(i.lightMapIntensity=t.lightMapIntensity),t.aoMap!==void 0&&(i.aoMap=n(t.aoMap)),t.aoMapIntensity!==void 0&&(i.aoMapIntensity=t.aoMapIntensity),t.gradientMap!==void 0&&(i.gradientMap=n(t.gradientMap)),t.clearcoatMap!==void 0&&(i.clearcoatMap=n(t.clearcoatMap)),t.clearcoatRoughnessMap!==void 0&&(i.clearcoatRoughnessMap=n(t.clearcoatRoughnessMap)),t.clearcoatNormalMap!==void 0&&(i.clearcoatNormalMap=n(t.clearcoatNormalMap)),t.clearcoatNormalScale!==void 0&&(i.clearcoatNormalScale=new q().fromArray(t.clearcoatNormalScale)),t.iridescenceMap!==void 0&&(i.iridescenceMap=n(t.iridescenceMap)),t.iridescenceThicknessMap!==void 0&&(i.iridescenceThicknessMap=n(t.iridescenceThicknessMap)),t.transmissionMap!==void 0&&(i.transmissionMap=n(t.transmissionMap)),t.thicknessMap!==void 0&&(i.thicknessMap=n(t.thicknessMap)),t.anisotropyMap!==void 0&&(i.anisotropyMap=n(t.anisotropyMap)),t.sheenColorMap!==void 0&&(i.sheenColorMap=n(t.sheenColorMap)),t.sheenRoughnessMap!==void 0&&(i.sheenRoughnessMap=n(t.sheenRoughnessMap)),i}setTextures(t){return this.textures=t,this}createMaterialFromType(t){return r.createMaterialFromType(t)}static createMaterialFromType(t){let e={ShadowMaterial:pl,SpriteMaterial:No,RawShaderMaterial:ml,ShaderMaterial:Ue,PointsMaterial:Bo,MeshPhysicalMaterial:gl,MeshStandardMaterial:Qo,MeshPhongMaterial:xl,MeshToonMaterial:vl,MeshNormalMaterial:_l,MeshLambertMaterial:yl,MeshDepthMaterial:jo,MeshDistanceMaterial:ta,MeshBasicMaterial:zn,MeshMatcapMaterial:bl,LineDashedMaterial:Sl,LineBasicMaterial:Qe,Material:Je};return new e[t]}},sa=class{static extractUrlBase(t){let e=t.lastIndexOf("/");return e===-1?"./":t.slice(0,e+1)}static resolveURL(t,e){return typeof t!="string"||t===""?"":(/^https?:\/\//i.test(e)&&/^\//.test(t)&&(e=e.replace(/(^https?:\/\/[^\/]+).*/i,"$1")),/^(https?:)?\/\//i.test(t)||/^data:.*,.*$/i.test(t)||/^blob:.*$/i.test(t)?t:e+t)}},Fl=class extends Ft{constructor(){super(),this.isInstancedBufferGeometry=!0,this.type="InstancedBufferGeometry",this.instanceCount=1/0}copy(t){return super.copy(t),this.instanceCount=t.instanceCount,this}toJSON(){let t=super.toJSON();return t.instanceCount=this.instanceCount,t.isInstancedBufferGeometry=!0,t}},Ll=class extends sn{constructor(t){super(t)}load(t,e,n,i){let s=this,o=new $n(s.manager);o.setPath(s.path),o.setRequestHeader(s.requestHeader),o.setWithCredentials(s.withCredentials),o.load(t,function(a){try{e(s.parse(JSON.parse(a)))}catch(c){i?i(c):console.error(c),s.manager.itemError(t)}},n,i)}parse(t){let e={},n={};function i(d,g){if(e[g]!==void 0)return e[g];let p=d.interleavedBuffers[g],m=s(d,p.buffer),v=ms(p.type,m),_=new As(v,p.stride);return _.uuid=p.uuid,e[g]=_,_}function s(d,g){if(n[g]!==void 0)return n[g];let p=d.arrayBuffers[g],m=new Uint32Array(p).buffer;return n[g]=m,m}let o=t.isInstancedBufferGeometry?new Fl:new Ft,a=t.data.index;if(a!==void 0){let d=ms(a.type,a.array);o.setIndex(new Ot(d,1))}let c=t.data.attributes;for(let d in c){let g=c[d],x;if(g.isInterleavedBufferAttribute){let p=i(t.data,g.data);x=new Tr(p,g.itemSize,g.offset,g.normalized)}else{let p=ms(g.type,g.array),m=g.isInstancedBufferAttribute?Bi:Ot;x=new m(p,g.itemSize,g.normalized)}g.name!==void 0&&(x.name=g.name),g.usage!==void 0&&x.setUsage(g.usage),o.setAttribute(d,x)}let l=t.data.morphAttributes;if(l)for(let d in l){let g=l[d],x=[];for(let p=0,m=g.length;p0){let c=new ia(e);s=new Pr(c),s.setCrossOrigin(this.crossOrigin);for(let l=0,f=t.length;l0){i=new Pr(this.manager),i.setCrossOrigin(this.crossOrigin);for(let o=0,a=t.length;o{let p=null,m=null;return x.boundingBox!==void 0&&(p=new se().fromJSON(x.boundingBox)),x.boundingSphere!==void 0&&(m=new Ve().fromJSON(x.boundingSphere)),{...x,boundingBox:p,boundingSphere:m}}),o._instanceInfo=t.instanceInfo,o._availableInstanceIds=t._availableInstanceIds,o._availableGeometryIds=t._availableGeometryIds,o._nextIndexStart=t.nextIndexStart,o._nextVertexStart=t.nextVertexStart,o._geometryCount=t.geometryCount,o._maxInstanceCount=t.maxInstanceCount,o._maxVertexCount=t.maxVertexCount,o._maxIndexCount=t.maxIndexCount,o._geometryInitialized=t.geometryInitialized,o._matricesTexture=l(t.matricesTexture.uuid),o._indirectTexture=l(t.indirectTexture.uuid),t.colorsTexture!==void 0&&(o._colorsTexture=l(t.colorsTexture.uuid)),t.boundingSphere!==void 0&&(o.boundingSphere=new Ve().fromJSON(t.boundingSphere)),t.boundingBox!==void 0&&(o.boundingBox=new se().fromJSON(t.boundingBox));break;case"LOD":o=new Bc;break;case"Line":o=new ri(a(t.geometry),c(t.material));break;case"LineLoop":o=new Xc(a(t.geometry),c(t.material));break;case"LineSegments":o=new kn(a(t.geometry),c(t.material));break;case"PointCloud":case"Points":o=new qc(a(t.geometry),c(t.material));break;case"Sprite":o=new Uc(c(t.material));break;case"Group":o=new Li;break;case"Bone":o=new Uo;break;default:o=new ue}if(o.uuid=t.uuid,t.name!==void 0&&(o.name=t.name),t.matrix!==void 0?(o.matrix.fromArray(t.matrix),t.matrixAutoUpdate!==void 0&&(o.matrixAutoUpdate=t.matrixAutoUpdate),o.matrixAutoUpdate&&o.matrix.decompose(o.position,o.quaternion,o.scale)):(t.position!==void 0&&o.position.fromArray(t.position),t.rotation!==void 0&&o.rotation.fromArray(t.rotation),t.quaternion!==void 0&&o.quaternion.fromArray(t.quaternion),t.scale!==void 0&&o.scale.fromArray(t.scale)),t.up!==void 0&&o.up.fromArray(t.up),t.castShadow!==void 0&&(o.castShadow=t.castShadow),t.receiveShadow!==void 0&&(o.receiveShadow=t.receiveShadow),t.shadow&&(t.shadow.intensity!==void 0&&(o.shadow.intensity=t.shadow.intensity),t.shadow.bias!==void 0&&(o.shadow.bias=t.shadow.bias),t.shadow.normalBias!==void 0&&(o.shadow.normalBias=t.shadow.normalBias),t.shadow.radius!==void 0&&(o.shadow.radius=t.shadow.radius),t.shadow.mapSize!==void 0&&o.shadow.mapSize.fromArray(t.shadow.mapSize),t.shadow.camera!==void 0&&(o.shadow.camera=this.parseObject(t.shadow.camera))),t.visible!==void 0&&(o.visible=t.visible),t.frustumCulled!==void 0&&(o.frustumCulled=t.frustumCulled),t.renderOrder!==void 0&&(o.renderOrder=t.renderOrder),t.userData!==void 0&&(o.userData=t.userData),t.layers!==void 0&&(o.layers.mask=t.layers),t.children!==void 0){let u=t.children;for(let d=0;d"u"&&console.warn("THREE.ImageBitmapLoader: createImageBitmap() not supported."),typeof fetch>"u"&&console.warn("THREE.ImageBitmapLoader: fetch() not supported."),this.options={premultiplyAlpha:"none"},this._abortController=new AbortController}setOptions(t){return this.options=t,this}load(t,e,n,i){t===void 0&&(t=""),this.path!==void 0&&(t=this.path+t),t=this.manager.resolveURL(t);let s=this,o=ni.get(`image-bitmap:${t}`);if(o!==void 0){if(s.manager.itemStart(t),o.then){o.then(l=>{if(gf.has(o)===!0)i&&i(gf.get(o)),s.manager.itemError(t),s.manager.itemEnd(t);else return e&&e(l),s.manager.itemEnd(t),l});return}return setTimeout(function(){e&&e(o),s.manager.itemEnd(t)},0),o}let a={};a.credentials=this.crossOrigin==="anonymous"?"same-origin":"include",a.headers=this.requestHeader,a.signal=typeof AbortSignal.any=="function"?AbortSignal.any([this._abortController.signal,this.manager.abortController.signal]):this._abortController.signal;let c=fetch(t,a).then(function(l){return l.blob()}).then(function(l){return createImageBitmap(l,Object.assign(s.options,{colorSpaceConversion:"none"}))}).then(function(l){return ni.add(`image-bitmap:${t}`,l),e&&e(l),s.manager.itemEnd(t),l}).catch(function(l){i&&i(l),gf.set(c,l),ni.remove(`image-bitmap:${t}`),s.manager.itemError(t),s.manager.itemEnd(t)});ni.add(`image-bitmap:${t}`,c),s.manager.itemStart(t)}abort(){return this._abortController.abort(),this._abortController=new AbortController,this}},yc,oa=class{static getContext(){return yc===void 0&&(yc=new(window.AudioContext||window.webkitAudioContext)),yc}static setContext(t){yc=t}},jf=class extends sn{constructor(t){super(t)}load(t,e,n,i){let s=this,o=new $n(this.manager);o.setResponseType("arraybuffer"),o.setPath(this.path),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(t,function(c){try{let l=c.slice(0);oa.getContext().decodeAudioData(l,function(h){e(h)}).catch(a)}catch(l){a(l)}},n,i);function a(c){i?i(c):console.error(c),s.manager.itemError(t)}}},ng=new gt,ig=new gt,cr=new gt,td=class{constructor(){this.type="StereoCamera",this.aspect=1,this.eyeSep=.064,this.cameraL=new Re,this.cameraL.layers.enable(1),this.cameraL.matrixAutoUpdate=!1,this.cameraR=new Re,this.cameraR.layers.enable(2),this.cameraR.matrixAutoUpdate=!1,this._cache={focus:null,fov:null,aspect:null,near:null,far:null,zoom:null,eyeSep:null}}update(t){let e=this._cache;if(e.focus!==t.focus||e.fov!==t.fov||e.aspect!==t.aspect*this.aspect||e.near!==t.near||e.far!==t.far||e.zoom!==t.zoom||e.eyeSep!==this.eyeSep){e.focus=t.focus,e.fov=t.fov,e.aspect=t.aspect*this.aspect,e.near=t.near,e.far=t.far,e.zoom=t.zoom,e.eyeSep=this.eyeSep,cr.copy(t.projectionMatrix);let i=e.eyeSep/2,s=i*e.near/e.focus,o=e.near*Math.tan(vr*e.fov*.5)/e.zoom,a,c;ig.elements[12]=-i,ng.elements[12]=i,a=-o*e.aspect+s,c=o*e.aspect+s,cr.elements[0]=2*e.near/(c-a),cr.elements[8]=(c+a)/(c-a),this.cameraL.projectionMatrix.copy(cr),a=-o*e.aspect-s,c=o*e.aspect-s,cr.elements[0]=2*e.near/(c-a),cr.elements[8]=(c+a)/(c-a),this.cameraR.projectionMatrix.copy(cr)}this.cameraL.matrixWorld.copy(t.matrixWorld).multiply(ig),this.cameraR.matrixWorld.copy(t.matrixWorld).multiply(ng)}},Nl=class extends Re{constructor(t=[]){super(),this.isArrayCamera=!0,this.isMultiViewCamera=!1,this.cameras=t}},Ls=class{constructor(t=!0){this.autoStart=t,this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1}start(){this.startTime=performance.now(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let t=0;if(this.autoStart&&!this.running)return this.start(),0;if(this.running){let e=performance.now();t=(e-this.oldTime)/1e3,this.oldTime=e,this.elapsedTime+=t}return t}},lr=new R,xf=new Ze,ib=new R,ur=new R,hr=new R,ed=class extends ue{constructor(){super(),this.type="AudioListener",this.context=oa.getContext(),this.gain=this.context.createGain(),this.gain.connect(this.context.destination),this.filter=null,this.timeDelta=0,this._clock=new Ls}getInput(){return this.gain}removeFilter(){return this.filter!==null&&(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination),this.gain.connect(this.context.destination),this.filter=null),this}getFilter(){return this.filter}setFilter(t){return this.filter!==null?(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination)):this.gain.disconnect(this.context.destination),this.filter=t,this.gain.connect(this.filter),this.filter.connect(this.context.destination),this}getMasterVolume(){return this.gain.gain.value}setMasterVolume(t){return this.gain.gain.setTargetAtTime(t,this.context.currentTime,.01),this}updateMatrixWorld(t){super.updateMatrixWorld(t);let e=this.context.listener;if(this.timeDelta=this._clock.getDelta(),this.matrixWorld.decompose(lr,xf,ib),ur.set(0,0,-1).applyQuaternion(xf),hr.set(0,1,0).applyQuaternion(xf),e.positionX){let n=this.context.currentTime+this.timeDelta;e.positionX.linearRampToValueAtTime(lr.x,n),e.positionY.linearRampToValueAtTime(lr.y,n),e.positionZ.linearRampToValueAtTime(lr.z,n),e.forwardX.linearRampToValueAtTime(ur.x,n),e.forwardY.linearRampToValueAtTime(ur.y,n),e.forwardZ.linearRampToValueAtTime(ur.z,n),e.upX.linearRampToValueAtTime(hr.x,n),e.upY.linearRampToValueAtTime(hr.y,n),e.upZ.linearRampToValueAtTime(hr.z,n)}else e.setPosition(lr.x,lr.y,lr.z),e.setOrientation(ur.x,ur.y,ur.z,hr.x,hr.y,hr.z)}},Ul=class extends ue{constructor(t){super(),this.type="Audio",this.listener=t,this.context=t.context,this.gain=this.context.createGain(),this.gain.connect(t.getInput()),this.autoplay=!1,this.buffer=null,this.detune=0,this.loop=!1,this.loopStart=0,this.loopEnd=0,this.offset=0,this.duration=void 0,this.playbackRate=1,this.isPlaying=!1,this.hasPlaybackControl=!0,this.source=null,this.sourceType="empty",this._startedAt=0,this._progress=0,this._connected=!1,this.filters=[]}getOutput(){return this.gain}setNodeSource(t){return this.hasPlaybackControl=!1,this.sourceType="audioNode",this.source=t,this.connect(),this}setMediaElementSource(t){return this.hasPlaybackControl=!1,this.sourceType="mediaNode",this.source=this.context.createMediaElementSource(t),this.connect(),this}setMediaStreamSource(t){return this.hasPlaybackControl=!1,this.sourceType="mediaStreamNode",this.source=this.context.createMediaStreamSource(t),this.connect(),this}setBuffer(t){return this.buffer=t,this.sourceType="buffer",this.autoplay&&this.play(),this}play(t=0){if(this.isPlaying===!0){console.warn("THREE.Audio: Audio is already playing.");return}if(this.hasPlaybackControl===!1){console.warn("THREE.Audio: this Audio has no playback control.");return}this._startedAt=this.context.currentTime+t;let e=this.context.createBufferSource();return e.buffer=this.buffer,e.loop=this.loop,e.loopStart=this.loopStart,e.loopEnd=this.loopEnd,e.onended=this.onEnded.bind(this),e.start(this._startedAt,this._progress+this.offset,this.duration),this.isPlaying=!0,this.source=e,this.setDetune(this.detune),this.setPlaybackRate(this.playbackRate),this.connect()}pause(){if(this.hasPlaybackControl===!1){console.warn("THREE.Audio: this Audio has no playback control.");return}return this.isPlaying===!0&&(this._progress+=Math.max(this.context.currentTime-this._startedAt,0)*this.playbackRate,this.loop===!0&&(this._progress=this._progress%(this.duration||this.buffer.duration)),this.source.stop(),this.source.onended=null,this.isPlaying=!1),this}stop(t=0){if(this.hasPlaybackControl===!1){console.warn("THREE.Audio: this Audio has no playback control.");return}return this._progress=0,this.source!==null&&(this.source.stop(this.context.currentTime+t),this.source.onended=null),this.isPlaying=!1,this}connect(){if(this.filters.length>0){this.source.connect(this.filters[0]);for(let t=1,e=this.filters.length;t0){this.source.disconnect(this.filters[0]);for(let t=1,e=this.filters.length;t0&&this._mixBufferRegionAdditive(n,i,this._addIndex*e,1,e);for(let c=e,l=e+e;c!==l;++c)if(n[c]!==n[c+e]){a.setValue(n,i);break}}saveOriginalState(){let t=this.binding,e=this.buffer,n=this.valueSize,i=n*this._origIndex;t.getValue(e,i);for(let s=n,o=i;s!==o;++s)e[s]=e[i+s%n];this._setIdentity(),this.cumulativeWeight=0,this.cumulativeWeightAdditive=0}restoreOriginalState(){let t=this.valueSize*3;this.binding.setValue(this.buffer,t)}_setAdditiveIdentityNumeric(){let t=this._addIndex*this.valueSize,e=t+this.valueSize;for(let n=t;n=.5)for(let o=0;o!==s;++o)t[e+o]=t[n+o]}_slerp(t,e,n,i){Ze.slerpFlat(t,e,t,e,t,n,i)}_slerpAdditive(t,e,n,i,s){let o=this._workIndex*s;Ze.multiplyQuaternionsFlat(t,o,t,e,t,n),Ze.slerpFlat(t,e,t,e,t,o,i)}_lerp(t,e,n,i,s){let o=1-i;for(let a=0;a!==s;++a){let c=e+a;t[c]=t[c]*o+t[n+a]*i}}_lerpAdditive(t,e,n,i,s){for(let o=0;o!==s;++o){let a=e+o;t[a]=t[a]+t[n+o]*i}}},Qd="\\[\\]\\.:\\/",sb=new RegExp("["+Qd+"]","g"),jd="[^"+Qd+"]",ob="[^"+Qd.replace("\\.","")+"]",ab=/((?:WC+[\/:])*)/.source.replace("WC",jd),cb=/(WCOD+)?/.source.replace("WCOD",ob),lb=/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",jd),ub=/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",jd),hb=new RegExp("^"+ab+cb+lb+ub+"$"),fb=["material","materials","bones","map"],rd=class{constructor(t,e,n){let i=n||pe.parseTrackName(e);this._targetGroup=t,this._bindings=t.subscribe_(e,i)}getValue(t,e){this.bind();let n=this._targetGroup.nCachedObjects_,i=this._bindings[n];i!==void 0&&i.getValue(t,e)}setValue(t,e){let n=this._bindings;for(let i=this._targetGroup.nCachedObjects_,s=n.length;i!==s;++i)n[i].setValue(t,e)}bind(){let t=this._bindings;for(let e=this._targetGroup.nCachedObjects_,n=t.length;e!==n;++e)t[e].bind()}unbind(){let t=this._bindings;for(let e=this._targetGroup.nCachedObjects_,n=t.length;e!==n;++e)t[e].unbind()}},pe=class r{constructor(t,e,n){this.path=e,this.parsedPath=n||r.parseTrackName(e),this.node=r.findNode(t,this.parsedPath.nodeName),this.rootNode=t,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(t,e,n){return t&&t.isAnimationObjectGroup?new r.Composite(t,e,n):new r(t,e,n)}static sanitizeNodeName(t){return t.replace(/\s/g,"_").replace(sb,"")}static parseTrackName(t){let e=hb.exec(t);if(e===null)throw new Error("PropertyBinding: Cannot parse trackName: "+t);let n={nodeName:e[2],objectName:e[3],objectIndex:e[4],propertyName:e[5],propertyIndex:e[6]},i=n.nodeName&&n.nodeName.lastIndexOf(".");if(i!==void 0&&i!==-1){let s=n.nodeName.substring(i+1);fb.indexOf(s)!==-1&&(n.nodeName=n.nodeName.substring(0,i),n.objectName=s)}if(n.propertyName===null||n.propertyName.length===0)throw new Error("PropertyBinding: can not parse propertyName from trackName: "+t);return n}static findNode(t,e){if(e===void 0||e===""||e==="."||e===-1||e===t.name||e===t.uuid)return t;if(t.skeleton){let n=t.skeleton.getBoneByName(e);if(n!==void 0)return n}if(t.children){let n=function(s){for(let o=0;o=s){let h=s++,u=t[h];e[u.uuid]=f,t[f]=u,e[l]=h,t[h]=c;for(let d=0,g=i;d!==g;++d){let x=n[d],p=x[h],m=x[f];x[f]=p,x[h]=m}}}this.nCachedObjects_=s}uncache(){let t=this._objects,e=this._indicesByUUID,n=this._bindings,i=n.length,s=this.nCachedObjects_,o=t.length;for(let a=0,c=arguments.length;a!==c;++a){let l=arguments[a],f=l.uuid,h=e[f];if(h!==void 0)if(delete e[f],h0&&(e[d.uuid]=h),t[h]=d,t.pop();for(let g=0,x=i;g!==x;++g){let p=n[g];p[h]=p[u],p.pop()}}}this.nCachedObjects_=s}subscribe_(t,e){let n=this._bindingsIndicesByPath,i=n[t],s=this._bindings;if(i!==void 0)return s[i];let o=this._paths,a=this._parsedPaths,c=this._objects,l=c.length,f=this.nCachedObjects_,h=new Array(l);i=s.length,n[t]=i,o.push(t),a.push(e),s.push(h);for(let u=f,d=c.length;u!==d;++u){let g=c[u];h[u]=new pe(g,t,e)}return h}unsubscribe_(t){let e=this._bindingsIndicesByPath,n=e[t];if(n!==void 0){let i=this._paths,s=this._parsedPaths,o=this._bindings,a=o.length-1,c=o[a],l=t[a];e[l]=n,o[n]=c,o.pop(),s[n]=s[a],s.pop(),i[n]=i[a],i.pop()}}},Ol=class{constructor(t,e,n=null,i=e.blendMode){this._mixer=t,this._clip=e,this._localRoot=n,this.blendMode=i;let s=e.tracks,o=s.length,a=new Array(o),c={endingStart:mr,endingEnd:mr};for(let l=0;l!==o;++l){let f=s[l].createInterpolant(null);a[l]=f,f.settings=c}this._interpolantSettings=c,this._interpolants=a,this._propertyBindings=new Array(o),this._cacheIndex=null,this._byClipCacheIndex=null,this._timeScaleInterpolant=null,this._weightInterpolant=null,this.loop=Yg,this._loopCount=-1,this._startTime=null,this.time=0,this.timeScale=1,this._effectiveTimeScale=1,this.weight=1,this._effectiveWeight=1,this.repetitions=1/0,this.paused=!1,this.enabled=!0,this.clampWhenFinished=!1,this.zeroSlopeAtStart=!0,this.zeroSlopeAtEnd=!0}play(){return this._mixer._activateAction(this),this}stop(){return this._mixer._deactivateAction(this),this.reset()}reset(){return this.paused=!1,this.enabled=!0,this.time=0,this._loopCount=-1,this._startTime=null,this.stopFading().stopWarping()}isRunning(){return this.enabled&&!this.paused&&this.timeScale!==0&&this._startTime===null&&this._mixer._isActiveAction(this)}isScheduled(){return this._mixer._isActiveAction(this)}startAt(t){return this._startTime=t,this}setLoop(t,e){return this.loop=t,this.repetitions=e,this}setEffectiveWeight(t){return this.weight=t,this._effectiveWeight=this.enabled?t:0,this.stopFading()}getEffectiveWeight(){return this._effectiveWeight}fadeIn(t){return this._scheduleFading(t,0,1)}fadeOut(t){return this._scheduleFading(t,1,0)}crossFadeFrom(t,e,n=!1){if(t.fadeOut(e),this.fadeIn(e),n===!0){let i=this._clip.duration,s=t._clip.duration,o=s/i,a=i/s;t.warp(1,o,e),this.warp(a,1,e)}return this}crossFadeTo(t,e,n=!1){return t.crossFadeFrom(this,e,n)}stopFading(){let t=this._weightInterpolant;return t!==null&&(this._weightInterpolant=null,this._mixer._takeBackControlInterpolant(t)),this}setEffectiveTimeScale(t){return this.timeScale=t,this._effectiveTimeScale=this.paused?0:t,this.stopWarping()}getEffectiveTimeScale(){return this._effectiveTimeScale}setDuration(t){return this.timeScale=this._clip.duration/t,this.stopWarping()}syncWith(t){return this.time=t.time,this.timeScale=t.timeScale,this.stopWarping()}halt(t){return this.warp(this._effectiveTimeScale,0,t)}warp(t,e,n){let i=this._mixer,s=i.time,o=this.timeScale,a=this._timeScaleInterpolant;a===null&&(a=i._lendControlInterpolant(),this._timeScaleInterpolant=a);let c=a.parameterPositions,l=a.sampleValues;return c[0]=s,c[1]=s+n,l[0]=t/o,l[1]=e/o,this}stopWarping(){let t=this._timeScaleInterpolant;return t!==null&&(this._timeScaleInterpolant=null,this._mixer._takeBackControlInterpolant(t)),this}getMixer(){return this._mixer}getClip(){return this._clip}getRoot(){return this._localRoot||this._mixer._root}_update(t,e,n,i){if(!this.enabled){this._updateWeight(t);return}let s=this._startTime;if(s!==null){let c=(t-s)*n;c<0||n===0?e=0:(this._startTime=null,e=n*c)}e*=this._updateTimeScale(t);let o=this._updateTime(e),a=this._updateWeight(t);if(a>0){let c=this._interpolants,l=this._propertyBindings;switch(this.blendMode){case Wd:for(let f=0,h=c.length;f!==h;++f)c[f].evaluate(o),l[f].accumulateAdditive(a);break;case Mu:default:for(let f=0,h=c.length;f!==h;++f)c[f].evaluate(o),l[f].accumulate(i,a)}}}_updateWeight(t){let e=0;if(this.enabled){e=this.weight;let n=this._weightInterpolant;if(n!==null){let i=n.evaluate(t)[0];e*=i,t>n.parameterPositions[1]&&(this.stopFading(),i===0&&(this.enabled=!1))}}return this._effectiveWeight=e,e}_updateTimeScale(t){let e=0;if(!this.paused){e=this.timeScale;let n=this._timeScaleInterpolant;if(n!==null){let i=n.evaluate(t)[0];e*=i,t>n.parameterPositions[1]&&(this.stopWarping(),e===0?this.paused=!0:this.timeScale=e)}}return this._effectiveTimeScale=e,e}_updateTime(t){let e=this._clip.duration,n=this.loop,i=this.time+t,s=this._loopCount,o=n===$g;if(t===0)return s===-1?i:o&&(s&1)===1?e-i:i;if(n===qg){s===-1&&(this._loopCount=0,this._setEndings(!0,!0,!1));t:{if(i>=e)i=e;else if(i<0)i=0;else{this.time=i;break t}this.clampWhenFinished?this.paused=!0:this.enabled=!1,this.time=i,this._mixer.dispatchEvent({type:"finished",action:this,direction:t<0?-1:1})}}else{if(s===-1&&(t>=0?(s=0,this._setEndings(!0,this.repetitions===0,o)):this._setEndings(this.repetitions===0,!0,o)),i>=e||i<0){let a=Math.floor(i/e);i-=e*a,s+=Math.abs(a);let c=this.repetitions-s;if(c<=0)this.clampWhenFinished?this.paused=!0:this.enabled=!1,i=t>0?e:0,this.time=i,this._mixer.dispatchEvent({type:"finished",action:this,direction:t>0?1:-1});else{if(c===1){let l=t<0;this._setEndings(l,!l,o)}else this._setEndings(!1,!1,o);this._loopCount=s,this.time=i,this._mixer.dispatchEvent({type:"loop",action:this,loopDelta:a})}}else this.time=i;if(o&&(s&1)===1)return e-i}return i}_setEndings(t,e,n){let i=this._interpolantSettings;n?(i.endingStart=gr,i.endingEnd=gr):(t?i.endingStart=this.zeroSlopeAtStart?gr:mr:i.endingStart=Ro,e?i.endingEnd=this.zeroSlopeAtEnd?gr:mr:i.endingEnd=Ro)}_scheduleFading(t,e,n){let i=this._mixer,s=i.time,o=this._weightInterpolant;o===null&&(o=i._lendControlInterpolant(),this._weightInterpolant=o);let a=o.parameterPositions,c=o.sampleValues;return a[0]=s,c[0]=e,a[1]=s+t,c[1]=n,this}},db=new Float32Array(1),od=class extends On{constructor(t){super(),this._root=t,this._initMemoryManager(),this._accuIndex=0,this.time=0,this.timeScale=1}_bindAction(t,e){let n=t._localRoot||this._root,i=t._clip.tracks,s=i.length,o=t._propertyBindings,a=t._interpolants,c=n.uuid,l=this._bindingsByRootAndName,f=l[c];f===void 0&&(f={},l[c]=f);for(let h=0;h!==s;++h){let u=i[h],d=u.name,g=f[d];if(g!==void 0)++g.referenceCount,o[h]=g;else{if(g=o[h],g!==void 0){g._cacheIndex===null&&(++g.referenceCount,this._addInactiveBinding(g,c,d));continue}let x=e&&e._propertyBindings[h].binding.parsedPath;g=new Bl(pe.create(n,d,x),u.ValueTypeName,u.getValueSize()),++g.referenceCount,this._addInactiveBinding(g,c,d),o[h]=g}a[h].resultBuffer=g.buffer}}_activateAction(t){if(!this._isActiveAction(t)){if(t._cacheIndex===null){let n=(t._localRoot||this._root).uuid,i=t._clip.uuid,s=this._actionsByClip[i];this._bindAction(t,s&&s.knownActions[0]),this._addInactiveAction(t,i,n)}let e=t._propertyBindings;for(let n=0,i=e.length;n!==i;++n){let s=e[n];s.useCount++===0&&(this._lendBinding(s),s.saveOriginalState())}this._lendAction(t)}}_deactivateAction(t){if(this._isActiveAction(t)){let e=t._propertyBindings;for(let n=0,i=e.length;n!==i;++n){let s=e[n];--s.useCount===0&&(s.restoreOriginalState(),this._takeBackBinding(s))}this._takeBackAction(t)}}_initMemoryManager(){this._actions=[],this._nActiveActions=0,this._actionsByClip={},this._bindings=[],this._nActiveBindings=0,this._bindingsByRootAndName={},this._controlInterpolants=[],this._nActiveControlInterpolants=0;let t=this;this.stats={actions:{get total(){return t._actions.length},get inUse(){return t._nActiveActions}},bindings:{get total(){return t._bindings.length},get inUse(){return t._nActiveBindings}},controlInterpolants:{get total(){return t._controlInterpolants.length},get inUse(){return t._nActiveControlInterpolants}}}}_isActiveAction(t){let e=t._cacheIndex;return e!==null&&e=0;--n)t[n].stop();return this}update(t){t*=this.timeScale;let e=this._actions,n=this._nActiveActions,i=this.time+=t,s=Math.sign(t),o=this._accuIndex^=1;for(let l=0;l!==n;++l)e[l]._update(i,t,s,o);let a=this._bindings,c=this._nActiveBindings;for(let l=0;l!==c;++l)a[l].apply(o);return this}setTime(t){this.time=0;for(let e=0;e=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,ag).distanceTo(t)}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}},cg=new R,bc=new R,ds=new R,ps=new R,vf=new R,gb=new R,xb=new R,dn=class{constructor(t=new R,e=new R){this.start=t,this.end=e}set(t,e){return this.start.copy(t),this.end.copy(e),this}copy(t){return this.start.copy(t.start),this.end.copy(t.end),this}getCenter(t){return t.addVectors(this.start,this.end).multiplyScalar(.5)}delta(t){return t.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(t,e){return this.delta(e).multiplyScalar(t).add(this.start)}closestPointToPointParameter(t,e){cg.subVectors(t,this.start),bc.subVectors(this.end,this.start);let n=bc.dot(bc),s=bc.dot(cg)/n;return e&&(s=Bt(s,0,1)),s}closestPointToPoint(t,e,n){let i=this.closestPointToPointParameter(t,e);return this.delta(n).multiplyScalar(i).add(this.start)}distanceSqToLine3(t,e=gb,n=xb){let i=10000000000000001e-32,s,o,a=this.start,c=t.start,l=this.end,f=t.end;ds.subVectors(l,a),ps.subVectors(f,c),vf.subVectors(a,c);let h=ds.dot(ds),u=ps.dot(ps),d=ps.dot(vf);if(h<=i&&u<=i)return e.copy(a),n.copy(c),e.sub(n),e.dot(e);if(h<=i)s=0,o=d/u,o=Bt(o,0,1);else{let g=ds.dot(vf);if(u<=i)o=0,s=Bt(-g/h,0,1);else{let x=ds.dot(ps),p=h*u-x*x;p!==0?s=Bt((x*d-g*u)/p,0,1):s=0,o=(x*s+d)/u,o<0?(o=0,s=Bt(-g/h,0,1)):o>1&&(o=1,s=Bt((x-g)/h,0,1))}}return e.copy(a).add(ds.multiplyScalar(s)),n.copy(c).add(ps.multiplyScalar(o)),e.sub(n),e.dot(e)}applyMatrix4(t){return this.start.applyMatrix4(t),this.end.applyMatrix4(t),this}equals(t){return t.start.equals(this.start)&&t.end.equals(this.end)}clone(){return new this.constructor().copy(this)}},lg=new R,vd=class extends ue{constructor(t,e){super(),this.light=t,this.matrixAutoUpdate=!1,this.color=e,this.type="SpotLightHelper";let n=new Ft,i=[0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,-1,0,1,0,0,0,0,1,1,0,0,0,0,-1,1];for(let o=0,a=1,c=32;o1)for(let h=0;h.99999)this.quaternion.set(0,0,0,1);else if(t.y<-.99999)this.quaternion.set(1,0,0,0);else{pg.set(t.z,0,-t.x).normalize();let e=Math.acos(t.y);this.quaternion.setFromAxisAngle(pg,e)}}setLength(t,e=t*.2,n=e*.2){this.line.scale.set(1,Math.max(1e-4,t-e),1),this.line.updateMatrix(),this.cone.scale.set(n,e,n),this.cone.position.y=t,this.cone.updateMatrix()}setColor(t){this.line.material.color.set(t),this.cone.material.color.set(t)}copy(t){return super.copy(t,!1),this.line.copy(t.line),this.cone.copy(t.cone),this}dispose(){this.line.geometry.dispose(),this.line.material.dispose(),this.cone.geometry.dispose(),this.cone.material.dispose()}},Id=class extends kn{constructor(t=1){let e=[0,0,0,t,0,0,0,0,0,0,t,0,0,0,0,0,0,t],n=[1,0,0,1,.6,0,0,1,0,.6,1,0,0,0,1,0,.6,1],i=new Ft;i.setAttribute("position",new bt(e,3)),i.setAttribute("color",new bt(n,3));let s=new Qe({vertexColors:!0,toneMapped:!1});super(i,s),this.type="AxesHelper"}setColors(t,e,n){let i=new ft,s=this.geometry.attributes.color.array;return i.set(t),i.toArray(s,0),i.toArray(s,3),i.set(e),i.toArray(s,6),i.toArray(s,9),i.set(n),i.toArray(s,12),i.toArray(s,15),this.geometry.attributes.color.needsUpdate=!0,this}dispose(){this.geometry.dispose(),this.material.dispose()}},Pd=class{constructor(){this.type="ShapePath",this.color=new ft,this.subPaths=[],this.currentPath=null}moveTo(t,e){return this.currentPath=new Cs,this.subPaths.push(this.currentPath),this.currentPath.moveTo(t,e),this}lineTo(t,e){return this.currentPath.lineTo(t,e),this}quadraticCurveTo(t,e,n,i){return this.currentPath.quadraticCurveTo(t,e,n,i),this}bezierCurveTo(t,e,n,i,s,o){return this.currentPath.bezierCurveTo(t,e,n,i,s,o),this}splineThru(t){return this.currentPath.splineThru(t),this}toShapes(t){function e(m){let v=[];for(let _=0,y=m.length;_Number.EPSILON){if(S<0&&(w=v[T],M=-M,E=v[b],S=-S),m.yE.y)continue;if(m.y===w.y){if(m.x===w.x)return!0}else{let I=S*(m.x-w.x)-M*(m.y-w.y);if(I===0)return!0;if(I<0)continue;y=!y}}else{if(m.y!==w.y)continue;if(E.x<=m.x&&m.x<=w.x||w.x<=m.x&&m.x<=E.x)return!0}}return y}let i=qn.isClockWise,s=this.subPaths;if(s.length===0)return[];let o,a,c,l=[];if(s.length===1)return a=s[0],c=new _i,c.curves=a.curves,l.push(c),l;let f=!i(s[0].getPoints());f=t?!f:f;let h=[],u=[],d=[],g=0,x;u[g]=void 0,d[g]=[];for(let m=0,v=s.length;m1){let m=!1,v=0;for(let _=0,y=u.length;_0&&m===!1&&(d=h)}let p;for(let m=0,v=u.length;mt?(r.repeat.x=1,r.repeat.y=e/t,r.offset.x=0,r.offset.y=(1-r.repeat.y)/2):(r.repeat.x=t/e,r.repeat.y=1,r.offset.x=(1-r.repeat.x)/2,r.offset.y=0),r}function yb(r,t){let e=r.image&&r.image.width?r.image.width/r.image.height:1;return e>t?(r.repeat.x=t/e,r.repeat.y=1,r.offset.x=(1-r.repeat.x)/2,r.offset.y=0):(r.repeat.x=1,r.repeat.y=e/t,r.offset.x=0,r.offset.y=(1-r.repeat.y)/2),r}function bb(r){return r.repeat.x=1,r.repeat.y=1,r.offset.x=0,r.offset.y=0,r}function Tu(r,t,e,n){let i=Sb(n);switch(e){case Hd:return r*t;case Jn:return r*t/i.components*i.byteLength;case Dr:return r*t/i.components*i.byteLength;case Fr:return r*t*2/i.components*i.byteLength;case Wi:return r*t*2/i.components*i.byteLength;case Gd:return r*t*3/i.components*i.byteLength;case Gt:return r*t*4/i.components*i.byteLength;case Xi:return r*t*4/i.components*i.byteLength;case pa:case ma:return Math.floor((r+3)/4)*Math.floor((t+3)/4)*8;case ga:case xa:return Math.floor((r+3)/4)*Math.floor((t+3)/4)*16;case Jl:case Ql:return Math.max(r,16)*Math.max(t,8)/4;case Zl:case Kl:return Math.max(r,8)*Math.max(t,8)/2;case jl:case tu:return Math.floor((r+3)/4)*Math.floor((t+3)/4)*8;case eu:return Math.floor((r+3)/4)*Math.floor((t+3)/4)*16;case nu:return Math.floor((r+3)/4)*Math.floor((t+3)/4)*16;case iu:return Math.floor((r+4)/5)*Math.floor((t+3)/4)*16;case ru:return Math.floor((r+4)/5)*Math.floor((t+4)/5)*16;case su:return Math.floor((r+5)/6)*Math.floor((t+4)/5)*16;case ou:return Math.floor((r+5)/6)*Math.floor((t+5)/6)*16;case au:return Math.floor((r+7)/8)*Math.floor((t+4)/5)*16;case cu:return Math.floor((r+7)/8)*Math.floor((t+5)/6)*16;case lu:return Math.floor((r+7)/8)*Math.floor((t+7)/8)*16;case uu:return Math.floor((r+9)/10)*Math.floor((t+4)/5)*16;case hu:return Math.floor((r+9)/10)*Math.floor((t+5)/6)*16;case fu:return Math.floor((r+9)/10)*Math.floor((t+7)/8)*16;case du:return Math.floor((r+9)/10)*Math.floor((t+9)/10)*16;case pu:return Math.floor((r+11)/12)*Math.floor((t+9)/10)*16;case mu:return Math.floor((r+11)/12)*Math.floor((t+11)/12)*16;case gu:case xu:case vu:return Math.ceil(r/4)*Math.ceil(t/4)*16;case _u:case yu:return Math.ceil(r/4)*Math.ceil(t/4)*8;case bu:case Su:return Math.ceil(r/4)*Math.ceil(t/4)*16}throw new Error(`Unable to determine texture byte length for ${e} format.`)}function Sb(r){switch(r){case on:case Bs:return{byteLength:1,components:1};case Hi:case da:case Ge:return{byteLength:2,components:1};case Yl:case $l:return{byteLength:2,components:4};case an:case Gi:case $t:return{byteLength:4,components:1};case kd:case Vd:return{byteLength:4,components:3}}throw new Error(`Unknown texture type ${r}.`)}var Fd=class{static contain(t,e){return _b(t,e)}static cover(t,e){return yb(t,e)}static fill(t){return bb(t)}static getByteLength(t,e,n,i){return Tu(t,e,n,i)}};typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:"180"}}));typeof window<"u"&&(window.__THREE__?console.warn("WARNING: Multiple instances of Three.js being imported."):window.__THREE__="180");function H0(){let r=null,t=!1,e=null,n=null;function i(s,o){e(s,o),n=r.requestAnimationFrame(i)}return{start:function(){t!==!0&&e!==null&&(n=r.requestAnimationFrame(i),t=!0)},stop:function(){r.cancelAnimationFrame(n),t=!1},setAnimationLoop:function(s){e=s},setContext:function(s){r=s}}}function Mb(r){let t=new WeakMap;function e(a,c){let l=a.array,f=a.usage,h=l.byteLength,u=r.createBuffer();r.bindBuffer(c,u),r.bufferData(c,l,f),a.onUploadCallback();let d;if(l instanceof Float32Array)d=r.FLOAT;else if(typeof Float16Array<"u"&&l instanceof Float16Array)d=r.HALF_FLOAT;else if(l instanceof Uint16Array)a.isFloat16BufferAttribute?d=r.HALF_FLOAT:d=r.UNSIGNED_SHORT;else if(l instanceof Int16Array)d=r.SHORT;else if(l instanceof Uint32Array)d=r.UNSIGNED_INT;else if(l instanceof Int32Array)d=r.INT;else if(l instanceof Int8Array)d=r.BYTE;else if(l instanceof Uint8Array)d=r.UNSIGNED_BYTE;else if(l instanceof Uint8ClampedArray)d=r.UNSIGNED_BYTE;else throw new Error("THREE.WebGLAttributes: Unsupported buffer data format: "+l);return{buffer:u,type:d,bytesPerElement:l.BYTES_PER_ELEMENT,version:a.version,size:h}}function n(a,c,l){let f=c.array,h=c.updateRanges;if(r.bindBuffer(l,a),h.length===0)r.bufferSubData(l,0,f);else{h.sort((d,g)=>d.start-g.start);let u=0;for(let d=1;d 0 + vec4 plane; + #ifdef ALPHA_TO_COVERAGE + float distanceToPlane, distanceGradient; + float clipOpacity = 1.0; + #pragma unroll_loop_start + for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) { + plane = clippingPlanes[ i ]; + distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w; + distanceGradient = fwidth( distanceToPlane ) / 2.0; + clipOpacity *= smoothstep( - distanceGradient, distanceGradient, distanceToPlane ); + if ( clipOpacity == 0.0 ) discard; + } + #pragma unroll_loop_end + #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES + float unionClipOpacity = 1.0; + #pragma unroll_loop_start + for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) { + plane = clippingPlanes[ i ]; + distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w; + distanceGradient = fwidth( distanceToPlane ) / 2.0; + unionClipOpacity *= 1.0 - smoothstep( - distanceGradient, distanceGradient, distanceToPlane ); + } + #pragma unroll_loop_end + clipOpacity *= 1.0 - unionClipOpacity; + #endif + diffuseColor.a *= clipOpacity; + if ( diffuseColor.a == 0.0 ) discard; + #else + #pragma unroll_loop_start + for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) { + plane = clippingPlanes[ i ]; + if ( dot( vClipPosition, plane.xyz ) > plane.w ) discard; + } + #pragma unroll_loop_end + #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES + bool clipped = true; + #pragma unroll_loop_start + for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) { + plane = clippingPlanes[ i ]; + clipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped; + } + #pragma unroll_loop_end + if ( clipped ) discard; + #endif + #endif +#endif`,kb=`#if NUM_CLIPPING_PLANES > 0 + varying vec3 vClipPosition; + uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ]; +#endif`,Vb=`#if NUM_CLIPPING_PLANES > 0 + varying vec3 vClipPosition; +#endif`,Hb=`#if NUM_CLIPPING_PLANES > 0 + vClipPosition = - mvPosition.xyz; +#endif`,Gb=`#if defined( USE_COLOR_ALPHA ) + diffuseColor *= vColor; +#elif defined( USE_COLOR ) + diffuseColor.rgb *= vColor; +#endif`,Wb=`#if defined( USE_COLOR_ALPHA ) + varying vec4 vColor; +#elif defined( USE_COLOR ) + varying vec3 vColor; +#endif`,Xb=`#if defined( USE_COLOR_ALPHA ) + varying vec4 vColor; +#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR ) + varying vec3 vColor; +#endif`,qb=`#if defined( USE_COLOR_ALPHA ) + vColor = vec4( 1.0 ); +#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR ) + vColor = vec3( 1.0 ); +#endif +#ifdef USE_COLOR + vColor *= color; +#endif +#ifdef USE_INSTANCING_COLOR + vColor.xyz *= instanceColor.xyz; +#endif +#ifdef USE_BATCHING_COLOR + vec3 batchingColor = getBatchingColor( getIndirectIndex( gl_DrawID ) ); + vColor.xyz *= batchingColor.xyz; +#endif`,Yb=`#define PI 3.141592653589793 +#define PI2 6.283185307179586 +#define PI_HALF 1.5707963267948966 +#define RECIPROCAL_PI 0.3183098861837907 +#define RECIPROCAL_PI2 0.15915494309189535 +#define EPSILON 1e-6 +#ifndef saturate +#define saturate( a ) clamp( a, 0.0, 1.0 ) +#endif +#define whiteComplement( a ) ( 1.0 - saturate( a ) ) +float pow2( const in float x ) { return x*x; } +vec3 pow2( const in vec3 x ) { return x*x; } +float pow3( const in float x ) { return x*x*x; } +float pow4( const in float x ) { float x2 = x*x; return x2*x2; } +float max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); } +float average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); } +highp float rand( const in vec2 uv ) { + const highp float a = 12.9898, b = 78.233, c = 43758.5453; + highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI ); + return fract( sin( sn ) * c ); +} +#ifdef HIGH_PRECISION + float precisionSafeLength( vec3 v ) { return length( v ); } +#else + float precisionSafeLength( vec3 v ) { + float maxComponent = max3( abs( v ) ); + return length( v / maxComponent ) * maxComponent; + } +#endif +struct IncidentLight { + vec3 color; + vec3 direction; + bool visible; +}; +struct ReflectedLight { + vec3 directDiffuse; + vec3 directSpecular; + vec3 indirectDiffuse; + vec3 indirectSpecular; +}; +#ifdef USE_ALPHAHASH + varying vec3 vPosition; +#endif +vec3 transformDirection( in vec3 dir, in mat4 matrix ) { + return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz ); +} +vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) { + return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz ); +} +mat3 transposeMat3( const in mat3 m ) { + mat3 tmp; + tmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x ); + tmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y ); + tmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z ); + return tmp; +} +bool isPerspectiveMatrix( mat4 m ) { + return m[ 2 ][ 3 ] == - 1.0; +} +vec2 equirectUv( in vec3 dir ) { + float u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5; + float v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5; + return vec2( u, v ); +} +vec3 BRDF_Lambert( const in vec3 diffuseColor ) { + return RECIPROCAL_PI * diffuseColor; +} +vec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) { + float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH ); + return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel ); +} +float F_Schlick( const in float f0, const in float f90, const in float dotVH ) { + float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH ); + return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel ); +} // validated`,$b=`#ifdef ENVMAP_TYPE_CUBE_UV + #define cubeUV_minMipLevel 4.0 + #define cubeUV_minTileSize 16.0 + float getFace( vec3 direction ) { + vec3 absDirection = abs( direction ); + float face = - 1.0; + if ( absDirection.x > absDirection.z ) { + if ( absDirection.x > absDirection.y ) + face = direction.x > 0.0 ? 0.0 : 3.0; + else + face = direction.y > 0.0 ? 1.0 : 4.0; + } else { + if ( absDirection.z > absDirection.y ) + face = direction.z > 0.0 ? 2.0 : 5.0; + else + face = direction.y > 0.0 ? 1.0 : 4.0; + } + return face; + } + vec2 getUV( vec3 direction, float face ) { + vec2 uv; + if ( face == 0.0 ) { + uv = vec2( direction.z, direction.y ) / abs( direction.x ); + } else if ( face == 1.0 ) { + uv = vec2( - direction.x, - direction.z ) / abs( direction.y ); + } else if ( face == 2.0 ) { + uv = vec2( - direction.x, direction.y ) / abs( direction.z ); + } else if ( face == 3.0 ) { + uv = vec2( - direction.z, direction.y ) / abs( direction.x ); + } else if ( face == 4.0 ) { + uv = vec2( - direction.x, direction.z ) / abs( direction.y ); + } else { + uv = vec2( direction.x, direction.y ) / abs( direction.z ); + } + return 0.5 * ( uv + 1.0 ); + } + vec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) { + float face = getFace( direction ); + float filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 ); + mipInt = max( mipInt, cubeUV_minMipLevel ); + float faceSize = exp2( mipInt ); + highp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0; + if ( face > 2.0 ) { + uv.y += faceSize; + face -= 3.0; + } + uv.x += face * faceSize; + uv.x += filterInt * 3.0 * cubeUV_minTileSize; + uv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize ); + uv.x *= CUBEUV_TEXEL_WIDTH; + uv.y *= CUBEUV_TEXEL_HEIGHT; + #ifdef texture2DGradEXT + return texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb; + #else + return texture2D( envMap, uv ).rgb; + #endif + } + #define cubeUV_r0 1.0 + #define cubeUV_m0 - 2.0 + #define cubeUV_r1 0.8 + #define cubeUV_m1 - 1.0 + #define cubeUV_r4 0.4 + #define cubeUV_m4 2.0 + #define cubeUV_r5 0.305 + #define cubeUV_m5 3.0 + #define cubeUV_r6 0.21 + #define cubeUV_m6 4.0 + float roughnessToMip( float roughness ) { + float mip = 0.0; + if ( roughness >= cubeUV_r1 ) { + mip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0; + } else if ( roughness >= cubeUV_r4 ) { + mip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1; + } else if ( roughness >= cubeUV_r5 ) { + mip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4; + } else if ( roughness >= cubeUV_r6 ) { + mip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5; + } else { + mip = - 2.0 * log2( 1.16 * roughness ); } + return mip; + } + vec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) { + float mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP ); + float mipF = fract( mip ); + float mipInt = floor( mip ); + vec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt ); + if ( mipF == 0.0 ) { + return vec4( color0, 1.0 ); + } else { + vec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 ); + return vec4( mix( color0, color1, mipF ), 1.0 ); + } + } +#endif`,Zb=`vec3 transformedNormal = objectNormal; +#ifdef USE_TANGENT + vec3 transformedTangent = objectTangent; +#endif +#ifdef USE_BATCHING + mat3 bm = mat3( batchingMatrix ); + transformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) ); + transformedNormal = bm * transformedNormal; + #ifdef USE_TANGENT + transformedTangent = bm * transformedTangent; + #endif +#endif +#ifdef USE_INSTANCING + mat3 im = mat3( instanceMatrix ); + transformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) ); + transformedNormal = im * transformedNormal; + #ifdef USE_TANGENT + transformedTangent = im * transformedTangent; + #endif +#endif +transformedNormal = normalMatrix * transformedNormal; +#ifdef FLIP_SIDED + transformedNormal = - transformedNormal; +#endif +#ifdef USE_TANGENT + transformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz; + #ifdef FLIP_SIDED + transformedTangent = - transformedTangent; + #endif +#endif`,Jb=`#ifdef USE_DISPLACEMENTMAP + uniform sampler2D displacementMap; + uniform float displacementScale; + uniform float displacementBias; +#endif`,Kb=`#ifdef USE_DISPLACEMENTMAP + transformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias ); +#endif`,Qb=`#ifdef USE_EMISSIVEMAP + vec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv ); + #ifdef DECODE_VIDEO_TEXTURE_EMISSIVE + emissiveColor = sRGBTransferEOTF( emissiveColor ); + #endif + totalEmissiveRadiance *= emissiveColor.rgb; +#endif`,jb=`#ifdef USE_EMISSIVEMAP + uniform sampler2D emissiveMap; +#endif`,tS="gl_FragColor = linearToOutputTexel( gl_FragColor );",eS=`vec4 LinearTransferOETF( in vec4 value ) { + return value; +} +vec4 sRGBTransferEOTF( in vec4 value ) { + return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a ); +} +vec4 sRGBTransferOETF( in vec4 value ) { + return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a ); +}`,nS=`#ifdef USE_ENVMAP + #ifdef ENV_WORLDPOS + vec3 cameraToFrag; + if ( isOrthographic ) { + cameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) ); + } else { + cameraToFrag = normalize( vWorldPosition - cameraPosition ); + } + vec3 worldNormal = inverseTransformDirection( normal, viewMatrix ); + #ifdef ENVMAP_MODE_REFLECTION + vec3 reflectVec = reflect( cameraToFrag, worldNormal ); + #else + vec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio ); + #endif + #else + vec3 reflectVec = vReflect; + #endif + #ifdef ENVMAP_TYPE_CUBE + vec4 envColor = textureCube( envMap, envMapRotation * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) ); + #else + vec4 envColor = vec4( 0.0 ); + #endif + #ifdef ENVMAP_BLENDING_MULTIPLY + outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity ); + #elif defined( ENVMAP_BLENDING_MIX ) + outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity ); + #elif defined( ENVMAP_BLENDING_ADD ) + outgoingLight += envColor.xyz * specularStrength * reflectivity; + #endif +#endif`,iS=`#ifdef USE_ENVMAP + uniform float envMapIntensity; + uniform float flipEnvMap; + uniform mat3 envMapRotation; + #ifdef ENVMAP_TYPE_CUBE + uniform samplerCube envMap; + #else + uniform sampler2D envMap; + #endif + +#endif`,rS=`#ifdef USE_ENVMAP + uniform float reflectivity; + #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT ) + #define ENV_WORLDPOS + #endif + #ifdef ENV_WORLDPOS + varying vec3 vWorldPosition; + uniform float refractionRatio; + #else + varying vec3 vReflect; + #endif +#endif`,sS=`#ifdef USE_ENVMAP + #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT ) + #define ENV_WORLDPOS + #endif + #ifdef ENV_WORLDPOS + + varying vec3 vWorldPosition; + #else + varying vec3 vReflect; + uniform float refractionRatio; + #endif +#endif`,oS=`#ifdef USE_ENVMAP + #ifdef ENV_WORLDPOS + vWorldPosition = worldPosition.xyz; + #else + vec3 cameraToVertex; + if ( isOrthographic ) { + cameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) ); + } else { + cameraToVertex = normalize( worldPosition.xyz - cameraPosition ); + } + vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix ); + #ifdef ENVMAP_MODE_REFLECTION + vReflect = reflect( cameraToVertex, worldNormal ); + #else + vReflect = refract( cameraToVertex, worldNormal, refractionRatio ); + #endif + #endif +#endif`,aS=`#ifdef USE_FOG + vFogDepth = - mvPosition.z; +#endif`,cS=`#ifdef USE_FOG + varying float vFogDepth; +#endif`,lS=`#ifdef USE_FOG + #ifdef FOG_EXP2 + float fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth ); + #else + float fogFactor = smoothstep( fogNear, fogFar, vFogDepth ); + #endif + gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor ); +#endif`,uS=`#ifdef USE_FOG + uniform vec3 fogColor; + varying float vFogDepth; + #ifdef FOG_EXP2 + uniform float fogDensity; + #else + uniform float fogNear; + uniform float fogFar; + #endif +#endif`,hS=`#ifdef USE_GRADIENTMAP + uniform sampler2D gradientMap; +#endif +vec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) { + float dotNL = dot( normal, lightDirection ); + vec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 ); + #ifdef USE_GRADIENTMAP + return vec3( texture2D( gradientMap, coord ).r ); + #else + vec2 fw = fwidth( coord ) * 0.5; + return mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) ); + #endif +}`,fS=`#ifdef USE_LIGHTMAP + uniform sampler2D lightMap; + uniform float lightMapIntensity; +#endif`,dS=`LambertMaterial material; +material.diffuseColor = diffuseColor.rgb; +material.specularStrength = specularStrength;`,pS=`varying vec3 vViewPosition; +struct LambertMaterial { + vec3 diffuseColor; + float specularStrength; +}; +void RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) { + float dotNL = saturate( dot( geometryNormal, directLight.direction ) ); + vec3 irradiance = dotNL * directLight.color; + reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); +} +void RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) { + reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); +} +#define RE_Direct RE_Direct_Lambert +#define RE_IndirectDiffuse RE_IndirectDiffuse_Lambert`,mS=`uniform bool receiveShadow; +uniform vec3 ambientLightColor; +#if defined( USE_LIGHT_PROBES ) + uniform vec3 lightProbe[ 9 ]; +#endif +vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) { + float x = normal.x, y = normal.y, z = normal.z; + vec3 result = shCoefficients[ 0 ] * 0.886227; + result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y; + result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z; + result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x; + result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y; + result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z; + result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 ); + result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z; + result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y ); + return result; +} +vec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) { + vec3 worldNormal = inverseTransformDirection( normal, viewMatrix ); + vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe ); + return irradiance; +} +vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) { + vec3 irradiance = ambientLightColor; + return irradiance; +} +float getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) { + float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 ); + if ( cutoffDistance > 0.0 ) { + distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) ); + } + return distanceFalloff; +} +float getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) { + return smoothstep( coneCosine, penumbraCosine, angleCosine ); +} +#if NUM_DIR_LIGHTS > 0 + struct DirectionalLight { + vec3 direction; + vec3 color; + }; + uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ]; + void getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) { + light.color = directionalLight.color; + light.direction = directionalLight.direction; + light.visible = true; + } +#endif +#if NUM_POINT_LIGHTS > 0 + struct PointLight { + vec3 position; + vec3 color; + float distance; + float decay; + }; + uniform PointLight pointLights[ NUM_POINT_LIGHTS ]; + void getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) { + vec3 lVector = pointLight.position - geometryPosition; + light.direction = normalize( lVector ); + float lightDistance = length( lVector ); + light.color = pointLight.color; + light.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay ); + light.visible = ( light.color != vec3( 0.0 ) ); + } +#endif +#if NUM_SPOT_LIGHTS > 0 + struct SpotLight { + vec3 position; + vec3 direction; + vec3 color; + float distance; + float decay; + float coneCos; + float penumbraCos; + }; + uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ]; + void getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) { + vec3 lVector = spotLight.position - geometryPosition; + light.direction = normalize( lVector ); + float angleCos = dot( light.direction, spotLight.direction ); + float spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos ); + if ( spotAttenuation > 0.0 ) { + float lightDistance = length( lVector ); + light.color = spotLight.color * spotAttenuation; + light.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay ); + light.visible = ( light.color != vec3( 0.0 ) ); + } else { + light.color = vec3( 0.0 ); + light.visible = false; + } + } +#endif +#if NUM_RECT_AREA_LIGHTS > 0 + struct RectAreaLight { + vec3 color; + vec3 position; + vec3 halfWidth; + vec3 halfHeight; + }; + uniform sampler2D ltc_1; uniform sampler2D ltc_2; + uniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ]; +#endif +#if NUM_HEMI_LIGHTS > 0 + struct HemisphereLight { + vec3 direction; + vec3 skyColor; + vec3 groundColor; + }; + uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ]; + vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) { + float dotNL = dot( normal, hemiLight.direction ); + float hemiDiffuseWeight = 0.5 * dotNL + 0.5; + vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight ); + return irradiance; + } +#endif`,gS=`#ifdef USE_ENVMAP + vec3 getIBLIrradiance( const in vec3 normal ) { + #ifdef ENVMAP_TYPE_CUBE_UV + vec3 worldNormal = inverseTransformDirection( normal, viewMatrix ); + vec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 ); + return PI * envMapColor.rgb * envMapIntensity; + #else + return vec3( 0.0 ); + #endif + } + vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) { + #ifdef ENVMAP_TYPE_CUBE_UV + vec3 reflectVec = reflect( - viewDir, normal ); + reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) ); + reflectVec = inverseTransformDirection( reflectVec, viewMatrix ); + vec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness ); + return envMapColor.rgb * envMapIntensity; + #else + return vec3( 0.0 ); + #endif + } + #ifdef USE_ANISOTROPY + vec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) { + #ifdef ENVMAP_TYPE_CUBE_UV + vec3 bentNormal = cross( bitangent, viewDir ); + bentNormal = normalize( cross( bentNormal, bitangent ) ); + bentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) ); + return getIBLRadiance( viewDir, bentNormal, roughness ); + #else + return vec3( 0.0 ); + #endif + } + #endif +#endif`,xS=`ToonMaterial material; +material.diffuseColor = diffuseColor.rgb;`,vS=`varying vec3 vViewPosition; +struct ToonMaterial { + vec3 diffuseColor; +}; +void RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) { + vec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color; + reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); +} +void RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) { + reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); +} +#define RE_Direct RE_Direct_Toon +#define RE_IndirectDiffuse RE_IndirectDiffuse_Toon`,_S=`BlinnPhongMaterial material; +material.diffuseColor = diffuseColor.rgb; +material.specularColor = specular; +material.specularShininess = shininess; +material.specularStrength = specularStrength;`,yS=`varying vec3 vViewPosition; +struct BlinnPhongMaterial { + vec3 diffuseColor; + vec3 specularColor; + float specularShininess; + float specularStrength; +}; +void RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) { + float dotNL = saturate( dot( geometryNormal, directLight.direction ) ); + vec3 irradiance = dotNL * directLight.color; + reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); + reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength; +} +void RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) { + reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); +} +#define RE_Direct RE_Direct_BlinnPhong +#define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong`,bS=`PhysicalMaterial material; +material.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor ); +vec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) ); +float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z ); +material.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness; +material.roughness = min( material.roughness, 1.0 ); +#ifdef IOR + material.ior = ior; + #ifdef USE_SPECULAR + float specularIntensityFactor = specularIntensity; + vec3 specularColorFactor = specularColor; + #ifdef USE_SPECULAR_COLORMAP + specularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb; + #endif + #ifdef USE_SPECULAR_INTENSITYMAP + specularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a; + #endif + material.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor ); + #else + float specularIntensityFactor = 1.0; + vec3 specularColorFactor = vec3( 1.0 ); + material.specularF90 = 1.0; + #endif + material.specularColor = mix( min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor ); +#else + material.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor ); + material.specularF90 = 1.0; +#endif +#ifdef USE_CLEARCOAT + material.clearcoat = clearcoat; + material.clearcoatRoughness = clearcoatRoughness; + material.clearcoatF0 = vec3( 0.04 ); + material.clearcoatF90 = 1.0; + #ifdef USE_CLEARCOATMAP + material.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x; + #endif + #ifdef USE_CLEARCOAT_ROUGHNESSMAP + material.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y; + #endif + material.clearcoat = saturate( material.clearcoat ); material.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 ); + material.clearcoatRoughness += geometryRoughness; + material.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 ); +#endif +#ifdef USE_DISPERSION + material.dispersion = dispersion; +#endif +#ifdef USE_IRIDESCENCE + material.iridescence = iridescence; + material.iridescenceIOR = iridescenceIOR; + #ifdef USE_IRIDESCENCEMAP + material.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r; + #endif + #ifdef USE_IRIDESCENCE_THICKNESSMAP + material.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum; + #else + material.iridescenceThickness = iridescenceThicknessMaximum; + #endif +#endif +#ifdef USE_SHEEN + material.sheenColor = sheenColor; + #ifdef USE_SHEEN_COLORMAP + material.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb; + #endif + material.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 ); + #ifdef USE_SHEEN_ROUGHNESSMAP + material.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a; + #endif +#endif +#ifdef USE_ANISOTROPY + #ifdef USE_ANISOTROPYMAP + mat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x ); + vec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb; + vec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b; + #else + vec2 anisotropyV = anisotropyVector; + #endif + material.anisotropy = length( anisotropyV ); + if( material.anisotropy == 0.0 ) { + anisotropyV = vec2( 1.0, 0.0 ); + } else { + anisotropyV /= material.anisotropy; + material.anisotropy = saturate( material.anisotropy ); + } + material.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) ); + material.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y; + material.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y; +#endif`,SS=`struct PhysicalMaterial { + vec3 diffuseColor; + float roughness; + vec3 specularColor; + float specularF90; + float dispersion; + #ifdef USE_CLEARCOAT + float clearcoat; + float clearcoatRoughness; + vec3 clearcoatF0; + float clearcoatF90; + #endif + #ifdef USE_IRIDESCENCE + float iridescence; + float iridescenceIOR; + float iridescenceThickness; + vec3 iridescenceFresnel; + vec3 iridescenceF0; + #endif + #ifdef USE_SHEEN + vec3 sheenColor; + float sheenRoughness; + #endif + #ifdef IOR + float ior; + #endif + #ifdef USE_TRANSMISSION + float transmission; + float transmissionAlpha; + float thickness; + float attenuationDistance; + vec3 attenuationColor; + #endif + #ifdef USE_ANISOTROPY + float anisotropy; + float alphaT; + vec3 anisotropyT; + vec3 anisotropyB; + #endif +}; +vec3 clearcoatSpecularDirect = vec3( 0.0 ); +vec3 clearcoatSpecularIndirect = vec3( 0.0 ); +vec3 sheenSpecularDirect = vec3( 0.0 ); +vec3 sheenSpecularIndirect = vec3(0.0 ); +vec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) { + float x = clamp( 1.0 - dotVH, 0.0, 1.0 ); + float x2 = x * x; + float x5 = clamp( x * x2 * x2, 0.0, 0.9999 ); + return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 ); +} +float V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) { + float a2 = pow2( alpha ); + float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) ); + float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) ); + return 0.5 / max( gv + gl, EPSILON ); +} +float D_GGX( const in float alpha, const in float dotNH ) { + float a2 = pow2( alpha ); + float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0; + return RECIPROCAL_PI * a2 / pow2( denom ); +} +#ifdef USE_ANISOTROPY + float V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) { + float gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) ); + float gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) ); + float v = 0.5 / ( gv + gl ); + return saturate(v); + } + float D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) { + float a2 = alphaT * alphaB; + highp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH ); + highp float v2 = dot( v, v ); + float w2 = a2 / v2; + return RECIPROCAL_PI * a2 * pow2 ( w2 ); + } +#endif +#ifdef USE_CLEARCOAT + vec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) { + vec3 f0 = material.clearcoatF0; + float f90 = material.clearcoatF90; + float roughness = material.clearcoatRoughness; + float alpha = pow2( roughness ); + vec3 halfDir = normalize( lightDir + viewDir ); + float dotNL = saturate( dot( normal, lightDir ) ); + float dotNV = saturate( dot( normal, viewDir ) ); + float dotNH = saturate( dot( normal, halfDir ) ); + float dotVH = saturate( dot( viewDir, halfDir ) ); + vec3 F = F_Schlick( f0, f90, dotVH ); + float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV ); + float D = D_GGX( alpha, dotNH ); + return F * ( V * D ); + } +#endif +vec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) { + vec3 f0 = material.specularColor; + float f90 = material.specularF90; + float roughness = material.roughness; + float alpha = pow2( roughness ); + vec3 halfDir = normalize( lightDir + viewDir ); + float dotNL = saturate( dot( normal, lightDir ) ); + float dotNV = saturate( dot( normal, viewDir ) ); + float dotNH = saturate( dot( normal, halfDir ) ); + float dotVH = saturate( dot( viewDir, halfDir ) ); + vec3 F = F_Schlick( f0, f90, dotVH ); + #ifdef USE_IRIDESCENCE + F = mix( F, material.iridescenceFresnel, material.iridescence ); + #endif + #ifdef USE_ANISOTROPY + float dotTL = dot( material.anisotropyT, lightDir ); + float dotTV = dot( material.anisotropyT, viewDir ); + float dotTH = dot( material.anisotropyT, halfDir ); + float dotBL = dot( material.anisotropyB, lightDir ); + float dotBV = dot( material.anisotropyB, viewDir ); + float dotBH = dot( material.anisotropyB, halfDir ); + float V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL ); + float D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH ); + #else + float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV ); + float D = D_GGX( alpha, dotNH ); + #endif + return F * ( V * D ); +} +vec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) { + const float LUT_SIZE = 64.0; + const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE; + const float LUT_BIAS = 0.5 / LUT_SIZE; + float dotNV = saturate( dot( N, V ) ); + vec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) ); + uv = uv * LUT_SCALE + LUT_BIAS; + return uv; +} +float LTC_ClippedSphereFormFactor( const in vec3 f ) { + float l = length( f ); + return max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 ); +} +vec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) { + float x = dot( v1, v2 ); + float y = abs( x ); + float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y; + float b = 3.4175940 + ( 4.1616724 + y ) * y; + float v = a / b; + float theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v; + return cross( v1, v2 ) * theta_sintheta; +} +vec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) { + vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ]; + vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ]; + vec3 lightNormal = cross( v1, v2 ); + if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 ); + vec3 T1, T2; + T1 = normalize( V - N * dot( V, N ) ); + T2 = - cross( N, T1 ); + mat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) ); + vec3 coords[ 4 ]; + coords[ 0 ] = mat * ( rectCoords[ 0 ] - P ); + coords[ 1 ] = mat * ( rectCoords[ 1 ] - P ); + coords[ 2 ] = mat * ( rectCoords[ 2 ] - P ); + coords[ 3 ] = mat * ( rectCoords[ 3 ] - P ); + coords[ 0 ] = normalize( coords[ 0 ] ); + coords[ 1 ] = normalize( coords[ 1 ] ); + coords[ 2 ] = normalize( coords[ 2 ] ); + coords[ 3 ] = normalize( coords[ 3 ] ); + vec3 vectorFormFactor = vec3( 0.0 ); + vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] ); + vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] ); + vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] ); + vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] ); + float result = LTC_ClippedSphereFormFactor( vectorFormFactor ); + return vec3( result ); +} +#if defined( USE_SHEEN ) +float D_Charlie( float roughness, float dotNH ) { + float alpha = pow2( roughness ); + float invAlpha = 1.0 / alpha; + float cos2h = dotNH * dotNH; + float sin2h = max( 1.0 - cos2h, 0.0078125 ); + return ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI ); +} +float V_Neubelt( float dotNV, float dotNL ) { + return saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) ); +} +vec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) { + vec3 halfDir = normalize( lightDir + viewDir ); + float dotNL = saturate( dot( normal, lightDir ) ); + float dotNV = saturate( dot( normal, viewDir ) ); + float dotNH = saturate( dot( normal, halfDir ) ); + float D = D_Charlie( sheenRoughness, dotNH ); + float V = V_Neubelt( dotNV, dotNL ); + return sheenColor * ( D * V ); +} +#endif +float IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) { + float dotNV = saturate( dot( normal, viewDir ) ); + float r2 = roughness * roughness; + float a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95; + float b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72; + float DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) ); + return saturate( DG * RECIPROCAL_PI ); +} +vec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) { + float dotNV = saturate( dot( normal, viewDir ) ); + const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 ); + const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 ); + vec4 r = roughness * c0 + c1; + float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y; + vec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw; + return fab; +} +vec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) { + vec2 fab = DFGApprox( normal, viewDir, roughness ); + return specularColor * fab.x + specularF90 * fab.y; +} +#ifdef USE_IRIDESCENCE +void computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) { +#else +void computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) { +#endif + vec2 fab = DFGApprox( normal, viewDir, roughness ); + #ifdef USE_IRIDESCENCE + vec3 Fr = mix( specularColor, iridescenceF0, iridescence ); + #else + vec3 Fr = specularColor; + #endif + vec3 FssEss = Fr * fab.x + specularF90 * fab.y; + float Ess = fab.x + fab.y; + float Ems = 1.0 - Ess; + vec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619; vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg ); + singleScatter += FssEss; + multiScatter += Fms * Ems; +} +#if NUM_RECT_AREA_LIGHTS > 0 + void RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) { + vec3 normal = geometryNormal; + vec3 viewDir = geometryViewDir; + vec3 position = geometryPosition; + vec3 lightPos = rectAreaLight.position; + vec3 halfWidth = rectAreaLight.halfWidth; + vec3 halfHeight = rectAreaLight.halfHeight; + vec3 lightColor = rectAreaLight.color; + float roughness = material.roughness; + vec3 rectCoords[ 4 ]; + rectCoords[ 0 ] = lightPos + halfWidth - halfHeight; rectCoords[ 1 ] = lightPos - halfWidth - halfHeight; + rectCoords[ 2 ] = lightPos - halfWidth + halfHeight; + rectCoords[ 3 ] = lightPos + halfWidth + halfHeight; + vec2 uv = LTC_Uv( normal, viewDir, roughness ); + vec4 t1 = texture2D( ltc_1, uv ); + vec4 t2 = texture2D( ltc_2, uv ); + mat3 mInv = mat3( + vec3( t1.x, 0, t1.y ), + vec3( 0, 1, 0 ), + vec3( t1.z, 0, t1.w ) + ); + vec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y ); + reflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords ); + reflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords ); + } +#endif +void RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) { + float dotNL = saturate( dot( geometryNormal, directLight.direction ) ); + vec3 irradiance = dotNL * directLight.color; + #ifdef USE_CLEARCOAT + float dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) ); + vec3 ccIrradiance = dotNLcc * directLight.color; + clearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material ); + #endif + #ifdef USE_SHEEN + sheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness ); + #endif + reflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometryViewDir, geometryNormal, material ); + reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); +} +void RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) { + reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); +} +void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) { + #ifdef USE_CLEARCOAT + clearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness ); + #endif + #ifdef USE_SHEEN + sheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness ); + #endif + vec3 singleScattering = vec3( 0.0 ); + vec3 multiScattering = vec3( 0.0 ); + vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI; + #ifdef USE_IRIDESCENCE + computeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnel, material.roughness, singleScattering, multiScattering ); + #else + computeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering ); + #endif + vec3 totalScattering = singleScattering + multiScattering; + vec3 diffuse = material.diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) ); + reflectedLight.indirectSpecular += radiance * singleScattering; + reflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance; + reflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance; +} +#define RE_Direct RE_Direct_Physical +#define RE_Direct_RectArea RE_Direct_RectArea_Physical +#define RE_IndirectDiffuse RE_IndirectDiffuse_Physical +#define RE_IndirectSpecular RE_IndirectSpecular_Physical +float computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) { + return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion ); +}`,MS=` +vec3 geometryPosition = - vViewPosition; +vec3 geometryNormal = normal; +vec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition ); +vec3 geometryClearcoatNormal = vec3( 0.0 ); +#ifdef USE_CLEARCOAT + geometryClearcoatNormal = clearcoatNormal; +#endif +#ifdef USE_IRIDESCENCE + float dotNVi = saturate( dot( normal, geometryViewDir ) ); + if ( material.iridescenceThickness == 0.0 ) { + material.iridescence = 0.0; + } else { + material.iridescence = saturate( material.iridescence ); + } + if ( material.iridescence > 0.0 ) { + material.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor ); + material.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi ); + } +#endif +IncidentLight directLight; +#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct ) + PointLight pointLight; + #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0 + PointLightShadow pointLightShadow; + #endif + #pragma unroll_loop_start + for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) { + pointLight = pointLights[ i ]; + getPointLightInfo( pointLight, geometryPosition, directLight ); + #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS ) + pointLightShadow = pointLightShadows[ i ]; + directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0; + #endif + RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); + } + #pragma unroll_loop_end +#endif +#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct ) + SpotLight spotLight; + vec4 spotColor; + vec3 spotLightCoord; + bool inSpotLightMap; + #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0 + SpotLightShadow spotLightShadow; + #endif + #pragma unroll_loop_start + for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) { + spotLight = spotLights[ i ]; + getSpotLightInfo( spotLight, geometryPosition, directLight ); + #if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS ) + #define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX + #elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS ) + #define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS + #else + #define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS ) + #endif + #if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS ) + spotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w; + inSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) ); + spotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy ); + directLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color; + #endif + #undef SPOT_LIGHT_MAP_INDEX + #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS ) + spotLightShadow = spotLightShadows[ i ]; + directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0; + #endif + RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); + } + #pragma unroll_loop_end +#endif +#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct ) + DirectionalLight directionalLight; + #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0 + DirectionalLightShadow directionalLightShadow; + #endif + #pragma unroll_loop_start + for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) { + directionalLight = directionalLights[ i ]; + getDirectionalLightInfo( directionalLight, directLight ); + #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS ) + directionalLightShadow = directionalLightShadows[ i ]; + directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0; + #endif + RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); + } + #pragma unroll_loop_end +#endif +#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea ) + RectAreaLight rectAreaLight; + #pragma unroll_loop_start + for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) { + rectAreaLight = rectAreaLights[ i ]; + RE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); + } + #pragma unroll_loop_end +#endif +#if defined( RE_IndirectDiffuse ) + vec3 iblIrradiance = vec3( 0.0 ); + vec3 irradiance = getAmbientLightIrradiance( ambientLightColor ); + #if defined( USE_LIGHT_PROBES ) + irradiance += getLightProbeIrradiance( lightProbe, geometryNormal ); + #endif + #if ( NUM_HEMI_LIGHTS > 0 ) + #pragma unroll_loop_start + for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) { + irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal ); + } + #pragma unroll_loop_end + #endif +#endif +#if defined( RE_IndirectSpecular ) + vec3 radiance = vec3( 0.0 ); + vec3 clearcoatRadiance = vec3( 0.0 ); +#endif`,TS=`#if defined( RE_IndirectDiffuse ) + #ifdef USE_LIGHTMAP + vec4 lightMapTexel = texture2D( lightMap, vLightMapUv ); + vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity; + irradiance += lightMapIrradiance; + #endif + #if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV ) + iblIrradiance += getIBLIrradiance( geometryNormal ); + #endif +#endif +#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular ) + #ifdef USE_ANISOTROPY + radiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy ); + #else + radiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness ); + #endif + #ifdef USE_CLEARCOAT + clearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness ); + #endif +#endif`,wS=`#if defined( RE_IndirectDiffuse ) + RE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); +#endif +#if defined( RE_IndirectSpecular ) + RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); +#endif`,AS=`#if defined( USE_LOGARITHMIC_DEPTH_BUFFER ) + gl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5; +#endif`,ES=`#if defined( USE_LOGARITHMIC_DEPTH_BUFFER ) + uniform float logDepthBufFC; + varying float vFragDepth; + varying float vIsPerspective; +#endif`,RS=`#ifdef USE_LOGARITHMIC_DEPTH_BUFFER + varying float vFragDepth; + varying float vIsPerspective; +#endif`,CS=`#ifdef USE_LOGARITHMIC_DEPTH_BUFFER + vFragDepth = 1.0 + gl_Position.w; + vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) ); +#endif`,IS=`#ifdef USE_MAP + vec4 sampledDiffuseColor = texture2D( map, vMapUv ); + #ifdef DECODE_VIDEO_TEXTURE + sampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor ); + #endif + diffuseColor *= sampledDiffuseColor; +#endif`,PS=`#ifdef USE_MAP + uniform sampler2D map; +#endif`,DS=`#if defined( USE_MAP ) || defined( USE_ALPHAMAP ) + #if defined( USE_POINTS_UV ) + vec2 uv = vUv; + #else + vec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy; + #endif +#endif +#ifdef USE_MAP + diffuseColor *= texture2D( map, uv ); +#endif +#ifdef USE_ALPHAMAP + diffuseColor.a *= texture2D( alphaMap, uv ).g; +#endif`,FS=`#if defined( USE_POINTS_UV ) + varying vec2 vUv; +#else + #if defined( USE_MAP ) || defined( USE_ALPHAMAP ) + uniform mat3 uvTransform; + #endif +#endif +#ifdef USE_MAP + uniform sampler2D map; +#endif +#ifdef USE_ALPHAMAP + uniform sampler2D alphaMap; +#endif`,LS=`float metalnessFactor = metalness; +#ifdef USE_METALNESSMAP + vec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv ); + metalnessFactor *= texelMetalness.b; +#endif`,NS=`#ifdef USE_METALNESSMAP + uniform sampler2D metalnessMap; +#endif`,US=`#ifdef USE_INSTANCING_MORPH + float morphTargetInfluences[ MORPHTARGETS_COUNT ]; + float morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r; + for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) { + morphTargetInfluences[i] = texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r; + } +#endif`,BS=`#if defined( USE_MORPHCOLORS ) + vColor *= morphTargetBaseInfluence; + for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) { + #if defined( USE_COLOR_ALPHA ) + if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ]; + #elif defined( USE_COLOR ) + if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ]; + #endif + } +#endif`,OS=`#ifdef USE_MORPHNORMALS + objectNormal *= morphTargetBaseInfluence; + for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) { + if ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ]; + } +#endif`,zS=`#ifdef USE_MORPHTARGETS + #ifndef USE_INSTANCING_MORPH + uniform float morphTargetBaseInfluence; + uniform float morphTargetInfluences[ MORPHTARGETS_COUNT ]; + #endif + uniform sampler2DArray morphTargetsTexture; + uniform ivec2 morphTargetsTextureSize; + vec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) { + int texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset; + int y = texelIndex / morphTargetsTextureSize.x; + int x = texelIndex - y * morphTargetsTextureSize.x; + ivec3 morphUV = ivec3( x, y, morphTargetIndex ); + return texelFetch( morphTargetsTexture, morphUV, 0 ); + } +#endif`,kS=`#ifdef USE_MORPHTARGETS + transformed *= morphTargetBaseInfluence; + for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) { + if ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ]; + } +#endif`,VS=`float faceDirection = gl_FrontFacing ? 1.0 : - 1.0; +#ifdef FLAT_SHADED + vec3 fdx = dFdx( vViewPosition ); + vec3 fdy = dFdy( vViewPosition ); + vec3 normal = normalize( cross( fdx, fdy ) ); +#else + vec3 normal = normalize( vNormal ); + #ifdef DOUBLE_SIDED + normal *= faceDirection; + #endif +#endif +#if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) + #ifdef USE_TANGENT + mat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal ); + #else + mat3 tbn = getTangentFrame( - vViewPosition, normal, + #if defined( USE_NORMALMAP ) + vNormalMapUv + #elif defined( USE_CLEARCOAT_NORMALMAP ) + vClearcoatNormalMapUv + #else + vUv + #endif + ); + #endif + #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED ) + tbn[0] *= faceDirection; + tbn[1] *= faceDirection; + #endif +#endif +#ifdef USE_CLEARCOAT_NORMALMAP + #ifdef USE_TANGENT + mat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal ); + #else + mat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv ); + #endif + #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED ) + tbn2[0] *= faceDirection; + tbn2[1] *= faceDirection; + #endif +#endif +vec3 nonPerturbedNormal = normal;`,HS=`#ifdef USE_NORMALMAP_OBJECTSPACE + normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0; + #ifdef FLIP_SIDED + normal = - normal; + #endif + #ifdef DOUBLE_SIDED + normal = normal * faceDirection; + #endif + normal = normalize( normalMatrix * normal ); +#elif defined( USE_NORMALMAP_TANGENTSPACE ) + vec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0; + mapN.xy *= normalScale; + normal = normalize( tbn * mapN ); +#elif defined( USE_BUMPMAP ) + normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection ); +#endif`,GS=`#ifndef FLAT_SHADED + varying vec3 vNormal; + #ifdef USE_TANGENT + varying vec3 vTangent; + varying vec3 vBitangent; + #endif +#endif`,WS=`#ifndef FLAT_SHADED + varying vec3 vNormal; + #ifdef USE_TANGENT + varying vec3 vTangent; + varying vec3 vBitangent; + #endif +#endif`,XS=`#ifndef FLAT_SHADED + vNormal = normalize( transformedNormal ); + #ifdef USE_TANGENT + vTangent = normalize( transformedTangent ); + vBitangent = normalize( cross( vNormal, vTangent ) * tangent.w ); + #endif +#endif`,qS=`#ifdef USE_NORMALMAP + uniform sampler2D normalMap; + uniform vec2 normalScale; +#endif +#ifdef USE_NORMALMAP_OBJECTSPACE + uniform mat3 normalMatrix; +#endif +#if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) ) + mat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) { + vec3 q0 = dFdx( eye_pos.xyz ); + vec3 q1 = dFdy( eye_pos.xyz ); + vec2 st0 = dFdx( uv.st ); + vec2 st1 = dFdy( uv.st ); + vec3 N = surf_norm; + vec3 q1perp = cross( q1, N ); + vec3 q0perp = cross( N, q0 ); + vec3 T = q1perp * st0.x + q0perp * st1.x; + vec3 B = q1perp * st0.y + q0perp * st1.y; + float det = max( dot( T, T ), dot( B, B ) ); + float scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det ); + return mat3( T * scale, B * scale, N ); + } +#endif`,YS=`#ifdef USE_CLEARCOAT + vec3 clearcoatNormal = nonPerturbedNormal; +#endif`,$S=`#ifdef USE_CLEARCOAT_NORMALMAP + vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0; + clearcoatMapN.xy *= clearcoatNormalScale; + clearcoatNormal = normalize( tbn2 * clearcoatMapN ); +#endif`,ZS=`#ifdef USE_CLEARCOATMAP + uniform sampler2D clearcoatMap; +#endif +#ifdef USE_CLEARCOAT_NORMALMAP + uniform sampler2D clearcoatNormalMap; + uniform vec2 clearcoatNormalScale; +#endif +#ifdef USE_CLEARCOAT_ROUGHNESSMAP + uniform sampler2D clearcoatRoughnessMap; +#endif`,JS=`#ifdef USE_IRIDESCENCEMAP + uniform sampler2D iridescenceMap; +#endif +#ifdef USE_IRIDESCENCE_THICKNESSMAP + uniform sampler2D iridescenceThicknessMap; +#endif`,KS=`#ifdef OPAQUE +diffuseColor.a = 1.0; +#endif +#ifdef USE_TRANSMISSION +diffuseColor.a *= material.transmissionAlpha; +#endif +gl_FragColor = vec4( outgoingLight, diffuseColor.a );`,QS=`vec3 packNormalToRGB( const in vec3 normal ) { + return normalize( normal ) * 0.5 + 0.5; +} +vec3 unpackRGBToNormal( const in vec3 rgb ) { + return 2.0 * rgb.xyz - 1.0; +} +const float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;const float ShiftRight8 = 1. / 256.; +const float Inv255 = 1. / 255.; +const vec4 PackFactors = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 ); +const vec2 UnpackFactors2 = vec2( UnpackDownscale, 1.0 / PackFactors.g ); +const vec3 UnpackFactors3 = vec3( UnpackDownscale / PackFactors.rg, 1.0 / PackFactors.b ); +const vec4 UnpackFactors4 = vec4( UnpackDownscale / PackFactors.rgb, 1.0 / PackFactors.a ); +vec4 packDepthToRGBA( const in float v ) { + if( v <= 0.0 ) + return vec4( 0., 0., 0., 0. ); + if( v >= 1.0 ) + return vec4( 1., 1., 1., 1. ); + float vuf; + float af = modf( v * PackFactors.a, vuf ); + float bf = modf( vuf * ShiftRight8, vuf ); + float gf = modf( vuf * ShiftRight8, vuf ); + return vec4( vuf * Inv255, gf * PackUpscale, bf * PackUpscale, af ); +} +vec3 packDepthToRGB( const in float v ) { + if( v <= 0.0 ) + return vec3( 0., 0., 0. ); + if( v >= 1.0 ) + return vec3( 1., 1., 1. ); + float vuf; + float bf = modf( v * PackFactors.b, vuf ); + float gf = modf( vuf * ShiftRight8, vuf ); + return vec3( vuf * Inv255, gf * PackUpscale, bf ); +} +vec2 packDepthToRG( const in float v ) { + if( v <= 0.0 ) + return vec2( 0., 0. ); + if( v >= 1.0 ) + return vec2( 1., 1. ); + float vuf; + float gf = modf( v * 256., vuf ); + return vec2( vuf * Inv255, gf ); +} +float unpackRGBAToDepth( const in vec4 v ) { + return dot( v, UnpackFactors4 ); +} +float unpackRGBToDepth( const in vec3 v ) { + return dot( v, UnpackFactors3 ); +} +float unpackRGToDepth( const in vec2 v ) { + return v.r * UnpackFactors2.r + v.g * UnpackFactors2.g; +} +vec4 pack2HalfToRGBA( const in vec2 v ) { + vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) ); + return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w ); +} +vec2 unpackRGBATo2Half( const in vec4 v ) { + return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) ); +} +float viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) { + return ( viewZ + near ) / ( near - far ); +} +float orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) { + return depth * ( near - far ) - near; +} +float viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) { + return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ ); +} +float perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) { + return ( near * far ) / ( ( far - near ) * depth - far ); +}`,jS=`#ifdef PREMULTIPLIED_ALPHA + gl_FragColor.rgb *= gl_FragColor.a; +#endif`,tM=`vec4 mvPosition = vec4( transformed, 1.0 ); +#ifdef USE_BATCHING + mvPosition = batchingMatrix * mvPosition; +#endif +#ifdef USE_INSTANCING + mvPosition = instanceMatrix * mvPosition; +#endif +mvPosition = modelViewMatrix * mvPosition; +gl_Position = projectionMatrix * mvPosition;`,eM=`#ifdef DITHERING + gl_FragColor.rgb = dithering( gl_FragColor.rgb ); +#endif`,nM=`#ifdef DITHERING + vec3 dithering( vec3 color ) { + float grid_position = rand( gl_FragCoord.xy ); + vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 ); + dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position ); + return color + dither_shift_RGB; + } +#endif`,iM=`float roughnessFactor = roughness; +#ifdef USE_ROUGHNESSMAP + vec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv ); + roughnessFactor *= texelRoughness.g; +#endif`,rM=`#ifdef USE_ROUGHNESSMAP + uniform sampler2D roughnessMap; +#endif`,sM=`#if NUM_SPOT_LIGHT_COORDS > 0 + varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ]; +#endif +#if NUM_SPOT_LIGHT_MAPS > 0 + uniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ]; +#endif +#ifdef USE_SHADOWMAP + #if NUM_DIR_LIGHT_SHADOWS > 0 + uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ]; + varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ]; + struct DirectionalLightShadow { + float shadowIntensity; + float shadowBias; + float shadowNormalBias; + float shadowRadius; + vec2 shadowMapSize; + }; + uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ]; + #endif + #if NUM_SPOT_LIGHT_SHADOWS > 0 + uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ]; + struct SpotLightShadow { + float shadowIntensity; + float shadowBias; + float shadowNormalBias; + float shadowRadius; + vec2 shadowMapSize; + }; + uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ]; + #endif + #if NUM_POINT_LIGHT_SHADOWS > 0 + uniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ]; + varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ]; + struct PointLightShadow { + float shadowIntensity; + float shadowBias; + float shadowNormalBias; + float shadowRadius; + vec2 shadowMapSize; + float shadowCameraNear; + float shadowCameraFar; + }; + uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ]; + #endif + float texture2DCompare( sampler2D depths, vec2 uv, float compare ) { + float depth = unpackRGBAToDepth( texture2D( depths, uv ) ); + #ifdef USE_REVERSED_DEPTH_BUFFER + return step( depth, compare ); + #else + return step( compare, depth ); + #endif + } + vec2 texture2DDistribution( sampler2D shadow, vec2 uv ) { + return unpackRGBATo2Half( texture2D( shadow, uv ) ); + } + float VSMShadow( sampler2D shadow, vec2 uv, float compare ) { + float occlusion = 1.0; + vec2 distribution = texture2DDistribution( shadow, uv ); + #ifdef USE_REVERSED_DEPTH_BUFFER + float hard_shadow = step( distribution.x, compare ); + #else + float hard_shadow = step( compare, distribution.x ); + #endif + if ( hard_shadow != 1.0 ) { + float distance = compare - distribution.x; + float variance = max( 0.00000, distribution.y * distribution.y ); + float softness_probability = variance / (variance + distance * distance ); softness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 ); occlusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 ); + } + return occlusion; + } + float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) { + float shadow = 1.0; + shadowCoord.xyz /= shadowCoord.w; + shadowCoord.z += shadowBias; + bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0; + bool frustumTest = inFrustum && shadowCoord.z <= 1.0; + if ( frustumTest ) { + #if defined( SHADOWMAP_TYPE_PCF ) + vec2 texelSize = vec2( 1.0 ) / shadowMapSize; + float dx0 = - texelSize.x * shadowRadius; + float dy0 = - texelSize.y * shadowRadius; + float dx1 = + texelSize.x * shadowRadius; + float dy1 = + texelSize.y * shadowRadius; + float dx2 = dx0 / 2.0; + float dy2 = dy0 / 2.0; + float dx3 = dx1 / 2.0; + float dy3 = dy1 / 2.0; + shadow = ( + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z ) + ) * ( 1.0 / 17.0 ); + #elif defined( SHADOWMAP_TYPE_PCF_SOFT ) + vec2 texelSize = vec2( 1.0 ) / shadowMapSize; + float dx = texelSize.x; + float dy = texelSize.y; + vec2 uv = shadowCoord.xy; + vec2 f = fract( uv * shadowMapSize + 0.5 ); + uv -= f * texelSize; + shadow = ( + texture2DCompare( shadowMap, uv, shadowCoord.z ) + + texture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) + + texture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) + + mix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ), + texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ), + f.x ) + + mix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ), + texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ), + f.x ) + + mix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ), + texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ), + f.y ) + + mix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ), + texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ), + f.y ) + + mix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ), + texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ), + f.x ), + mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ), + texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ), + f.x ), + f.y ) + ) * ( 1.0 / 9.0 ); + #elif defined( SHADOWMAP_TYPE_VSM ) + shadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z ); + #else + shadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ); + #endif + } + return mix( 1.0, shadow, shadowIntensity ); + } + vec2 cubeToUV( vec3 v, float texelSizeY ) { + vec3 absV = abs( v ); + float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) ); + absV *= scaleToCube; + v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY ); + vec2 planar = v.xy; + float almostATexel = 1.5 * texelSizeY; + float almostOne = 1.0 - almostATexel; + if ( absV.z >= almostOne ) { + if ( v.z > 0.0 ) + planar.x = 4.0 - v.x; + } else if ( absV.x >= almostOne ) { + float signX = sign( v.x ); + planar.x = v.z * signX + 2.0 * signX; + } else if ( absV.y >= almostOne ) { + float signY = sign( v.y ); + planar.x = v.x + 2.0 * signY + 2.0; + planar.y = v.z * signY - 2.0; + } + return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 ); + } + float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) { + float shadow = 1.0; + vec3 lightToPosition = shadowCoord.xyz; + + float lightToPositionLength = length( lightToPosition ); + if ( lightToPositionLength - shadowCameraFar <= 0.0 && lightToPositionLength - shadowCameraNear >= 0.0 ) { + float dp = ( lightToPositionLength - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear ); dp += shadowBias; + vec3 bd3D = normalize( lightToPosition ); + vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) ); + #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM ) + vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y; + shadow = ( + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp ) + ) * ( 1.0 / 9.0 ); + #else + shadow = texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ); + #endif + } + return mix( 1.0, shadow, shadowIntensity ); + } +#endif`,oM=`#if NUM_SPOT_LIGHT_COORDS > 0 + uniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ]; + varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ]; +#endif +#ifdef USE_SHADOWMAP + #if NUM_DIR_LIGHT_SHADOWS > 0 + uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ]; + varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ]; + struct DirectionalLightShadow { + float shadowIntensity; + float shadowBias; + float shadowNormalBias; + float shadowRadius; + vec2 shadowMapSize; + }; + uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ]; + #endif + #if NUM_SPOT_LIGHT_SHADOWS > 0 + struct SpotLightShadow { + float shadowIntensity; + float shadowBias; + float shadowNormalBias; + float shadowRadius; + vec2 shadowMapSize; + }; + uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ]; + #endif + #if NUM_POINT_LIGHT_SHADOWS > 0 + uniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ]; + varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ]; + struct PointLightShadow { + float shadowIntensity; + float shadowBias; + float shadowNormalBias; + float shadowRadius; + vec2 shadowMapSize; + float shadowCameraNear; + float shadowCameraFar; + }; + uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ]; + #endif +#endif`,aM=`#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 ) + vec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix ); + vec4 shadowWorldPosition; +#endif +#if defined( USE_SHADOWMAP ) + #if NUM_DIR_LIGHT_SHADOWS > 0 + #pragma unroll_loop_start + for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) { + shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 ); + vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition; + } + #pragma unroll_loop_end + #endif + #if NUM_POINT_LIGHT_SHADOWS > 0 + #pragma unroll_loop_start + for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) { + shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 ); + vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition; + } + #pragma unroll_loop_end + #endif +#endif +#if NUM_SPOT_LIGHT_COORDS > 0 + #pragma unroll_loop_start + for ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) { + shadowWorldPosition = worldPosition; + #if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS ) + shadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias; + #endif + vSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition; + } + #pragma unroll_loop_end +#endif`,cM=`float getShadowMask() { + float shadow = 1.0; + #ifdef USE_SHADOWMAP + #if NUM_DIR_LIGHT_SHADOWS > 0 + DirectionalLightShadow directionalLight; + #pragma unroll_loop_start + for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) { + directionalLight = directionalLightShadows[ i ]; + shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0; + } + #pragma unroll_loop_end + #endif + #if NUM_SPOT_LIGHT_SHADOWS > 0 + SpotLightShadow spotLight; + #pragma unroll_loop_start + for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) { + spotLight = spotLightShadows[ i ]; + shadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0; + } + #pragma unroll_loop_end + #endif + #if NUM_POINT_LIGHT_SHADOWS > 0 + PointLightShadow pointLight; + #pragma unroll_loop_start + for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) { + pointLight = pointLightShadows[ i ]; + shadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0; + } + #pragma unroll_loop_end + #endif + #endif + return shadow; +}`,lM=`#ifdef USE_SKINNING + mat4 boneMatX = getBoneMatrix( skinIndex.x ); + mat4 boneMatY = getBoneMatrix( skinIndex.y ); + mat4 boneMatZ = getBoneMatrix( skinIndex.z ); + mat4 boneMatW = getBoneMatrix( skinIndex.w ); +#endif`,uM=`#ifdef USE_SKINNING + uniform mat4 bindMatrix; + uniform mat4 bindMatrixInverse; + uniform highp sampler2D boneTexture; + mat4 getBoneMatrix( const in float i ) { + int size = textureSize( boneTexture, 0 ).x; + int j = int( i ) * 4; + int x = j % size; + int y = j / size; + vec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 ); + vec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 ); + vec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 ); + vec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 ); + return mat4( v1, v2, v3, v4 ); + } +#endif`,hM=`#ifdef USE_SKINNING + vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 ); + vec4 skinned = vec4( 0.0 ); + skinned += boneMatX * skinVertex * skinWeight.x; + skinned += boneMatY * skinVertex * skinWeight.y; + skinned += boneMatZ * skinVertex * skinWeight.z; + skinned += boneMatW * skinVertex * skinWeight.w; + transformed = ( bindMatrixInverse * skinned ).xyz; +#endif`,fM=`#ifdef USE_SKINNING + mat4 skinMatrix = mat4( 0.0 ); + skinMatrix += skinWeight.x * boneMatX; + skinMatrix += skinWeight.y * boneMatY; + skinMatrix += skinWeight.z * boneMatZ; + skinMatrix += skinWeight.w * boneMatW; + skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix; + objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz; + #ifdef USE_TANGENT + objectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz; + #endif +#endif`,dM=`float specularStrength; +#ifdef USE_SPECULARMAP + vec4 texelSpecular = texture2D( specularMap, vSpecularMapUv ); + specularStrength = texelSpecular.r; +#else + specularStrength = 1.0; +#endif`,pM=`#ifdef USE_SPECULARMAP + uniform sampler2D specularMap; +#endif`,mM=`#if defined( TONE_MAPPING ) + gl_FragColor.rgb = toneMapping( gl_FragColor.rgb ); +#endif`,gM=`#ifndef saturate +#define saturate( a ) clamp( a, 0.0, 1.0 ) +#endif +uniform float toneMappingExposure; +vec3 LinearToneMapping( vec3 color ) { + return saturate( toneMappingExposure * color ); +} +vec3 ReinhardToneMapping( vec3 color ) { + color *= toneMappingExposure; + return saturate( color / ( vec3( 1.0 ) + color ) ); +} +vec3 CineonToneMapping( vec3 color ) { + color *= toneMappingExposure; + color = max( vec3( 0.0 ), color - 0.004 ); + return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) ); +} +vec3 RRTAndODTFit( vec3 v ) { + vec3 a = v * ( v + 0.0245786 ) - 0.000090537; + vec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081; + return a / b; +} +vec3 ACESFilmicToneMapping( vec3 color ) { + const mat3 ACESInputMat = mat3( + vec3( 0.59719, 0.07600, 0.02840 ), vec3( 0.35458, 0.90834, 0.13383 ), + vec3( 0.04823, 0.01566, 0.83777 ) + ); + const mat3 ACESOutputMat = mat3( + vec3( 1.60475, -0.10208, -0.00327 ), vec3( -0.53108, 1.10813, -0.07276 ), + vec3( -0.07367, -0.00605, 1.07602 ) + ); + color *= toneMappingExposure / 0.6; + color = ACESInputMat * color; + color = RRTAndODTFit( color ); + color = ACESOutputMat * color; + return saturate( color ); +} +const mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3( + vec3( 1.6605, - 0.1246, - 0.0182 ), + vec3( - 0.5876, 1.1329, - 0.1006 ), + vec3( - 0.0728, - 0.0083, 1.1187 ) +); +const mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3( + vec3( 0.6274, 0.0691, 0.0164 ), + vec3( 0.3293, 0.9195, 0.0880 ), + vec3( 0.0433, 0.0113, 0.8956 ) +); +vec3 agxDefaultContrastApprox( vec3 x ) { + vec3 x2 = x * x; + vec3 x4 = x2 * x2; + return + 15.5 * x4 * x2 + - 40.14 * x4 * x + + 31.96 * x4 + - 6.868 * x2 * x + + 0.4298 * x2 + + 0.1191 * x + - 0.00232; +} +vec3 AgXToneMapping( vec3 color ) { + const mat3 AgXInsetMatrix = mat3( + vec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ), + vec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ), + vec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 ) + ); + const mat3 AgXOutsetMatrix = mat3( + vec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ), + vec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ), + vec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 ) + ); + const float AgxMinEv = - 12.47393; const float AgxMaxEv = 4.026069; + color *= toneMappingExposure; + color = LINEAR_SRGB_TO_LINEAR_REC2020 * color; + color = AgXInsetMatrix * color; + color = max( color, 1e-10 ); color = log2( color ); + color = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv ); + color = clamp( color, 0.0, 1.0 ); + color = agxDefaultContrastApprox( color ); + color = AgXOutsetMatrix * color; + color = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) ); + color = LINEAR_REC2020_TO_LINEAR_SRGB * color; + color = clamp( color, 0.0, 1.0 ); + return color; +} +vec3 NeutralToneMapping( vec3 color ) { + const float StartCompression = 0.8 - 0.04; + const float Desaturation = 0.15; + color *= toneMappingExposure; + float x = min( color.r, min( color.g, color.b ) ); + float offset = x < 0.08 ? x - 6.25 * x * x : 0.04; + color -= offset; + float peak = max( color.r, max( color.g, color.b ) ); + if ( peak < StartCompression ) return color; + float d = 1. - StartCompression; + float newPeak = 1. - d * d / ( peak + d - StartCompression ); + color *= newPeak / peak; + float g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. ); + return mix( color, vec3( newPeak ), g ); +} +vec3 CustomToneMapping( vec3 color ) { return color; }`,xM=`#ifdef USE_TRANSMISSION + material.transmission = transmission; + material.transmissionAlpha = 1.0; + material.thickness = thickness; + material.attenuationDistance = attenuationDistance; + material.attenuationColor = attenuationColor; + #ifdef USE_TRANSMISSIONMAP + material.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r; + #endif + #ifdef USE_THICKNESSMAP + material.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g; + #endif + vec3 pos = vWorldPosition; + vec3 v = normalize( cameraPosition - pos ); + vec3 n = inverseTransformDirection( normal, viewMatrix ); + vec4 transmitted = getIBLVolumeRefraction( + n, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90, + pos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness, + material.attenuationColor, material.attenuationDistance ); + material.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission ); + totalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission ); +#endif`,vM=`#ifdef USE_TRANSMISSION + uniform float transmission; + uniform float thickness; + uniform float attenuationDistance; + uniform vec3 attenuationColor; + #ifdef USE_TRANSMISSIONMAP + uniform sampler2D transmissionMap; + #endif + #ifdef USE_THICKNESSMAP + uniform sampler2D thicknessMap; + #endif + uniform vec2 transmissionSamplerSize; + uniform sampler2D transmissionSamplerMap; + uniform mat4 modelMatrix; + uniform mat4 projectionMatrix; + varying vec3 vWorldPosition; + float w0( float a ) { + return ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 ); + } + float w1( float a ) { + return ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 ); + } + float w2( float a ){ + return ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 ); + } + float w3( float a ) { + return ( 1.0 / 6.0 ) * ( a * a * a ); + } + float g0( float a ) { + return w0( a ) + w1( a ); + } + float g1( float a ) { + return w2( a ) + w3( a ); + } + float h0( float a ) { + return - 1.0 + w1( a ) / ( w0( a ) + w1( a ) ); + } + float h1( float a ) { + return 1.0 + w3( a ) / ( w2( a ) + w3( a ) ); + } + vec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) { + uv = uv * texelSize.zw + 0.5; + vec2 iuv = floor( uv ); + vec2 fuv = fract( uv ); + float g0x = g0( fuv.x ); + float g1x = g1( fuv.x ); + float h0x = h0( fuv.x ); + float h1x = h1( fuv.x ); + float h0y = h0( fuv.y ); + float h1y = h1( fuv.y ); + vec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy; + vec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy; + vec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy; + vec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy; + return g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) + + g1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) ); + } + vec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) { + vec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) ); + vec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) ); + vec2 fLodSizeInv = 1.0 / fLodSize; + vec2 cLodSizeInv = 1.0 / cLodSize; + vec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) ); + vec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) ); + return mix( fSample, cSample, fract( lod ) ); + } + vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) { + vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior ); + vec3 modelScale; + modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) ); + modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) ); + modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) ); + return normalize( refractionVector ) * thickness * modelScale; + } + float applyIorToRoughness( const in float roughness, const in float ior ) { + return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 ); + } + vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) { + float lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior ); + return textureBicubic( transmissionSamplerMap, fragCoord.xy, lod ); + } + vec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) { + if ( isinf( attenuationDistance ) ) { + return vec3( 1.0 ); + } else { + vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance; + vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); return transmittance; + } + } + vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor, + const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix, + const in mat4 viewMatrix, const in mat4 projMatrix, const in float dispersion, const in float ior, const in float thickness, + const in vec3 attenuationColor, const in float attenuationDistance ) { + vec4 transmittedLight; + vec3 transmittance; + #ifdef USE_DISPERSION + float halfSpread = ( ior - 1.0 ) * 0.025 * dispersion; + vec3 iors = vec3( ior - halfSpread, ior, ior + halfSpread ); + for ( int i = 0; i < 3; i ++ ) { + vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, iors[ i ], modelMatrix ); + vec3 refractedRayExit = position + transmissionRay; + vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 ); + vec2 refractionCoords = ndcPos.xy / ndcPos.w; + refractionCoords += 1.0; + refractionCoords /= 2.0; + vec4 transmissionSample = getTransmissionSample( refractionCoords, roughness, iors[ i ] ); + transmittedLight[ i ] = transmissionSample[ i ]; + transmittedLight.a += transmissionSample.a; + transmittance[ i ] = diffuseColor[ i ] * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance )[ i ]; + } + transmittedLight.a /= 3.0; + #else + vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix ); + vec3 refractedRayExit = position + transmissionRay; + vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 ); + vec2 refractionCoords = ndcPos.xy / ndcPos.w; + refractionCoords += 1.0; + refractionCoords /= 2.0; + transmittedLight = getTransmissionSample( refractionCoords, roughness, ior ); + transmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance ); + #endif + vec3 attenuatedColor = transmittance * transmittedLight.rgb; + vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness ); + float transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0; + return vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor ); + } +#endif`,_M=`#if defined( USE_UV ) || defined( USE_ANISOTROPY ) + varying vec2 vUv; +#endif +#ifdef USE_MAP + varying vec2 vMapUv; +#endif +#ifdef USE_ALPHAMAP + varying vec2 vAlphaMapUv; +#endif +#ifdef USE_LIGHTMAP + varying vec2 vLightMapUv; +#endif +#ifdef USE_AOMAP + varying vec2 vAoMapUv; +#endif +#ifdef USE_BUMPMAP + varying vec2 vBumpMapUv; +#endif +#ifdef USE_NORMALMAP + varying vec2 vNormalMapUv; +#endif +#ifdef USE_EMISSIVEMAP + varying vec2 vEmissiveMapUv; +#endif +#ifdef USE_METALNESSMAP + varying vec2 vMetalnessMapUv; +#endif +#ifdef USE_ROUGHNESSMAP + varying vec2 vRoughnessMapUv; +#endif +#ifdef USE_ANISOTROPYMAP + varying vec2 vAnisotropyMapUv; +#endif +#ifdef USE_CLEARCOATMAP + varying vec2 vClearcoatMapUv; +#endif +#ifdef USE_CLEARCOAT_NORMALMAP + varying vec2 vClearcoatNormalMapUv; +#endif +#ifdef USE_CLEARCOAT_ROUGHNESSMAP + varying vec2 vClearcoatRoughnessMapUv; +#endif +#ifdef USE_IRIDESCENCEMAP + varying vec2 vIridescenceMapUv; +#endif +#ifdef USE_IRIDESCENCE_THICKNESSMAP + varying vec2 vIridescenceThicknessMapUv; +#endif +#ifdef USE_SHEEN_COLORMAP + varying vec2 vSheenColorMapUv; +#endif +#ifdef USE_SHEEN_ROUGHNESSMAP + varying vec2 vSheenRoughnessMapUv; +#endif +#ifdef USE_SPECULARMAP + varying vec2 vSpecularMapUv; +#endif +#ifdef USE_SPECULAR_COLORMAP + varying vec2 vSpecularColorMapUv; +#endif +#ifdef USE_SPECULAR_INTENSITYMAP + varying vec2 vSpecularIntensityMapUv; +#endif +#ifdef USE_TRANSMISSIONMAP + uniform mat3 transmissionMapTransform; + varying vec2 vTransmissionMapUv; +#endif +#ifdef USE_THICKNESSMAP + uniform mat3 thicknessMapTransform; + varying vec2 vThicknessMapUv; +#endif`,yM=`#if defined( USE_UV ) || defined( USE_ANISOTROPY ) + varying vec2 vUv; +#endif +#ifdef USE_MAP + uniform mat3 mapTransform; + varying vec2 vMapUv; +#endif +#ifdef USE_ALPHAMAP + uniform mat3 alphaMapTransform; + varying vec2 vAlphaMapUv; +#endif +#ifdef USE_LIGHTMAP + uniform mat3 lightMapTransform; + varying vec2 vLightMapUv; +#endif +#ifdef USE_AOMAP + uniform mat3 aoMapTransform; + varying vec2 vAoMapUv; +#endif +#ifdef USE_BUMPMAP + uniform mat3 bumpMapTransform; + varying vec2 vBumpMapUv; +#endif +#ifdef USE_NORMALMAP + uniform mat3 normalMapTransform; + varying vec2 vNormalMapUv; +#endif +#ifdef USE_DISPLACEMENTMAP + uniform mat3 displacementMapTransform; + varying vec2 vDisplacementMapUv; +#endif +#ifdef USE_EMISSIVEMAP + uniform mat3 emissiveMapTransform; + varying vec2 vEmissiveMapUv; +#endif +#ifdef USE_METALNESSMAP + uniform mat3 metalnessMapTransform; + varying vec2 vMetalnessMapUv; +#endif +#ifdef USE_ROUGHNESSMAP + uniform mat3 roughnessMapTransform; + varying vec2 vRoughnessMapUv; +#endif +#ifdef USE_ANISOTROPYMAP + uniform mat3 anisotropyMapTransform; + varying vec2 vAnisotropyMapUv; +#endif +#ifdef USE_CLEARCOATMAP + uniform mat3 clearcoatMapTransform; + varying vec2 vClearcoatMapUv; +#endif +#ifdef USE_CLEARCOAT_NORMALMAP + uniform mat3 clearcoatNormalMapTransform; + varying vec2 vClearcoatNormalMapUv; +#endif +#ifdef USE_CLEARCOAT_ROUGHNESSMAP + uniform mat3 clearcoatRoughnessMapTransform; + varying vec2 vClearcoatRoughnessMapUv; +#endif +#ifdef USE_SHEEN_COLORMAP + uniform mat3 sheenColorMapTransform; + varying vec2 vSheenColorMapUv; +#endif +#ifdef USE_SHEEN_ROUGHNESSMAP + uniform mat3 sheenRoughnessMapTransform; + varying vec2 vSheenRoughnessMapUv; +#endif +#ifdef USE_IRIDESCENCEMAP + uniform mat3 iridescenceMapTransform; + varying vec2 vIridescenceMapUv; +#endif +#ifdef USE_IRIDESCENCE_THICKNESSMAP + uniform mat3 iridescenceThicknessMapTransform; + varying vec2 vIridescenceThicknessMapUv; +#endif +#ifdef USE_SPECULARMAP + uniform mat3 specularMapTransform; + varying vec2 vSpecularMapUv; +#endif +#ifdef USE_SPECULAR_COLORMAP + uniform mat3 specularColorMapTransform; + varying vec2 vSpecularColorMapUv; +#endif +#ifdef USE_SPECULAR_INTENSITYMAP + uniform mat3 specularIntensityMapTransform; + varying vec2 vSpecularIntensityMapUv; +#endif +#ifdef USE_TRANSMISSIONMAP + uniform mat3 transmissionMapTransform; + varying vec2 vTransmissionMapUv; +#endif +#ifdef USE_THICKNESSMAP + uniform mat3 thicknessMapTransform; + varying vec2 vThicknessMapUv; +#endif`,bM=`#if defined( USE_UV ) || defined( USE_ANISOTROPY ) + vUv = vec3( uv, 1 ).xy; +#endif +#ifdef USE_MAP + vMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy; +#endif +#ifdef USE_ALPHAMAP + vAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_LIGHTMAP + vLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_AOMAP + vAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_BUMPMAP + vBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_NORMALMAP + vNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_DISPLACEMENTMAP + vDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_EMISSIVEMAP + vEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_METALNESSMAP + vMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_ROUGHNESSMAP + vRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_ANISOTROPYMAP + vAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_CLEARCOATMAP + vClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_CLEARCOAT_NORMALMAP + vClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_CLEARCOAT_ROUGHNESSMAP + vClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_IRIDESCENCEMAP + vIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_IRIDESCENCE_THICKNESSMAP + vIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_SHEEN_COLORMAP + vSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_SHEEN_ROUGHNESSMAP + vSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_SPECULARMAP + vSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_SPECULAR_COLORMAP + vSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_SPECULAR_INTENSITYMAP + vSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_TRANSMISSIONMAP + vTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_THICKNESSMAP + vThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy; +#endif`,SM=`#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0 + vec4 worldPosition = vec4( transformed, 1.0 ); + #ifdef USE_BATCHING + worldPosition = batchingMatrix * worldPosition; + #endif + #ifdef USE_INSTANCING + worldPosition = instanceMatrix * worldPosition; + #endif + worldPosition = modelMatrix * worldPosition; +#endif`,MM=`varying vec2 vUv; +uniform mat3 uvTransform; +void main() { + vUv = ( uvTransform * vec3( uv, 1 ) ).xy; + gl_Position = vec4( position.xy, 1.0, 1.0 ); +}`,TM=`uniform sampler2D t2D; +uniform float backgroundIntensity; +varying vec2 vUv; +void main() { + vec4 texColor = texture2D( t2D, vUv ); + #ifdef DECODE_VIDEO_TEXTURE + texColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w ); + #endif + texColor.rgb *= backgroundIntensity; + gl_FragColor = texColor; + #include + #include +}`,wM=`varying vec3 vWorldDirection; +#include +void main() { + vWorldDirection = transformDirection( position, modelMatrix ); + #include + #include + gl_Position.z = gl_Position.w; +}`,AM=`#ifdef ENVMAP_TYPE_CUBE + uniform samplerCube envMap; +#elif defined( ENVMAP_TYPE_CUBE_UV ) + uniform sampler2D envMap; +#endif +uniform float flipEnvMap; +uniform float backgroundBlurriness; +uniform float backgroundIntensity; +uniform mat3 backgroundRotation; +varying vec3 vWorldDirection; +#include +void main() { + #ifdef ENVMAP_TYPE_CUBE + vec4 texColor = textureCube( envMap, backgroundRotation * vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) ); + #elif defined( ENVMAP_TYPE_CUBE_UV ) + vec4 texColor = textureCubeUV( envMap, backgroundRotation * vWorldDirection, backgroundBlurriness ); + #else + vec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 ); + #endif + texColor.rgb *= backgroundIntensity; + gl_FragColor = texColor; + #include + #include +}`,EM=`varying vec3 vWorldDirection; +#include +void main() { + vWorldDirection = transformDirection( position, modelMatrix ); + #include + #include + gl_Position.z = gl_Position.w; +}`,RM=`uniform samplerCube tCube; +uniform float tFlip; +uniform float opacity; +varying vec3 vWorldDirection; +void main() { + vec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) ); + gl_FragColor = texColor; + gl_FragColor.a *= opacity; + #include + #include +}`,CM=`#include +#include +#include +#include +#include +#include +#include +#include +varying vec2 vHighPrecisionZW; +void main() { + #include + #include + #include + #include + #ifdef USE_DISPLACEMENTMAP + #include + #include + #include + #endif + #include + #include + #include + #include + #include + #include + #include + vHighPrecisionZW = gl_Position.zw; +}`,IM=`#if DEPTH_PACKING == 3200 + uniform float opacity; +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +varying vec2 vHighPrecisionZW; +void main() { + vec4 diffuseColor = vec4( 1.0 ); + #include + #if DEPTH_PACKING == 3200 + diffuseColor.a = opacity; + #endif + #include + #include + #include + #include + #include + #ifdef USE_REVERSED_DEPTH_BUFFER + float fragCoordZ = vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ]; + #else + float fragCoordZ = 0.5 * vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ] + 0.5; + #endif + #if DEPTH_PACKING == 3200 + gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity ); + #elif DEPTH_PACKING == 3201 + gl_FragColor = packDepthToRGBA( fragCoordZ ); + #elif DEPTH_PACKING == 3202 + gl_FragColor = vec4( packDepthToRGB( fragCoordZ ), 1.0 ); + #elif DEPTH_PACKING == 3203 + gl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 ); + #endif +}`,PM=`#define DISTANCE +varying vec3 vWorldPosition; +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #ifdef USE_DISPLACEMENTMAP + #include + #include + #include + #endif + #include + #include + #include + #include + #include + #include + #include + vWorldPosition = worldPosition.xyz; +}`,DM=`#define DISTANCE +uniform vec3 referencePosition; +uniform float nearDistance; +uniform float farDistance; +varying vec3 vWorldPosition; +#include +#include +#include +#include +#include +#include +#include +#include +void main () { + vec4 diffuseColor = vec4( 1.0 ); + #include + #include + #include + #include + #include + float dist = length( vWorldPosition - referencePosition ); + dist = ( dist - nearDistance ) / ( farDistance - nearDistance ); + dist = saturate( dist ); + gl_FragColor = packDepthToRGBA( dist ); +}`,FM=`varying vec3 vWorldDirection; +#include +void main() { + vWorldDirection = transformDirection( position, modelMatrix ); + #include + #include +}`,LM=`uniform sampler2D tEquirect; +varying vec3 vWorldDirection; +#include +void main() { + vec3 direction = normalize( vWorldDirection ); + vec2 sampleUV = equirectUv( direction ); + gl_FragColor = texture2D( tEquirect, sampleUV ); + #include + #include +}`,NM=`uniform float scale; +attribute float lineDistance; +varying float vLineDistance; +#include +#include +#include +#include +#include +#include +#include +void main() { + vLineDistance = scale * lineDistance; + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include +}`,UM=`uniform vec3 diffuse; +uniform float opacity; +uniform float dashSize; +uniform float totalSize; +varying float vLineDistance; +#include +#include +#include +#include +#include +#include +#include +void main() { + vec4 diffuseColor = vec4( diffuse, opacity ); + #include + if ( mod( vLineDistance, totalSize ) > dashSize ) { + discard; + } + vec3 outgoingLight = vec3( 0.0 ); + #include + #include + #include + outgoingLight = diffuseColor.rgb; + #include + #include + #include + #include + #include +}`,BM=`#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #include + #if defined ( USE_ENVMAP ) || defined ( USE_SKINNING ) + #include + #include + #include + #include + #include + #endif + #include + #include + #include + #include + #include + #include + #include + #include + #include +}`,OM=`uniform vec3 diffuse; +uniform float opacity; +#ifndef FLAT_SHADED + varying vec3 vNormal; +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + vec4 diffuseColor = vec4( diffuse, opacity ); + #include + #include + #include + #include + #include + #include + #include + #include + ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); + #ifdef USE_LIGHTMAP + vec4 lightMapTexel = texture2D( lightMap, vLightMapUv ); + reflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI; + #else + reflectedLight.indirectDiffuse += vec3( 1.0 ); + #endif + #include + reflectedLight.indirectDiffuse *= diffuseColor.rgb; + vec3 outgoingLight = reflectedLight.indirectDiffuse; + #include + #include + #include + #include + #include + #include + #include +}`,zM=`#define LAMBERT +varying vec3 vViewPosition; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vViewPosition = - mvPosition.xyz; + #include + #include + #include + #include +}`,kM=`#define LAMBERT +uniform vec3 diffuse; +uniform vec3 emissive; +uniform float opacity; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + vec4 diffuseColor = vec4( diffuse, opacity ); + #include + ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); + vec3 totalEmissiveRadiance = emissive; + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance; + #include + #include + #include + #include + #include + #include + #include +}`,VM=`#define MATCAP +varying vec3 vViewPosition; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vViewPosition = - mvPosition.xyz; +}`,HM=`#define MATCAP +uniform vec3 diffuse; +uniform float opacity; +uniform sampler2D matcap; +varying vec3 vViewPosition; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + vec4 diffuseColor = vec4( diffuse, opacity ); + #include + #include + #include + #include + #include + #include + #include + #include + #include + vec3 viewDir = normalize( vViewPosition ); + vec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) ); + vec3 y = cross( viewDir, x ); + vec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5; + #ifdef USE_MATCAP + vec4 matcapColor = texture2D( matcap, uv ); + #else + vec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 ); + #endif + vec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb; + #include + #include + #include + #include + #include + #include +}`,GM=`#define NORMAL +#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE ) + varying vec3 vViewPosition; +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include +#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE ) + vViewPosition = - mvPosition.xyz; +#endif +}`,WM=`#define NORMAL +uniform float opacity; +#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE ) + varying vec3 vViewPosition; +#endif +#include +#include +#include +#include +#include +#include +#include +void main() { + vec4 diffuseColor = vec4( 0.0, 0.0, 0.0, opacity ); + #include + #include + #include + #include + gl_FragColor = vec4( packNormalToRGB( normal ), diffuseColor.a ); + #ifdef OPAQUE + gl_FragColor.a = 1.0; + #endif +}`,XM=`#define PHONG +varying vec3 vViewPosition; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vViewPosition = - mvPosition.xyz; + #include + #include + #include + #include +}`,qM=`#define PHONG +uniform vec3 diffuse; +uniform vec3 emissive; +uniform vec3 specular; +uniform float shininess; +uniform float opacity; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + vec4 diffuseColor = vec4( diffuse, opacity ); + #include + ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); + vec3 totalEmissiveRadiance = emissive; + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance; + #include + #include + #include + #include + #include + #include + #include +}`,YM=`#define STANDARD +varying vec3 vViewPosition; +#ifdef USE_TRANSMISSION + varying vec3 vWorldPosition; +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vViewPosition = - mvPosition.xyz; + #include + #include + #include +#ifdef USE_TRANSMISSION + vWorldPosition = worldPosition.xyz; +#endif +}`,$M=`#define STANDARD +#ifdef PHYSICAL + #define IOR + #define USE_SPECULAR +#endif +uniform vec3 diffuse; +uniform vec3 emissive; +uniform float roughness; +uniform float metalness; +uniform float opacity; +#ifdef IOR + uniform float ior; +#endif +#ifdef USE_SPECULAR + uniform float specularIntensity; + uniform vec3 specularColor; + #ifdef USE_SPECULAR_COLORMAP + uniform sampler2D specularColorMap; + #endif + #ifdef USE_SPECULAR_INTENSITYMAP + uniform sampler2D specularIntensityMap; + #endif +#endif +#ifdef USE_CLEARCOAT + uniform float clearcoat; + uniform float clearcoatRoughness; +#endif +#ifdef USE_DISPERSION + uniform float dispersion; +#endif +#ifdef USE_IRIDESCENCE + uniform float iridescence; + uniform float iridescenceIOR; + uniform float iridescenceThicknessMinimum; + uniform float iridescenceThicknessMaximum; +#endif +#ifdef USE_SHEEN + uniform vec3 sheenColor; + uniform float sheenRoughness; + #ifdef USE_SHEEN_COLORMAP + uniform sampler2D sheenColorMap; + #endif + #ifdef USE_SHEEN_ROUGHNESSMAP + uniform sampler2D sheenRoughnessMap; + #endif +#endif +#ifdef USE_ANISOTROPY + uniform vec2 anisotropyVector; + #ifdef USE_ANISOTROPYMAP + uniform sampler2D anisotropyMap; + #endif +#endif +varying vec3 vViewPosition; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + vec4 diffuseColor = vec4( diffuse, opacity ); + #include + ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); + vec3 totalEmissiveRadiance = emissive; + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse; + vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular; + #include + vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance; + #ifdef USE_SHEEN + float sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor ); + outgoingLight = outgoingLight * sheenEnergyComp + sheenSpecularDirect + sheenSpecularIndirect; + #endif + #ifdef USE_CLEARCOAT + float dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) ); + vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc ); + outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat; + #endif + #include + #include + #include + #include + #include + #include +}`,ZM=`#define TOON +varying vec3 vViewPosition; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vViewPosition = - mvPosition.xyz; + #include + #include + #include +}`,JM=`#define TOON +uniform vec3 diffuse; +uniform vec3 emissive; +uniform float opacity; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + vec4 diffuseColor = vec4( diffuse, opacity ); + #include + ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); + vec3 totalEmissiveRadiance = emissive; + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance; + #include + #include + #include + #include + #include + #include +}`,KM=`uniform float size; +uniform float scale; +#include +#include +#include +#include +#include +#include +#ifdef USE_POINTS_UV + varying vec2 vUv; + uniform mat3 uvTransform; +#endif +void main() { + #ifdef USE_POINTS_UV + vUv = ( uvTransform * vec3( uv, 1 ) ).xy; + #endif + #include + #include + #include + #include + #include + #include + gl_PointSize = size; + #ifdef USE_SIZEATTENUATION + bool isPerspective = isPerspectiveMatrix( projectionMatrix ); + if ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z ); + #endif + #include + #include + #include + #include +}`,QM=`uniform vec3 diffuse; +uniform float opacity; +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + vec4 diffuseColor = vec4( diffuse, opacity ); + #include + vec3 outgoingLight = vec3( 0.0 ); + #include + #include + #include + #include + #include + outgoingLight = diffuseColor.rgb; + #include + #include + #include + #include + #include +}`,jM=`#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include +}`,tT=`uniform vec3 color; +uniform float opacity; +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + gl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) ); + #include + #include + #include +}`,eT=`uniform float rotation; +uniform vec2 center; +#include +#include +#include +#include +#include +void main() { + #include + vec4 mvPosition = modelViewMatrix[ 3 ]; + vec2 scale = vec2( length( modelMatrix[ 0 ].xyz ), length( modelMatrix[ 1 ].xyz ) ); + #ifndef USE_SIZEATTENUATION + bool isPerspective = isPerspectiveMatrix( projectionMatrix ); + if ( isPerspective ) scale *= - mvPosition.z; + #endif + vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale; + vec2 rotatedPosition; + rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y; + rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y; + mvPosition.xy += rotatedPosition; + gl_Position = projectionMatrix * mvPosition; + #include + #include + #include +}`,nT=`uniform vec3 diffuse; +uniform float opacity; +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + vec4 diffuseColor = vec4( diffuse, opacity ); + #include + vec3 outgoingLight = vec3( 0.0 ); + #include + #include + #include + #include + #include + outgoingLight = diffuseColor.rgb; + #include + #include + #include + #include +}`,jt={alphahash_fragment:Tb,alphahash_pars_fragment:wb,alphamap_fragment:Ab,alphamap_pars_fragment:Eb,alphatest_fragment:Rb,alphatest_pars_fragment:Cb,aomap_fragment:Ib,aomap_pars_fragment:Pb,batching_pars_vertex:Db,batching_vertex:Fb,begin_vertex:Lb,beginnormal_vertex:Nb,bsdfs:Ub,iridescence_fragment:Bb,bumpmap_pars_fragment:Ob,clipping_planes_fragment:zb,clipping_planes_pars_fragment:kb,clipping_planes_pars_vertex:Vb,clipping_planes_vertex:Hb,color_fragment:Gb,color_pars_fragment:Wb,color_pars_vertex:Xb,color_vertex:qb,common:Yb,cube_uv_reflection_fragment:$b,defaultnormal_vertex:Zb,displacementmap_pars_vertex:Jb,displacementmap_vertex:Kb,emissivemap_fragment:Qb,emissivemap_pars_fragment:jb,colorspace_fragment:tS,colorspace_pars_fragment:eS,envmap_fragment:nS,envmap_common_pars_fragment:iS,envmap_pars_fragment:rS,envmap_pars_vertex:sS,envmap_physical_pars_fragment:gS,envmap_vertex:oS,fog_vertex:aS,fog_pars_vertex:cS,fog_fragment:lS,fog_pars_fragment:uS,gradientmap_pars_fragment:hS,lightmap_pars_fragment:fS,lights_lambert_fragment:dS,lights_lambert_pars_fragment:pS,lights_pars_begin:mS,lights_toon_fragment:xS,lights_toon_pars_fragment:vS,lights_phong_fragment:_S,lights_phong_pars_fragment:yS,lights_physical_fragment:bS,lights_physical_pars_fragment:SS,lights_fragment_begin:MS,lights_fragment_maps:TS,lights_fragment_end:wS,logdepthbuf_fragment:AS,logdepthbuf_pars_fragment:ES,logdepthbuf_pars_vertex:RS,logdepthbuf_vertex:CS,map_fragment:IS,map_pars_fragment:PS,map_particle_fragment:DS,map_particle_pars_fragment:FS,metalnessmap_fragment:LS,metalnessmap_pars_fragment:NS,morphinstance_vertex:US,morphcolor_vertex:BS,morphnormal_vertex:OS,morphtarget_pars_vertex:zS,morphtarget_vertex:kS,normal_fragment_begin:VS,normal_fragment_maps:HS,normal_pars_fragment:GS,normal_pars_vertex:WS,normal_vertex:XS,normalmap_pars_fragment:qS,clearcoat_normal_fragment_begin:YS,clearcoat_normal_fragment_maps:$S,clearcoat_pars_fragment:ZS,iridescence_pars_fragment:JS,opaque_fragment:KS,packing:QS,premultiplied_alpha_fragment:jS,project_vertex:tM,dithering_fragment:eM,dithering_pars_fragment:nM,roughnessmap_fragment:iM,roughnessmap_pars_fragment:rM,shadowmap_pars_fragment:sM,shadowmap_pars_vertex:oM,shadowmap_vertex:aM,shadowmask_pars_fragment:cM,skinbase_vertex:lM,skinning_pars_vertex:uM,skinning_vertex:hM,skinnormal_vertex:fM,specularmap_fragment:dM,specularmap_pars_fragment:pM,tonemapping_fragment:mM,tonemapping_pars_fragment:gM,transmission_fragment:xM,transmission_pars_fragment:vM,uv_pars_fragment:_M,uv_pars_vertex:yM,uv_vertex:bM,worldpos_vertex:SM,background_vert:MM,background_frag:TM,backgroundCube_vert:wM,backgroundCube_frag:AM,cube_vert:EM,cube_frag:RM,depth_vert:CM,depth_frag:IM,distanceRGBA_vert:PM,distanceRGBA_frag:DM,equirect_vert:FM,equirect_frag:LM,linedashed_vert:NM,linedashed_frag:UM,meshbasic_vert:BM,meshbasic_frag:OM,meshlambert_vert:zM,meshlambert_frag:kM,meshmatcap_vert:VM,meshmatcap_frag:HM,meshnormal_vert:GM,meshnormal_frag:WM,meshphong_vert:XM,meshphong_frag:qM,meshphysical_vert:YM,meshphysical_frag:$M,meshtoon_vert:ZM,meshtoon_frag:JM,points_vert:KM,points_frag:QM,shadow_vert:jM,shadow_frag:tT,sprite_vert:eT,sprite_frag:nT},mt={common:{diffuse:{value:new ft(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new Xt},alphaMap:{value:null},alphaMapTransform:{value:new Xt},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new Xt}},envmap:{envMap:{value:null},envMapRotation:{value:new Xt},flipEnvMap:{value:-1},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new Xt}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new Xt}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new Xt},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new Xt},normalScale:{value:new q(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new Xt},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new Xt}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new Xt}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new Xt}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new ft(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMap:{value:[]},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotShadowMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMap:{value:[]},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null}},points:{diffuse:{value:new ft(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new Xt},alphaTest:{value:0},uvTransform:{value:new Xt}},sprite:{diffuse:{value:new ft(16777215)},opacity:{value:1},center:{value:new q(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new Xt},alphaMap:{value:null},alphaMapTransform:{value:new Xt},alphaTest:{value:0}}},ci={basic:{uniforms:cn([mt.common,mt.specularmap,mt.envmap,mt.aomap,mt.lightmap,mt.fog]),vertexShader:jt.meshbasic_vert,fragmentShader:jt.meshbasic_frag},lambert:{uniforms:cn([mt.common,mt.specularmap,mt.envmap,mt.aomap,mt.lightmap,mt.emissivemap,mt.bumpmap,mt.normalmap,mt.displacementmap,mt.fog,mt.lights,{emissive:{value:new ft(0)}}]),vertexShader:jt.meshlambert_vert,fragmentShader:jt.meshlambert_frag},phong:{uniforms:cn([mt.common,mt.specularmap,mt.envmap,mt.aomap,mt.lightmap,mt.emissivemap,mt.bumpmap,mt.normalmap,mt.displacementmap,mt.fog,mt.lights,{emissive:{value:new ft(0)},specular:{value:new ft(1118481)},shininess:{value:30}}]),vertexShader:jt.meshphong_vert,fragmentShader:jt.meshphong_frag},standard:{uniforms:cn([mt.common,mt.envmap,mt.aomap,mt.lightmap,mt.emissivemap,mt.bumpmap,mt.normalmap,mt.displacementmap,mt.roughnessmap,mt.metalnessmap,mt.fog,mt.lights,{emissive:{value:new ft(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:jt.meshphysical_vert,fragmentShader:jt.meshphysical_frag},toon:{uniforms:cn([mt.common,mt.aomap,mt.lightmap,mt.emissivemap,mt.bumpmap,mt.normalmap,mt.displacementmap,mt.gradientmap,mt.fog,mt.lights,{emissive:{value:new ft(0)}}]),vertexShader:jt.meshtoon_vert,fragmentShader:jt.meshtoon_frag},matcap:{uniforms:cn([mt.common,mt.bumpmap,mt.normalmap,mt.displacementmap,mt.fog,{matcap:{value:null}}]),vertexShader:jt.meshmatcap_vert,fragmentShader:jt.meshmatcap_frag},points:{uniforms:cn([mt.points,mt.fog]),vertexShader:jt.points_vert,fragmentShader:jt.points_frag},dashed:{uniforms:cn([mt.common,mt.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:jt.linedashed_vert,fragmentShader:jt.linedashed_frag},depth:{uniforms:cn([mt.common,mt.displacementmap]),vertexShader:jt.depth_vert,fragmentShader:jt.depth_frag},normal:{uniforms:cn([mt.common,mt.bumpmap,mt.normalmap,mt.displacementmap,{opacity:{value:1}}]),vertexShader:jt.meshnormal_vert,fragmentShader:jt.meshnormal_frag},sprite:{uniforms:cn([mt.sprite,mt.fog]),vertexShader:jt.sprite_vert,fragmentShader:jt.sprite_frag},background:{uniforms:{uvTransform:{value:new Xt},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:jt.background_vert,fragmentShader:jt.background_frag},backgroundCube:{uniforms:{envMap:{value:null},flipEnvMap:{value:-1},backgroundBlurriness:{value:0},backgroundIntensity:{value:1},backgroundRotation:{value:new Xt}},vertexShader:jt.backgroundCube_vert,fragmentShader:jt.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:jt.cube_vert,fragmentShader:jt.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:jt.equirect_vert,fragmentShader:jt.equirect_frag},distanceRGBA:{uniforms:cn([mt.common,mt.displacementmap,{referencePosition:{value:new R},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:jt.distanceRGBA_vert,fragmentShader:jt.distanceRGBA_frag},shadow:{uniforms:cn([mt.lights,mt.fog,{color:{value:new ft(0)},opacity:{value:1}}]),vertexShader:jt.shadow_vert,fragmentShader:jt.shadow_frag}};ci.physical={uniforms:cn([ci.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new Xt},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new Xt},clearcoatNormalScale:{value:new q(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new Xt},dispersion:{value:0},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new Xt},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new Xt},sheen:{value:0},sheenColor:{value:new ft(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new Xt},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new Xt},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new Xt},transmissionSamplerSize:{value:new q},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new Xt},attenuationDistance:{value:0},attenuationColor:{value:new ft(0)},specularColor:{value:new ft(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new Xt},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new Xt},anisotropyVector:{value:new q},anisotropyMap:{value:null},anisotropyMapTransform:{value:new Xt}}]),vertexShader:jt.meshphysical_vert,fragmentShader:jt.meshphysical_frag};var wu={r:0,b:0,g:0},Nr=new In,iT=new gt;function rT(r,t,e,n,i,s,o){let a=new ft(0),c=s===!0?0:1,l,f,h=null,u=0,d=null;function g(_){let y=_.isScene===!0?_.background:null;return y&&y.isTexture&&(y=(_.backgroundBlurriness>0?e:t).get(y)),y}function x(_){let y=!1,b=g(_);b===null?m(a,c):b&&b.isColor&&(m(b,1),y=!0);let T=r.xr.getEnvironmentBlendMode();T==="additive"?n.buffers.color.setClear(0,0,0,1,o):T==="alpha-blend"&&n.buffers.color.setClear(0,0,0,0,o),(r.autoClear||y)&&(n.buffers.depth.setTest(!0),n.buffers.depth.setMask(!0),n.buffers.color.setMask(!0),r.clear(r.autoClearColor,r.autoClearDepth,r.autoClearStencil))}function p(_,y){let b=g(y);b&&(b.isCubeTexture||b.mapping===Ns)?(f===void 0&&(f=new Me(new Sr(1,1,1),new Ue({name:"BackgroundCubeMaterial",uniforms:Lr(ci.backgroundCube.uniforms),vertexShader:ci.backgroundCube.vertexShader,fragmentShader:ci.backgroundCube.fragmentShader,side:He,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),f.geometry.deleteAttribute("normal"),f.geometry.deleteAttribute("uv"),f.onBeforeRender=function(T,w,E){this.matrixWorld.copyPosition(E.matrixWorld)},Object.defineProperty(f.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),i.update(f)),Nr.copy(y.backgroundRotation),Nr.x*=-1,Nr.y*=-1,Nr.z*=-1,b.isCubeTexture&&b.isRenderTargetTexture===!1&&(Nr.y*=-1,Nr.z*=-1),f.material.uniforms.envMap.value=b,f.material.uniforms.flipEnvMap.value=b.isCubeTexture&&b.isRenderTargetTexture===!1?-1:1,f.material.uniforms.backgroundBlurriness.value=y.backgroundBlurriness,f.material.uniforms.backgroundIntensity.value=y.backgroundIntensity,f.material.uniforms.backgroundRotation.value.setFromMatrix4(iT.makeRotationFromEuler(Nr)),f.material.toneMapped=ie.getTransfer(b.colorSpace)!==me,(h!==b||u!==b.version||d!==r.toneMapping)&&(f.material.needsUpdate=!0,h=b,u=b.version,d=r.toneMapping),f.layers.enableAll(),_.unshift(f,f.geometry,f.material,0,0,null)):b&&b.isTexture&&(l===void 0&&(l=new Me(new Ps(2,2),new Ue({name:"BackgroundMaterial",uniforms:Lr(ci.background.uniforms),vertexShader:ci.background.vertexShader,fragmentShader:ci.background.fragmentShader,side:yn,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),l.geometry.deleteAttribute("normal"),Object.defineProperty(l.material,"map",{get:function(){return this.uniforms.t2D.value}}),i.update(l)),l.material.uniforms.t2D.value=b,l.material.uniforms.backgroundIntensity.value=y.backgroundIntensity,l.material.toneMapped=ie.getTransfer(b.colorSpace)!==me,b.matrixAutoUpdate===!0&&b.updateMatrix(),l.material.uniforms.uvTransform.value.copy(b.matrix),(h!==b||u!==b.version||d!==r.toneMapping)&&(l.material.needsUpdate=!0,h=b,u=b.version,d=r.toneMapping),l.layers.enableAll(),_.unshift(l,l.geometry,l.material,0,0,null))}function m(_,y){_.getRGB(wu,Zd(r)),n.buffers.color.setClear(wu.r,wu.g,wu.b,y,o)}function v(){f!==void 0&&(f.geometry.dispose(),f.material.dispose(),f=void 0),l!==void 0&&(l.geometry.dispose(),l.material.dispose(),l=void 0)}return{getClearColor:function(){return a},setClearColor:function(_,y=1){a.set(_),c=y,m(a,c)},getClearAlpha:function(){return c},setClearAlpha:function(_){c=_,m(a,c)},render:x,addToRenderList:p,dispose:v}}function sT(r,t){let e=r.getParameter(r.MAX_VERTEX_ATTRIBS),n={},i=u(null),s=i,o=!1;function a(S,I,P,L,N){let z=!1,V=h(L,P,I);s!==V&&(s=V,l(s.object)),z=d(S,L,P,N),z&&g(S,L,P,N),N!==null&&t.update(N,r.ELEMENT_ARRAY_BUFFER),(z||o)&&(o=!1,y(S,I,P,L),N!==null&&r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,t.get(N).buffer))}function c(){return r.createVertexArray()}function l(S){return r.bindVertexArray(S)}function f(S){return r.deleteVertexArray(S)}function h(S,I,P){let L=P.wireframe===!0,N=n[S.id];N===void 0&&(N={},n[S.id]=N);let z=N[I.id];z===void 0&&(z={},N[I.id]=z);let V=z[L];return V===void 0&&(V=u(c()),z[L]=V),V}function u(S){let I=[],P=[],L=[];for(let N=0;N=0){let pt=N[W],_t=z[W];if(_t===void 0&&(W==="instanceMatrix"&&S.instanceMatrix&&(_t=S.instanceMatrix),W==="instanceColor"&&S.instanceColor&&(_t=S.instanceColor)),pt===void 0||pt.attribute!==_t||_t&&pt.data!==_t.data)return!0;V++}return s.attributesNum!==V||s.index!==L}function g(S,I,P,L){let N={},z=I.attributes,V=0,j=P.getAttributes();for(let W in j)if(j[W].location>=0){let pt=z[W];pt===void 0&&(W==="instanceMatrix"&&S.instanceMatrix&&(pt=S.instanceMatrix),W==="instanceColor"&&S.instanceColor&&(pt=S.instanceColor));let _t={};_t.attribute=pt,pt&&pt.data&&(_t.data=pt.data),N[W]=_t,V++}s.attributes=N,s.attributesNum=V,s.index=L}function x(){let S=s.newAttributes;for(let I=0,P=S.length;I=0){let ct=N[j];if(ct===void 0&&(j==="instanceMatrix"&&S.instanceMatrix&&(ct=S.instanceMatrix),j==="instanceColor"&&S.instanceColor&&(ct=S.instanceColor)),ct!==void 0){let pt=ct.normalized,_t=ct.itemSize,Ht=t.get(ct);if(Ht===void 0)continue;let ee=Ht.buffer,he=Ht.type,Qt=Ht.bytesPerElement,$=he===r.INT||he===r.UNSIGNED_INT||ct.gpuType===Gi;if(ct.isInterleavedBufferAttribute){let tt=ct.data,St=tt.stride,Pt=ct.offset;if(tt.isInstancedInterleavedBuffer){for(let wt=0;wt0&&r.getShaderPrecisionFormat(r.FRAGMENT_SHADER,r.HIGH_FLOAT).precision>0)return"highp";w="mediump"}return w==="mediump"&&r.getShaderPrecisionFormat(r.VERTEX_SHADER,r.MEDIUM_FLOAT).precision>0&&r.getShaderPrecisionFormat(r.FRAGMENT_SHADER,r.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}let l=e.precision!==void 0?e.precision:"highp",f=c(l);f!==l&&(console.warn("THREE.WebGLRenderer:",l,"not supported, using",f,"instead."),l=f);let h=e.logarithmicDepthBuffer===!0,u=e.reversedDepthBuffer===!0&&t.has("EXT_clip_control"),d=r.getParameter(r.MAX_TEXTURE_IMAGE_UNITS),g=r.getParameter(r.MAX_VERTEX_TEXTURE_IMAGE_UNITS),x=r.getParameter(r.MAX_TEXTURE_SIZE),p=r.getParameter(r.MAX_CUBE_MAP_TEXTURE_SIZE),m=r.getParameter(r.MAX_VERTEX_ATTRIBS),v=r.getParameter(r.MAX_VERTEX_UNIFORM_VECTORS),_=r.getParameter(r.MAX_VARYING_VECTORS),y=r.getParameter(r.MAX_FRAGMENT_UNIFORM_VECTORS),b=g>0,T=r.getParameter(r.MAX_SAMPLES);return{isWebGL2:!0,getMaxAnisotropy:s,getMaxPrecision:c,textureFormatReadable:o,textureTypeReadable:a,precision:l,logarithmicDepthBuffer:h,reversedDepthBuffer:u,maxTextures:d,maxVertexTextures:g,maxTextureSize:x,maxCubemapSize:p,maxAttributes:m,maxVertexUniforms:v,maxVaryings:_,maxFragmentUniforms:y,vertexTextures:b,maxSamples:T}}function cT(r){let t=this,e=null,n=0,i=!1,s=!1,o=new _n,a=new Xt,c={value:null,needsUpdate:!1};this.uniform=c,this.numPlanes=0,this.numIntersection=0,this.init=function(h,u){let d=h.length!==0||u||n!==0||i;return i=u,n=h.length,d},this.beginShadows=function(){s=!0,f(null)},this.endShadows=function(){s=!1},this.setGlobalState=function(h,u){e=f(h,u,0)},this.setState=function(h,u,d){let g=h.clippingPlanes,x=h.clipIntersection,p=h.clipShadows,m=r.get(h);if(!i||g===null||g.length===0||s&&!p)s?f(null):l();else{let v=s?0:n,_=v*4,y=m.clippingState||null;c.value=y,y=f(g,u,_,d);for(let b=0;b!==_;++b)y[b]=e[b];m.clippingState=y,this.numIntersection=x?this.numPlanes:0,this.numPlanes+=v}};function l(){c.value!==e&&(c.value=e,c.needsUpdate=n>0),t.numPlanes=n,t.numIntersection=0}function f(h,u,d,g){let x=h!==null?h.length:0,p=null;if(x!==0){if(p=c.value,g!==!0||p===null){let m=d+x*4,v=u.matrixWorldInverse;a.getNormalMatrix(v),(p===null||p.length0){let l=new Fc(c.height);return l.fromEquirectangularTexture(r,o),t.set(o,l),o.addEventListener("dispose",i),e(l.texture,o.mapping)}else return null}}return o}function i(o){let a=o.target;a.removeEventListener("dispose",i);let c=t.get(a);c!==void 0&&(t.delete(a),c.dispose())}function s(){t=new WeakMap}return{get:n,dispose:s}}var Vs=4,v0=[.125,.215,.35,.446,.526,.582],Or=20,tp=new ki,_0=new ft,ep=null,np=0,ip=0,rp=!1,Br=(1+Math.sqrt(5))/2,ks=1/Br,y0=[new R(-Br,ks,0),new R(Br,ks,0),new R(-ks,0,Br),new R(ks,0,Br),new R(0,Br,-ks),new R(0,Br,ks),new R(-1,1,-1),new R(1,1,-1),new R(-1,1,1),new R(1,1,1)],uT=new R,Ru=class{constructor(t){this._renderer=t,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._compileMaterial(this._blurMaterial)}fromScene(t,e=0,n=.1,i=100,s={}){let{size:o=256,position:a=uT}=s;ep=this._renderer.getRenderTarget(),np=this._renderer.getActiveCubeFace(),ip=this._renderer.getActiveMipmapLevel(),rp=this._renderer.xr.enabled,this._renderer.xr.enabled=!1,this._setSize(o);let c=this._allocateTargets();return c.depthBuffer=!0,this._sceneToCubeUV(t,n,i,c,a),e>0&&this._blur(c,0,0,e),this._applyPMREM(c),this._cleanup(c),c}fromEquirectangular(t,e=null){return this._fromTexture(t,e)}fromCubemap(t,e=null){return this._fromTexture(t,e)}compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=M0(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=S0(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose()}_setSize(t){this._lodMax=Math.floor(Math.log2(t)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let t=0;t2?b:0,b,b),h.setRenderTarget(i),m&&h.render(p,c),h.render(t,c)}p.geometry.dispose(),p.material.dispose(),h.toneMapping=d,h.autoClear=u,t.background=v}_textureToCubeUV(t,e){let n=this._renderer,i=t.mapping===Si||t.mapping===Vi;i?(this._cubemapMaterial===null&&(this._cubemapMaterial=M0()),this._cubemapMaterial.uniforms.flipEnvMap.value=t.isRenderTargetTexture===!1?-1:1):this._equirectMaterial===null&&(this._equirectMaterial=S0());let s=i?this._cubemapMaterial:this._equirectMaterial,o=new Me(this._lodPlanes[0],s),a=s.uniforms;a.envMap.value=t;let c=this._cubeSize;Au(e,0,0,3*c,2*c),n.setRenderTarget(e),n.render(o,tp)}_applyPMREM(t){let e=this._renderer,n=e.autoClear;e.autoClear=!1;let i=this._lodPlanes.length;for(let s=1;sOr&&console.warn(`sigmaRadians, ${s}, is too large and will clip, as it requested ${p} samples when the maximum is set to ${Or}`);let m=[],v=0;for(let w=0;w_-Vs?i-_+Vs:0),T=4*(this._cubeSize-y);Au(e,b,T,3*y,2*y),c.setRenderTarget(e),c.render(h,tp)}};function hT(r){let t=[],e=[],n=[],i=r,s=r-Vs+1+v0.length;for(let o=0;or-Vs?c=v0[o-r+Vs-1]:o===0&&(c=0),n.push(c);let l=1/(a-2),f=-l,h=1+l,u=[f,f,h,f,h,h,f,f,h,h,f,h],d=6,g=6,x=3,p=2,m=1,v=new Float32Array(x*g*d),_=new Float32Array(p*g*d),y=new Float32Array(m*g*d);for(let T=0;T2?0:-1,M=[w,E,0,w+2/3,E,0,w+2/3,E+1,0,w,E,0,w+2/3,E+1,0,w,E+1,0];v.set(M,x*g*T),_.set(u,p*g*T);let S=[T,T,T,T,T,T];y.set(S,m*g*T)}let b=new Ft;b.setAttribute("position",new Ot(v,x)),b.setAttribute("uv",new Ot(_,p)),b.setAttribute("faceIndex",new Ot(y,m)),t.push(b),i>Vs&&i--}return{lodPlanes:t,sizeLods:e,sigmas:n}}function b0(r,t,e){let n=new ze(r,t,e);return n.texture.mapping=Ns,n.texture.name="PMREM.cubeUv",n.scissorTest=!0,n}function Au(r,t,e,n,i){r.viewport.set(t,e,n,i),r.scissor.set(t,e,n,i)}function fT(r,t,e){let n=new Float32Array(Or),i=new R(0,1,0);return new Ue({name:"SphericalGaussianBlur",defines:{n:Or,CUBEUV_TEXEL_WIDTH:1/t,CUBEUV_TEXEL_HEIGHT:1/e,CUBEUV_MAX_MIP:`${r}.0`},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:n},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:i}},vertexShader:pp(),fragmentShader:` + + precision mediump float; + precision mediump int; + + varying vec3 vOutputDirection; + + uniform sampler2D envMap; + uniform int samples; + uniform float weights[ n ]; + uniform bool latitudinal; + uniform float dTheta; + uniform float mipInt; + uniform vec3 poleAxis; + + #define ENVMAP_TYPE_CUBE_UV + #include + + vec3 getSample( float theta, vec3 axis ) { + + float cosTheta = cos( theta ); + // Rodrigues' axis-angle rotation + vec3 sampleDirection = vOutputDirection * cosTheta + + cross( axis, vOutputDirection ) * sin( theta ) + + axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta ); + + return bilinearCubeUV( envMap, sampleDirection, mipInt ); + + } + + void main() { + + vec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection ); + + if ( all( equal( axis, vec3( 0.0 ) ) ) ) { + + axis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x ); + + } + + axis = normalize( axis ); + + gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 ); + gl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis ); + + for ( int i = 1; i < n; i++ ) { + + if ( i >= samples ) { + + break; + + } + + float theta = dTheta * float( i ); + gl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis ); + gl_FragColor.rgb += weights[ i ] * getSample( theta, axis ); + + } + + } + `,blending:ke,depthTest:!1,depthWrite:!1})}function S0(){return new Ue({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null}},vertexShader:pp(),fragmentShader:` + + precision mediump float; + precision mediump int; + + varying vec3 vOutputDirection; + + uniform sampler2D envMap; + + #include + + void main() { + + vec3 outputDirection = normalize( vOutputDirection ); + vec2 uv = equirectUv( outputDirection ); + + gl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 ); + + } + `,blending:ke,depthTest:!1,depthWrite:!1})}function M0(){return new Ue({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:pp(),fragmentShader:` + + precision mediump float; + precision mediump int; + + uniform float flipEnvMap; + + varying vec3 vOutputDirection; + + uniform samplerCube envMap; + + void main() { + + gl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) ); + + } + `,blending:ke,depthTest:!1,depthWrite:!1})}function pp(){return` + + precision mediump float; + precision mediump int; + + attribute float faceIndex; + + varying vec3 vOutputDirection; + + // RH coordinate system; PMREM face-indexing convention + vec3 getDirection( vec2 uv, float face ) { + + uv = 2.0 * uv - 1.0; + + vec3 direction = vec3( uv, 1.0 ); + + if ( face == 0.0 ) { + + direction = direction.zyx; // ( 1, v, u ) pos x + + } else if ( face == 1.0 ) { + + direction = direction.xzy; + direction.xz *= -1.0; // ( -u, 1, -v ) pos y + + } else if ( face == 2.0 ) { + + direction.x *= -1.0; // ( -u, v, 1 ) pos z + + } else if ( face == 3.0 ) { + + direction = direction.zyx; + direction.xz *= -1.0; // ( -1, v, -u ) neg x + + } else if ( face == 4.0 ) { + + direction = direction.xzy; + direction.xy *= -1.0; // ( -u, -1, v ) neg y + + } else if ( face == 5.0 ) { + + direction.z *= -1.0; // ( u, v, -1 ) neg z + + } + + return direction; + + } + + void main() { + + vOutputDirection = getDirection( uv, faceIndex ); + gl_Position = vec4( position, 1.0 ); + + } + `}function dT(r){let t=new WeakMap,e=null;function n(a){if(a&&a.isTexture){let c=a.mapping,l=c===Mi||c===ha,f=c===Si||c===Vi;if(l||f){let h=t.get(a),u=h!==void 0?h.texture.pmremVersion:0;if(a.isRenderTargetTexture&&a.pmremVersion!==u)return e===null&&(e=new Ru(r)),h=l?e.fromEquirectangular(a,h):e.fromCubemap(a,h),h.texture.pmremVersion=a.pmremVersion,t.set(a,h),h.texture;if(h!==void 0)return h.texture;{let d=a.image;return l&&d&&d.height>0||f&&d&&i(d)?(e===null&&(e=new Ru(r)),h=l?e.fromEquirectangular(a):e.fromCubemap(a),h.texture.pmremVersion=a.pmremVersion,t.set(a,h),a.addEventListener("dispose",s),h.texture):null}}}return a}function i(a){let c=0,l=6;for(let f=0;ft.maxTextureSize&&(b=Math.ceil(y/t.maxTextureSize),y=t.maxTextureSize);let T=new Float32Array(y*b*4*h),w=new Ui(T,y,b,h);w.type=$t,w.needsUpdate=!0;let E=_*4;for(let S=0;S0)return r;let i=t*e,s=w0[i];if(s===void 0&&(s=new Float32Array(i),w0[i]=s),t!==0){n.toArray(s,0);for(let o=1,a=0;o!==t;++o)a+=e,r[o].toArray(s,a)}return s}function We(r,t){if(r.length!==t.length)return!1;for(let e=0,n=r.length;e":" "} ${a}: ${e[o]}`)}return n.join(` +`)}var D0=new Xt;function uw(r){ie._getMatrix(D0,ie.workingColorSpace,r);let t=`mat3( ${D0.elements.map(e=>e.toFixed(4))} )`;switch(ie.getTransfer(r)){case Co:return[t,"LinearTransferOETF"];case me:return[t,"sRGBTransferOETF"];default:return console.warn("THREE.WebGLProgram: Unsupported color space: ",r),[t,"LinearTransferOETF"]}}function F0(r,t,e){let n=r.getShaderParameter(t,r.COMPILE_STATUS),s=(r.getShaderInfoLog(t)||"").trim();if(n&&s==="")return"";let o=/ERROR: 0:(\d+)/.exec(s);if(o){let a=parseInt(o[1]);return e.toUpperCase()+` + +`+s+` + +`+lw(r.getShaderSource(t),a)}else return s}function hw(r,t){let e=uw(t);return[`vec4 ${r}( vec4 value ) {`,` return ${e[1]}( vec4( value.rgb * ${e[0]}, value.a ) );`,"}"].join(` +`)}function fw(r,t){let e;switch(t){case Og:e="Linear";break;case zg:e="Reinhard";break;case kg:e="Cineon";break;case Vg:e="ACESFilmic";break;case Gg:e="AgX";break;case Wg:e="Neutral";break;case Hg:e="Custom";break;default:console.warn("THREE.WebGLProgram: Unsupported toneMapping:",t),e="Linear"}return"vec3 "+r+"( vec3 color ) { return "+e+"ToneMapping( color ); }"}var Eu=new R;function dw(){ie.getLuminanceCoefficients(Eu);let r=Eu.x.toFixed(4),t=Eu.y.toFixed(4),e=Eu.z.toFixed(4);return["float luminance( const in vec3 rgb ) {",` const vec3 weights = vec3( ${r}, ${t}, ${e} );`," return dot( weights, rgb );","}"].join(` +`)}function pw(r){return[r.extensionClipCullDistance?"#extension GL_ANGLE_clip_cull_distance : require":"",r.extensionMultiDraw?"#extension GL_ANGLE_multi_draw : require":""].filter(va).join(` +`)}function mw(r){let t=[];for(let e in r){let n=r[e];n!==!1&&t.push("#define "+e+" "+n)}return t.join(` +`)}function gw(r,t){let e={},n=r.getProgramParameter(t,r.ACTIVE_ATTRIBUTES);for(let i=0;i/gm;function lp(r){return r.replace(xw,_w)}var vw=new Map;function _w(r,t){let e=jt[t];if(e===void 0){let n=vw.get(t);if(n!==void 0)e=jt[n],console.warn('THREE.WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.',t,n);else throw new Error("Can not resolve #include <"+t+">")}return lp(e)}var yw=/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;function U0(r){return r.replace(yw,bw)}function bw(r,t,e,n){let i="";for(let s=parseInt(t);s0&&(p+=` +`),m=["#define SHADER_TYPE "+e.shaderType,"#define SHADER_NAME "+e.shaderName,g].filter(va).join(` +`),m.length>0&&(m+=` +`)):(p=[B0(e),"#define SHADER_TYPE "+e.shaderType,"#define SHADER_NAME "+e.shaderName,g,e.extensionClipCullDistance?"#define USE_CLIP_DISTANCE":"",e.batching?"#define USE_BATCHING":"",e.batchingColor?"#define USE_BATCHING_COLOR":"",e.instancing?"#define USE_INSTANCING":"",e.instancingColor?"#define USE_INSTANCING_COLOR":"",e.instancingMorph?"#define USE_INSTANCING_MORPH":"",e.useFog&&e.fog?"#define USE_FOG":"",e.useFog&&e.fogExp2?"#define FOG_EXP2":"",e.map?"#define USE_MAP":"",e.envMap?"#define USE_ENVMAP":"",e.envMap?"#define "+f:"",e.lightMap?"#define USE_LIGHTMAP":"",e.aoMap?"#define USE_AOMAP":"",e.bumpMap?"#define USE_BUMPMAP":"",e.normalMap?"#define USE_NORMALMAP":"",e.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",e.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",e.displacementMap?"#define USE_DISPLACEMENTMAP":"",e.emissiveMap?"#define USE_EMISSIVEMAP":"",e.anisotropy?"#define USE_ANISOTROPY":"",e.anisotropyMap?"#define USE_ANISOTROPYMAP":"",e.clearcoatMap?"#define USE_CLEARCOATMAP":"",e.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",e.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",e.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",e.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",e.specularMap?"#define USE_SPECULARMAP":"",e.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",e.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",e.roughnessMap?"#define USE_ROUGHNESSMAP":"",e.metalnessMap?"#define USE_METALNESSMAP":"",e.alphaMap?"#define USE_ALPHAMAP":"",e.alphaHash?"#define USE_ALPHAHASH":"",e.transmission?"#define USE_TRANSMISSION":"",e.transmissionMap?"#define USE_TRANSMISSIONMAP":"",e.thicknessMap?"#define USE_THICKNESSMAP":"",e.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",e.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",e.mapUv?"#define MAP_UV "+e.mapUv:"",e.alphaMapUv?"#define ALPHAMAP_UV "+e.alphaMapUv:"",e.lightMapUv?"#define LIGHTMAP_UV "+e.lightMapUv:"",e.aoMapUv?"#define AOMAP_UV "+e.aoMapUv:"",e.emissiveMapUv?"#define EMISSIVEMAP_UV "+e.emissiveMapUv:"",e.bumpMapUv?"#define BUMPMAP_UV "+e.bumpMapUv:"",e.normalMapUv?"#define NORMALMAP_UV "+e.normalMapUv:"",e.displacementMapUv?"#define DISPLACEMENTMAP_UV "+e.displacementMapUv:"",e.metalnessMapUv?"#define METALNESSMAP_UV "+e.metalnessMapUv:"",e.roughnessMapUv?"#define ROUGHNESSMAP_UV "+e.roughnessMapUv:"",e.anisotropyMapUv?"#define ANISOTROPYMAP_UV "+e.anisotropyMapUv:"",e.clearcoatMapUv?"#define CLEARCOATMAP_UV "+e.clearcoatMapUv:"",e.clearcoatNormalMapUv?"#define CLEARCOAT_NORMALMAP_UV "+e.clearcoatNormalMapUv:"",e.clearcoatRoughnessMapUv?"#define CLEARCOAT_ROUGHNESSMAP_UV "+e.clearcoatRoughnessMapUv:"",e.iridescenceMapUv?"#define IRIDESCENCEMAP_UV "+e.iridescenceMapUv:"",e.iridescenceThicknessMapUv?"#define IRIDESCENCE_THICKNESSMAP_UV "+e.iridescenceThicknessMapUv:"",e.sheenColorMapUv?"#define SHEEN_COLORMAP_UV "+e.sheenColorMapUv:"",e.sheenRoughnessMapUv?"#define SHEEN_ROUGHNESSMAP_UV "+e.sheenRoughnessMapUv:"",e.specularMapUv?"#define SPECULARMAP_UV "+e.specularMapUv:"",e.specularColorMapUv?"#define SPECULAR_COLORMAP_UV "+e.specularColorMapUv:"",e.specularIntensityMapUv?"#define SPECULAR_INTENSITYMAP_UV "+e.specularIntensityMapUv:"",e.transmissionMapUv?"#define TRANSMISSIONMAP_UV "+e.transmissionMapUv:"",e.thicknessMapUv?"#define THICKNESSMAP_UV "+e.thicknessMapUv:"",e.vertexTangents&&e.flatShading===!1?"#define USE_TANGENT":"",e.vertexColors?"#define USE_COLOR":"",e.vertexAlphas?"#define USE_COLOR_ALPHA":"",e.vertexUv1s?"#define USE_UV1":"",e.vertexUv2s?"#define USE_UV2":"",e.vertexUv3s?"#define USE_UV3":"",e.pointsUvs?"#define USE_POINTS_UV":"",e.flatShading?"#define FLAT_SHADED":"",e.skinning?"#define USE_SKINNING":"",e.morphTargets?"#define USE_MORPHTARGETS":"",e.morphNormals&&e.flatShading===!1?"#define USE_MORPHNORMALS":"",e.morphColors?"#define USE_MORPHCOLORS":"",e.morphTargetsCount>0?"#define MORPHTARGETS_TEXTURE_STRIDE "+e.morphTextureStride:"",e.morphTargetsCount>0?"#define MORPHTARGETS_COUNT "+e.morphTargetsCount:"",e.doubleSided?"#define DOUBLE_SIDED":"",e.flipSided?"#define FLIP_SIDED":"",e.shadowMapEnabled?"#define USE_SHADOWMAP":"",e.shadowMapEnabled?"#define "+c:"",e.sizeAttenuation?"#define USE_SIZEATTENUATION":"",e.numLightProbes>0?"#define USE_LIGHT_PROBES":"",e.logarithmicDepthBuffer?"#define USE_LOGARITHMIC_DEPTH_BUFFER":"",e.reversedDepthBuffer?"#define USE_REVERSED_DEPTH_BUFFER":"","uniform mat4 modelMatrix;","uniform mat4 modelViewMatrix;","uniform mat4 projectionMatrix;","uniform mat4 viewMatrix;","uniform mat3 normalMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;","#ifdef USE_INSTANCING"," attribute mat4 instanceMatrix;","#endif","#ifdef USE_INSTANCING_COLOR"," attribute vec3 instanceColor;","#endif","#ifdef USE_INSTANCING_MORPH"," uniform sampler2D morphTexture;","#endif","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","#ifdef USE_UV1"," attribute vec2 uv1;","#endif","#ifdef USE_UV2"," attribute vec2 uv2;","#endif","#ifdef USE_UV3"," attribute vec2 uv3;","#endif","#ifdef USE_TANGENT"," attribute vec4 tangent;","#endif","#if defined( USE_COLOR_ALPHA )"," attribute vec4 color;","#elif defined( USE_COLOR )"," attribute vec3 color;","#endif","#ifdef USE_SKINNING"," attribute vec4 skinIndex;"," attribute vec4 skinWeight;","#endif",` +`].filter(va).join(` +`),m=[B0(e),"#define SHADER_TYPE "+e.shaderType,"#define SHADER_NAME "+e.shaderName,g,e.useFog&&e.fog?"#define USE_FOG":"",e.useFog&&e.fogExp2?"#define FOG_EXP2":"",e.alphaToCoverage?"#define ALPHA_TO_COVERAGE":"",e.map?"#define USE_MAP":"",e.matcap?"#define USE_MATCAP":"",e.envMap?"#define USE_ENVMAP":"",e.envMap?"#define "+l:"",e.envMap?"#define "+f:"",e.envMap?"#define "+h:"",u?"#define CUBEUV_TEXEL_WIDTH "+u.texelWidth:"",u?"#define CUBEUV_TEXEL_HEIGHT "+u.texelHeight:"",u?"#define CUBEUV_MAX_MIP "+u.maxMip+".0":"",e.lightMap?"#define USE_LIGHTMAP":"",e.aoMap?"#define USE_AOMAP":"",e.bumpMap?"#define USE_BUMPMAP":"",e.normalMap?"#define USE_NORMALMAP":"",e.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",e.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",e.emissiveMap?"#define USE_EMISSIVEMAP":"",e.anisotropy?"#define USE_ANISOTROPY":"",e.anisotropyMap?"#define USE_ANISOTROPYMAP":"",e.clearcoat?"#define USE_CLEARCOAT":"",e.clearcoatMap?"#define USE_CLEARCOATMAP":"",e.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",e.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",e.dispersion?"#define USE_DISPERSION":"",e.iridescence?"#define USE_IRIDESCENCE":"",e.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",e.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",e.specularMap?"#define USE_SPECULARMAP":"",e.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",e.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",e.roughnessMap?"#define USE_ROUGHNESSMAP":"",e.metalnessMap?"#define USE_METALNESSMAP":"",e.alphaMap?"#define USE_ALPHAMAP":"",e.alphaTest?"#define USE_ALPHATEST":"",e.alphaHash?"#define USE_ALPHAHASH":"",e.sheen?"#define USE_SHEEN":"",e.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",e.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",e.transmission?"#define USE_TRANSMISSION":"",e.transmissionMap?"#define USE_TRANSMISSIONMAP":"",e.thicknessMap?"#define USE_THICKNESSMAP":"",e.vertexTangents&&e.flatShading===!1?"#define USE_TANGENT":"",e.vertexColors||e.instancingColor||e.batchingColor?"#define USE_COLOR":"",e.vertexAlphas?"#define USE_COLOR_ALPHA":"",e.vertexUv1s?"#define USE_UV1":"",e.vertexUv2s?"#define USE_UV2":"",e.vertexUv3s?"#define USE_UV3":"",e.pointsUvs?"#define USE_POINTS_UV":"",e.gradientMap?"#define USE_GRADIENTMAP":"",e.flatShading?"#define FLAT_SHADED":"",e.doubleSided?"#define DOUBLE_SIDED":"",e.flipSided?"#define FLIP_SIDED":"",e.shadowMapEnabled?"#define USE_SHADOWMAP":"",e.shadowMapEnabled?"#define "+c:"",e.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",e.numLightProbes>0?"#define USE_LIGHT_PROBES":"",e.decodeVideoTexture?"#define DECODE_VIDEO_TEXTURE":"",e.decodeVideoTextureEmissive?"#define DECODE_VIDEO_TEXTURE_EMISSIVE":"",e.logarithmicDepthBuffer?"#define USE_LOGARITHMIC_DEPTH_BUFFER":"",e.reversedDepthBuffer?"#define USE_REVERSED_DEPTH_BUFFER":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",e.toneMapping!==Zn?"#define TONE_MAPPING":"",e.toneMapping!==Zn?jt.tonemapping_pars_fragment:"",e.toneMapping!==Zn?fw("toneMapping",e.toneMapping):"",e.dithering?"#define DITHERING":"",e.opaque?"#define OPAQUE":"",jt.colorspace_pars_fragment,hw("linearToOutputTexel",e.outputColorSpace),dw(),e.useDepthPacking?"#define DEPTH_PACKING "+e.depthPacking:"",` +`].filter(va).join(` +`)),o=lp(o),o=L0(o,e),o=N0(o,e),a=lp(a),a=L0(a,e),a=N0(a,e),o=U0(o),a=U0(a),e.isRawShaderMaterial!==!0&&(v=`#version 300 es +`,p=[d,"#define attribute in","#define varying out","#define texture2D texture"].join(` +`)+` +`+p,m=["#define varying in",e.glslVersion===qd?"":"layout(location = 0) out highp vec4 pc_fragColor;",e.glslVersion===qd?"":"#define gl_FragColor pc_fragColor","#define gl_FragDepthEXT gl_FragDepth","#define texture2D texture","#define textureCube texture","#define texture2DProj textureProj","#define texture2DLodEXT textureLod","#define texture2DProjLodEXT textureProjLod","#define textureCubeLodEXT textureLod","#define texture2DGradEXT textureGrad","#define texture2DProjGradEXT textureProjGrad","#define textureCubeGradEXT textureGrad"].join(` +`)+` +`+m);let _=v+p+o,y=v+m+a,b=P0(i,i.VERTEX_SHADER,_),T=P0(i,i.FRAGMENT_SHADER,y);i.attachShader(x,b),i.attachShader(x,T),e.index0AttributeName!==void 0?i.bindAttribLocation(x,0,e.index0AttributeName):e.morphTargets===!0&&i.bindAttribLocation(x,0,"position"),i.linkProgram(x);function w(I){if(r.debug.checkShaderErrors){let P=i.getProgramInfoLog(x)||"",L=i.getShaderInfoLog(b)||"",N=i.getShaderInfoLog(T)||"",z=P.trim(),V=L.trim(),j=N.trim(),W=!0,ct=!0;if(i.getProgramParameter(x,i.LINK_STATUS)===!1)if(W=!1,typeof r.debug.onShaderError=="function")r.debug.onShaderError(i,x,b,T);else{let pt=F0(i,b,"vertex"),_t=F0(i,T,"fragment");console.error("THREE.WebGLProgram: Shader Error "+i.getError()+" - VALIDATE_STATUS "+i.getProgramParameter(x,i.VALIDATE_STATUS)+` + +Material Name: `+I.name+` +Material Type: `+I.type+` + +Program Info Log: `+z+` +`+pt+` +`+_t)}else z!==""?console.warn("THREE.WebGLProgram: Program Info Log:",z):(V===""||j==="")&&(ct=!1);ct&&(I.diagnostics={runnable:W,programLog:z,vertexShader:{log:V,prefix:p},fragmentShader:{log:j,prefix:m}})}i.deleteShader(b),i.deleteShader(T),E=new Hs(i,x),M=gw(i,x)}let E;this.getUniforms=function(){return E===void 0&&w(this),E};let M;this.getAttributes=function(){return M===void 0&&w(this),M};let S=e.rendererExtensionParallelShaderCompile===!1;return this.isReady=function(){return S===!1&&(S=i.getProgramParameter(x,aw)),S},this.destroy=function(){n.releaseStatesOfProgram(this),i.deleteProgram(x),this.program=void 0},this.type=e.shaderType,this.name=e.shaderName,this.id=cw++,this.cacheKey=t,this.usedTimes=1,this.program=x,this.vertexShader=b,this.fragmentShader=T,this}var Rw=0,up=class{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(t){let e=t.vertexShader,n=t.fragmentShader,i=this._getShaderStage(e),s=this._getShaderStage(n),o=this._getShaderCacheForMaterial(t);return o.has(i)===!1&&(o.add(i),i.usedTimes++),o.has(s)===!1&&(o.add(s),s.usedTimes++),this}remove(t){let e=this.materialCache.get(t);for(let n of e)n.usedTimes--,n.usedTimes===0&&this.shaderCache.delete(n.code);return this.materialCache.delete(t),this}getVertexShaderID(t){return this._getShaderStage(t.vertexShader).id}getFragmentShaderID(t){return this._getShaderStage(t.fragmentShader).id}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(t){let e=this.materialCache,n=e.get(t);return n===void 0&&(n=new Set,e.set(t,n)),n}_getShaderStage(t){let e=this.shaderCache,n=e.get(t);return n===void 0&&(n=new hp(t),e.set(t,n)),n}},hp=class{constructor(t){this.id=Rw++,this.code=t,this.usedTimes=0}};function Cw(r,t,e,n,i,s,o){let a=new Ss,c=new up,l=new Set,f=[],h=i.logarithmicDepthBuffer,u=i.vertexTextures,d=i.precision,g={MeshDepthMaterial:"depth",MeshDistanceMaterial:"distanceRGBA",MeshNormalMaterial:"normal",MeshBasicMaterial:"basic",MeshLambertMaterial:"lambert",MeshPhongMaterial:"phong",MeshToonMaterial:"toon",MeshStandardMaterial:"physical",MeshPhysicalMaterial:"physical",MeshMatcapMaterial:"matcap",LineBasicMaterial:"basic",LineDashedMaterial:"dashed",PointsMaterial:"points",ShadowMaterial:"shadow",SpriteMaterial:"sprite"};function x(M){return l.add(M),M===0?"uv":`uv${M}`}function p(M,S,I,P,L){let N=P.fog,z=L.geometry,V=M.isMeshStandardMaterial?P.environment:null,j=(M.isMeshStandardMaterial?e:t).get(M.envMap||V),W=j&&j.mapping===Ns?j.image.height:null,ct=g[M.type];M.precision!==null&&(d=i.getMaxPrecision(M.precision),d!==M.precision&&console.warn("THREE.WebGLProgram.getParameters:",M.precision,"not supported, using",d,"instead."));let pt=z.morphAttributes.position||z.morphAttributes.normal||z.morphAttributes.color,_t=pt!==void 0?pt.length:0,Ht=0;z.morphAttributes.position!==void 0&&(Ht=1),z.morphAttributes.normal!==void 0&&(Ht=2),z.morphAttributes.color!==void 0&&(Ht=3);let ee,he,Qt,$;if(ct){let de=ci[ct];ee=de.vertexShader,he=de.fragmentShader}else ee=M.vertexShader,he=M.fragmentShader,c.update(M),Qt=c.getVertexShaderID(M),$=c.getFragmentShaderID(M);let tt=r.getRenderTarget(),St=r.state.buffers.depth.getReversed(),Pt=L.isInstancedMesh===!0,wt=L.isBatchedMesh===!0,te=!!M.map,fe=!!M.matcap,F=!!j,nt=!!M.aoMap,K=!!M.lightMap,J=!!M.bumpMap,Z=!!M.normalMap,ut=!!M.displacementMap,it=!!M.emissiveMap,ht=!!M.metalnessMap,qt=!!M.roughnessMap,Wt=M.anisotropy>0,D=M.clearcoat>0,A=M.dispersion>0,k=M.iridescence>0,X=M.sheen>0,et=M.transmission>0,Y=Wt&&!!M.anisotropyMap,It=D&&!!M.clearcoatMap,lt=D&&!!M.clearcoatNormalMap,Et=D&&!!M.clearcoatRoughnessMap,Rt=k&&!!M.iridescenceMap,rt=k&&!!M.iridescenceThicknessMap,yt=X&&!!M.sheenColorMap,zt=X&&!!M.sheenRoughnessMap,Dt=!!M.specularMap,xt=!!M.specularColorMap,Jt=!!M.specularIntensityMap,U=et&&!!M.transmissionMap,at=et&&!!M.thicknessMap,dt=!!M.gradientMap,Tt=!!M.alphaMap,st=M.alphaTest>0,Q=!!M.alphaHash,Ct=!!M.extensions,Yt=Zn;M.toneMapped&&(tt===null||tt.isXRRenderTarget===!0)&&(Yt=r.toneMapping);let Se={shaderID:ct,shaderType:M.type,shaderName:M.name,vertexShader:ee,fragmentShader:he,defines:M.defines,customVertexShaderID:Qt,customFragmentShaderID:$,isRawShaderMaterial:M.isRawShaderMaterial===!0,glslVersion:M.glslVersion,precision:d,batching:wt,batchingColor:wt&&L._colorsTexture!==null,instancing:Pt,instancingColor:Pt&&L.instanceColor!==null,instancingMorph:Pt&&L.morphTexture!==null,supportsVertexTextures:u,outputColorSpace:tt===null?r.outputColorSpace:tt.isXRRenderTarget===!0?tt.texture.colorSpace:yr,alphaToCoverage:!!M.alphaToCoverage,map:te,matcap:fe,envMap:F,envMapMode:F&&j.mapping,envMapCubeUVHeight:W,aoMap:nt,lightMap:K,bumpMap:J,normalMap:Z,displacementMap:u&&ut,emissiveMap:it,normalMapObjectSpace:Z&&M.normalMapType===Kg,normalMapTangentSpace:Z&&M.normalMapType===qi,metalnessMap:ht,roughnessMap:qt,anisotropy:Wt,anisotropyMap:Y,clearcoat:D,clearcoatMap:It,clearcoatNormalMap:lt,clearcoatRoughnessMap:Et,dispersion:A,iridescence:k,iridescenceMap:Rt,iridescenceThicknessMap:rt,sheen:X,sheenColorMap:yt,sheenRoughnessMap:zt,specularMap:Dt,specularColorMap:xt,specularIntensityMap:Jt,transmission:et,transmissionMap:U,thicknessMap:at,gradientMap:dt,opaque:M.transparent===!1&&M.blending===Yn&&M.alphaToCoverage===!1,alphaMap:Tt,alphaTest:st,alphaHash:Q,combine:M.combine,mapUv:te&&x(M.map.channel),aoMapUv:nt&&x(M.aoMap.channel),lightMapUv:K&&x(M.lightMap.channel),bumpMapUv:J&&x(M.bumpMap.channel),normalMapUv:Z&&x(M.normalMap.channel),displacementMapUv:ut&&x(M.displacementMap.channel),emissiveMapUv:it&&x(M.emissiveMap.channel),metalnessMapUv:ht&&x(M.metalnessMap.channel),roughnessMapUv:qt&&x(M.roughnessMap.channel),anisotropyMapUv:Y&&x(M.anisotropyMap.channel),clearcoatMapUv:It&&x(M.clearcoatMap.channel),clearcoatNormalMapUv:lt&&x(M.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:Et&&x(M.clearcoatRoughnessMap.channel),iridescenceMapUv:Rt&&x(M.iridescenceMap.channel),iridescenceThicknessMapUv:rt&&x(M.iridescenceThicknessMap.channel),sheenColorMapUv:yt&&x(M.sheenColorMap.channel),sheenRoughnessMapUv:zt&&x(M.sheenRoughnessMap.channel),specularMapUv:Dt&&x(M.specularMap.channel),specularColorMapUv:xt&&x(M.specularColorMap.channel),specularIntensityMapUv:Jt&&x(M.specularIntensityMap.channel),transmissionMapUv:U&&x(M.transmissionMap.channel),thicknessMapUv:at&&x(M.thicknessMap.channel),alphaMapUv:Tt&&x(M.alphaMap.channel),vertexTangents:!!z.attributes.tangent&&(Z||Wt),vertexColors:M.vertexColors,vertexAlphas:M.vertexColors===!0&&!!z.attributes.color&&z.attributes.color.itemSize===4,pointsUvs:L.isPoints===!0&&!!z.attributes.uv&&(te||Tt),fog:!!N,useFog:M.fog===!0,fogExp2:!!N&&N.isFogExp2,flatShading:M.flatShading===!0&&M.wireframe===!1,sizeAttenuation:M.sizeAttenuation===!0,logarithmicDepthBuffer:h,reversedDepthBuffer:St,skinning:L.isSkinnedMesh===!0,morphTargets:z.morphAttributes.position!==void 0,morphNormals:z.morphAttributes.normal!==void 0,morphColors:z.morphAttributes.color!==void 0,morphTargetsCount:_t,morphTextureStride:Ht,numDirLights:S.directional.length,numPointLights:S.point.length,numSpotLights:S.spot.length,numSpotLightMaps:S.spotLightMap.length,numRectAreaLights:S.rectArea.length,numHemiLights:S.hemi.length,numDirLightShadows:S.directionalShadowMap.length,numPointLightShadows:S.pointShadowMap.length,numSpotLightShadows:S.spotShadowMap.length,numSpotLightShadowsWithMaps:S.numSpotLightShadowsWithMaps,numLightProbes:S.numLightProbes,numClippingPlanes:o.numPlanes,numClipIntersection:o.numIntersection,dithering:M.dithering,shadowMapEnabled:r.shadowMap.enabled&&I.length>0,shadowMapType:r.shadowMap.type,toneMapping:Yt,decodeVideoTexture:te&&M.map.isVideoTexture===!0&&ie.getTransfer(M.map.colorSpace)===me,decodeVideoTextureEmissive:it&&M.emissiveMap.isVideoTexture===!0&&ie.getTransfer(M.emissiveMap.colorSpace)===me,premultipliedAlpha:M.premultipliedAlpha,doubleSided:M.side===Sn,flipSided:M.side===He,useDepthPacking:M.depthPacking>=0,depthPacking:M.depthPacking||0,index0AttributeName:M.index0AttributeName,extensionClipCullDistance:Ct&&M.extensions.clipCullDistance===!0&&n.has("WEBGL_clip_cull_distance"),extensionMultiDraw:(Ct&&M.extensions.multiDraw===!0||wt)&&n.has("WEBGL_multi_draw"),rendererExtensionParallelShaderCompile:n.has("KHR_parallel_shader_compile"),customProgramCacheKey:M.customProgramCacheKey()};return Se.vertexUv1s=l.has(1),Se.vertexUv2s=l.has(2),Se.vertexUv3s=l.has(3),l.clear(),Se}function m(M){let S=[];if(M.shaderID?S.push(M.shaderID):(S.push(M.customVertexShaderID),S.push(M.customFragmentShaderID)),M.defines!==void 0)for(let I in M.defines)S.push(I),S.push(M.defines[I]);return M.isRawShaderMaterial===!1&&(v(S,M),_(S,M),S.push(r.outputColorSpace)),S.push(M.customProgramCacheKey),S.join()}function v(M,S){M.push(S.precision),M.push(S.outputColorSpace),M.push(S.envMapMode),M.push(S.envMapCubeUVHeight),M.push(S.mapUv),M.push(S.alphaMapUv),M.push(S.lightMapUv),M.push(S.aoMapUv),M.push(S.bumpMapUv),M.push(S.normalMapUv),M.push(S.displacementMapUv),M.push(S.emissiveMapUv),M.push(S.metalnessMapUv),M.push(S.roughnessMapUv),M.push(S.anisotropyMapUv),M.push(S.clearcoatMapUv),M.push(S.clearcoatNormalMapUv),M.push(S.clearcoatRoughnessMapUv),M.push(S.iridescenceMapUv),M.push(S.iridescenceThicknessMapUv),M.push(S.sheenColorMapUv),M.push(S.sheenRoughnessMapUv),M.push(S.specularMapUv),M.push(S.specularColorMapUv),M.push(S.specularIntensityMapUv),M.push(S.transmissionMapUv),M.push(S.thicknessMapUv),M.push(S.combine),M.push(S.fogExp2),M.push(S.sizeAttenuation),M.push(S.morphTargetsCount),M.push(S.morphAttributeCount),M.push(S.numDirLights),M.push(S.numPointLights),M.push(S.numSpotLights),M.push(S.numSpotLightMaps),M.push(S.numHemiLights),M.push(S.numRectAreaLights),M.push(S.numDirLightShadows),M.push(S.numPointLightShadows),M.push(S.numSpotLightShadows),M.push(S.numSpotLightShadowsWithMaps),M.push(S.numLightProbes),M.push(S.shadowMapType),M.push(S.toneMapping),M.push(S.numClippingPlanes),M.push(S.numClipIntersection),M.push(S.depthPacking)}function _(M,S){a.disableAll(),S.supportsVertexTextures&&a.enable(0),S.instancing&&a.enable(1),S.instancingColor&&a.enable(2),S.instancingMorph&&a.enable(3),S.matcap&&a.enable(4),S.envMap&&a.enable(5),S.normalMapObjectSpace&&a.enable(6),S.normalMapTangentSpace&&a.enable(7),S.clearcoat&&a.enable(8),S.iridescence&&a.enable(9),S.alphaTest&&a.enable(10),S.vertexColors&&a.enable(11),S.vertexAlphas&&a.enable(12),S.vertexUv1s&&a.enable(13),S.vertexUv2s&&a.enable(14),S.vertexUv3s&&a.enable(15),S.vertexTangents&&a.enable(16),S.anisotropy&&a.enable(17),S.alphaHash&&a.enable(18),S.batching&&a.enable(19),S.dispersion&&a.enable(20),S.batchingColor&&a.enable(21),S.gradientMap&&a.enable(22),M.push(a.mask),a.disableAll(),S.fog&&a.enable(0),S.useFog&&a.enable(1),S.flatShading&&a.enable(2),S.logarithmicDepthBuffer&&a.enable(3),S.reversedDepthBuffer&&a.enable(4),S.skinning&&a.enable(5),S.morphTargets&&a.enable(6),S.morphNormals&&a.enable(7),S.morphColors&&a.enable(8),S.premultipliedAlpha&&a.enable(9),S.shadowMapEnabled&&a.enable(10),S.doubleSided&&a.enable(11),S.flipSided&&a.enable(12),S.useDepthPacking&&a.enable(13),S.dithering&&a.enable(14),S.transmission&&a.enable(15),S.sheen&&a.enable(16),S.opaque&&a.enable(17),S.pointsUvs&&a.enable(18),S.decodeVideoTexture&&a.enable(19),S.decodeVideoTextureEmissive&&a.enable(20),S.alphaToCoverage&&a.enable(21),M.push(a.mask)}function y(M){let S=g[M.type],I;if(S){let P=ci[S];I=c0.clone(P.uniforms)}else I=M.uniforms;return I}function b(M,S){let I;for(let P=0,L=f.length;P0?n.push(m):d.transparent===!0?i.push(m):e.push(m)}function c(h,u,d,g,x,p){let m=o(h,u,d,g,x,p);d.transmission>0?n.unshift(m):d.transparent===!0?i.unshift(m):e.unshift(m)}function l(h,u){e.length>1&&e.sort(h||Pw),n.length>1&&n.sort(u||O0),i.length>1&&i.sort(u||O0)}function f(){for(let h=t,u=r.length;h=s.length?(o=new z0,s.push(o)):o=s[i],o}function e(){r=new WeakMap}return{get:t,dispose:e}}function Fw(){let r={};return{get:function(t){if(r[t.id]!==void 0)return r[t.id];let e;switch(t.type){case"DirectionalLight":e={direction:new R,color:new ft};break;case"SpotLight":e={position:new R,direction:new R,color:new ft,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":e={position:new R,color:new ft,distance:0,decay:0};break;case"HemisphereLight":e={direction:new R,skyColor:new ft,groundColor:new ft};break;case"RectAreaLight":e={color:new ft,position:new R,halfWidth:new R,halfHeight:new R};break}return r[t.id]=e,e}}}function Lw(){let r={};return{get:function(t){if(r[t.id]!==void 0)return r[t.id];let e;switch(t.type){case"DirectionalLight":e={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new q};break;case"SpotLight":e={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new q};break;case"PointLight":e={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new q,shadowCameraNear:1,shadowCameraFar:1e3};break}return r[t.id]=e,e}}}var Nw=0;function Uw(r,t){return(t.castShadow?2:0)-(r.castShadow?2:0)+(t.map?1:0)-(r.map?1:0)}function Bw(r){let t=new Fw,e=Lw(),n={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let l=0;l<9;l++)n.probe.push(new R);let i=new R,s=new gt,o=new gt;function a(l){let f=0,h=0,u=0;for(let M=0;M<9;M++)n.probe[M].set(0,0,0);let d=0,g=0,x=0,p=0,m=0,v=0,_=0,y=0,b=0,T=0,w=0;l.sort(Uw);for(let M=0,S=l.length;M0&&(r.has("OES_texture_float_linear")===!0?(n.rectAreaLTC1=mt.LTC_FLOAT_1,n.rectAreaLTC2=mt.LTC_FLOAT_2):(n.rectAreaLTC1=mt.LTC_HALF_1,n.rectAreaLTC2=mt.LTC_HALF_2)),n.ambient[0]=f,n.ambient[1]=h,n.ambient[2]=u;let E=n.hash;(E.directionalLength!==d||E.pointLength!==g||E.spotLength!==x||E.rectAreaLength!==p||E.hemiLength!==m||E.numDirectionalShadows!==v||E.numPointShadows!==_||E.numSpotShadows!==y||E.numSpotMaps!==b||E.numLightProbes!==w)&&(n.directional.length=d,n.spot.length=x,n.rectArea.length=p,n.point.length=g,n.hemi.length=m,n.directionalShadow.length=v,n.directionalShadowMap.length=v,n.pointShadow.length=_,n.pointShadowMap.length=_,n.spotShadow.length=y,n.spotShadowMap.length=y,n.directionalShadowMatrix.length=v,n.pointShadowMatrix.length=_,n.spotLightMatrix.length=y+b-T,n.spotLightMap.length=b,n.numSpotLightShadowsWithMaps=T,n.numLightProbes=w,E.directionalLength=d,E.pointLength=g,E.spotLength=x,E.rectAreaLength=p,E.hemiLength=m,E.numDirectionalShadows=v,E.numPointShadows=_,E.numSpotShadows=y,E.numSpotMaps=b,E.numLightProbes=w,n.version=Nw++)}function c(l,f){let h=0,u=0,d=0,g=0,x=0,p=f.matrixWorldInverse;for(let m=0,v=l.length;m=o.length?(a=new k0(r),o.push(a)):a=o[s],a}function n(){t=new WeakMap}return{get:e,dispose:n}}var zw=`void main() { + gl_Position = vec4( position, 1.0 ); +}`,kw=`uniform sampler2D shadow_pass; +uniform vec2 resolution; +uniform float radius; +#include +void main() { + const float samples = float( VSM_SAMPLES ); + float mean = 0.0; + float squared_mean = 0.0; + float uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 ); + float uvStart = samples <= 1.0 ? 0.0 : - 1.0; + for ( float i = 0.0; i < samples; i ++ ) { + float uvOffset = uvStart + i * uvStride; + #ifdef HORIZONTAL_PASS + vec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ) ); + mean += distribution.x; + squared_mean += distribution.y * distribution.y + distribution.x * distribution.x; + #else + float depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ) ); + mean += depth; + squared_mean += depth * depth; + #endif + } + mean = mean / samples; + squared_mean = squared_mean / samples; + float std_dev = sqrt( squared_mean - mean * mean ); + gl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) ); +}`;function Vw(r,t,e){let n=new Oi,i=new q,s=new q,o=new Kt,a=new jo({depthPacking:Jg}),c=new ta,l={},f=e.maxTextureSize,h={[yn]:He,[He]:yn,[Sn]:Sn},u=new Ue({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new q},radius:{value:4}},vertexShader:zw,fragmentShader:kw}),d=u.clone();d.defines.HORIZONTAL_PASS=1;let g=new Ft;g.setAttribute("position",new Ot(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));let x=new Me(g,u),p=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=Nd;let m=this.type;this.render=function(T,w,E){if(p.enabled===!1||p.autoUpdate===!1&&p.needsUpdate===!1||T.length===0)return;let M=r.getRenderTarget(),S=r.getActiveCubeFace(),I=r.getActiveMipmapLevel(),P=r.state;P.setBlending(ke),P.buffers.depth.getReversed()===!0?P.buffers.color.setClear(0,0,0,0):P.buffers.color.setClear(1,1,1,1),P.buffers.depth.setTest(!0),P.setScissorTest(!1);let L=m!==oi&&this.type===oi,N=m===oi&&this.type!==oi;for(let z=0,V=T.length;zf||i.y>f)&&(i.x>f&&(s.x=Math.floor(f/ct.x),i.x=s.x*ct.x,W.mapSize.x=s.x),i.y>f&&(s.y=Math.floor(f/ct.y),i.y=s.y*ct.y,W.mapSize.y=s.y)),W.map===null||L===!0||N===!0){let _t=this.type!==oi?{minFilter:Vt,magFilter:Vt}:{};W.map!==null&&W.map.dispose(),W.map=new ze(i.x,i.y,_t),W.map.texture.name=j.name+".shadowMap",W.camera.updateProjectionMatrix()}r.setRenderTarget(W.map),r.clear();let pt=W.getViewportCount();for(let _t=0;_t0||w.map&&w.alphaTest>0||w.alphaToCoverage===!0){let P=S.uuid,L=w.uuid,N=l[P];N===void 0&&(N={},l[P]=N);let z=N[L];z===void 0&&(z=S.clone(),N[L]=z,w.addEventListener("dispose",b)),S=z}if(S.visible=w.visible,S.wireframe=w.wireframe,M===oi?S.side=w.shadowSide!==null?w.shadowSide:w.side:S.side=w.shadowSide!==null?w.shadowSide:h[w.side],S.alphaMap=w.alphaMap,S.alphaTest=w.alphaToCoverage===!0?.5:w.alphaTest,S.map=w.map,S.clipShadows=w.clipShadows,S.clippingPlanes=w.clippingPlanes,S.clipIntersection=w.clipIntersection,S.displacementMap=w.displacementMap,S.displacementScale=w.displacementScale,S.displacementBias=w.displacementBias,S.wireframeLinewidth=w.wireframeLinewidth,S.linewidth=w.linewidth,E.isPointLight===!0&&S.isMeshDistanceMaterial===!0){let P=r.properties.get(S);P.light=E}return S}function y(T,w,E,M,S){if(T.visible===!1)return;if(T.layers.test(w.layers)&&(T.isMesh||T.isLine||T.isPoints)&&(T.castShadow||T.receiveShadow&&S===oi)&&(!T.frustumCulled||n.intersectsObject(T))){T.modelViewMatrix.multiplyMatrices(E.matrixWorldInverse,T.matrixWorld);let L=t.update(T),N=T.material;if(Array.isArray(N)){let z=L.groups;for(let V=0,j=z.length;V=1):W.indexOf("OpenGL ES")!==-1&&(j=parseFloat(/^OpenGL ES (\d)/.exec(W)[1]),V=j>=2);let ct=null,pt={},_t=r.getParameter(r.SCISSOR_BOX),Ht=r.getParameter(r.VIEWPORT),ee=new Kt().fromArray(_t),he=new Kt().fromArray(Ht);function Qt(U,at,dt,Tt){let st=new Uint8Array(4),Q=r.createTexture();r.bindTexture(U,Q),r.texParameteri(U,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(U,r.TEXTURE_MAG_FILTER,r.NEAREST);for(let Ct=0;Ct"u"?!1:/OculusBrowser/g.test(navigator.userAgent),l=new q,f=new WeakMap,h,u=new WeakMap,d=!1;try{d=typeof OffscreenCanvas<"u"&&new OffscreenCanvas(1,1).getContext("2d")!==null}catch{}function g(D,A){return d?new OffscreenCanvas(D,A):_s("canvas")}function x(D,A,k){let X=1,et=Wt(D);if((et.width>k||et.height>k)&&(X=k/Math.max(et.width,et.height)),X<1)if(typeof HTMLImageElement<"u"&&D instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&D instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&D instanceof ImageBitmap||typeof VideoFrame<"u"&&D instanceof VideoFrame){let Y=Math.floor(X*et.width),It=Math.floor(X*et.height);h===void 0&&(h=g(Y,It));let lt=A?g(Y,It):h;return lt.width=Y,lt.height=It,lt.getContext("2d").drawImage(D,0,0,Y,It),console.warn("THREE.WebGLRenderer: Texture has been resized from ("+et.width+"x"+et.height+") to ("+Y+"x"+It+")."),lt}else return"data"in D&&console.warn("THREE.WebGLRenderer: Image in DataTexture is too big ("+et.width+"x"+et.height+")."),D;return D}function p(D){return D.generateMipmaps}function m(D){r.generateMipmap(D)}function v(D){return D.isWebGLCubeRenderTarget?r.TEXTURE_CUBE_MAP:D.isWebGL3DRenderTarget?r.TEXTURE_3D:D.isWebGLArrayRenderTarget||D.isCompressedArrayTexture?r.TEXTURE_2D_ARRAY:r.TEXTURE_2D}function _(D,A,k,X,et=!1){if(D!==null){if(r[D]!==void 0)return r[D];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+D+"'")}let Y=A;if(A===r.RED&&(k===r.FLOAT&&(Y=r.R32F),k===r.HALF_FLOAT&&(Y=r.R16F),k===r.UNSIGNED_BYTE&&(Y=r.R8)),A===r.RED_INTEGER&&(k===r.UNSIGNED_BYTE&&(Y=r.R8UI),k===r.UNSIGNED_SHORT&&(Y=r.R16UI),k===r.UNSIGNED_INT&&(Y=r.R32UI),k===r.BYTE&&(Y=r.R8I),k===r.SHORT&&(Y=r.R16I),k===r.INT&&(Y=r.R32I)),A===r.RG&&(k===r.FLOAT&&(Y=r.RG32F),k===r.HALF_FLOAT&&(Y=r.RG16F),k===r.UNSIGNED_BYTE&&(Y=r.RG8)),A===r.RG_INTEGER&&(k===r.UNSIGNED_BYTE&&(Y=r.RG8UI),k===r.UNSIGNED_SHORT&&(Y=r.RG16UI),k===r.UNSIGNED_INT&&(Y=r.RG32UI),k===r.BYTE&&(Y=r.RG8I),k===r.SHORT&&(Y=r.RG16I),k===r.INT&&(Y=r.RG32I)),A===r.RGB_INTEGER&&(k===r.UNSIGNED_BYTE&&(Y=r.RGB8UI),k===r.UNSIGNED_SHORT&&(Y=r.RGB16UI),k===r.UNSIGNED_INT&&(Y=r.RGB32UI),k===r.BYTE&&(Y=r.RGB8I),k===r.SHORT&&(Y=r.RGB16I),k===r.INT&&(Y=r.RGB32I)),A===r.RGBA_INTEGER&&(k===r.UNSIGNED_BYTE&&(Y=r.RGBA8UI),k===r.UNSIGNED_SHORT&&(Y=r.RGBA16UI),k===r.UNSIGNED_INT&&(Y=r.RGBA32UI),k===r.BYTE&&(Y=r.RGBA8I),k===r.SHORT&&(Y=r.RGBA16I),k===r.INT&&(Y=r.RGBA32I)),A===r.RGB&&(k===r.UNSIGNED_INT_5_9_9_9_REV&&(Y=r.RGB9_E5),k===r.UNSIGNED_INT_10F_11F_11F_REV&&(Y=r.R11F_G11F_B10F)),A===r.RGBA){let It=et?Co:ie.getTransfer(X);k===r.FLOAT&&(Y=r.RGBA32F),k===r.HALF_FLOAT&&(Y=r.RGBA16F),k===r.UNSIGNED_BYTE&&(Y=It===me?r.SRGB8_ALPHA8:r.RGBA8),k===r.UNSIGNED_SHORT_4_4_4_4&&(Y=r.RGBA4),k===r.UNSIGNED_SHORT_5_5_5_1&&(Y=r.RGB5_A1)}return(Y===r.R16F||Y===r.R32F||Y===r.RG16F||Y===r.RG32F||Y===r.RGBA16F||Y===r.RGBA32F)&&t.get("EXT_color_buffer_float"),Y}function y(D,A){let k;return D?A===null||A===an||A===Os?k=r.DEPTH24_STENCIL8:A===$t?k=r.DEPTH32F_STENCIL8:A===Hi&&(k=r.DEPTH24_STENCIL8,console.warn("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):A===null||A===an||A===Os?k=r.DEPTH_COMPONENT24:A===$t?k=r.DEPTH_COMPONENT32F:A===Hi&&(k=r.DEPTH_COMPONENT16),k}function b(D,A){return p(D)===!0||D.isFramebufferTexture&&D.minFilter!==Vt&&D.minFilter!==re?Math.log2(Math.max(A.width,A.height))+1:D.mipmaps!==void 0&&D.mipmaps.length>0?D.mipmaps.length:D.isCompressedTexture&&Array.isArray(D.image)?A.mipmaps.length:1}function T(D){let A=D.target;A.removeEventListener("dispose",T),E(A),A.isVideoTexture&&f.delete(A)}function w(D){let A=D.target;A.removeEventListener("dispose",w),S(A)}function E(D){let A=n.get(D);if(A.__webglInit===void 0)return;let k=D.source,X=u.get(k);if(X){let et=X[A.__cacheKey];et.usedTimes--,et.usedTimes===0&&M(D),Object.keys(X).length===0&&u.delete(k)}n.remove(D)}function M(D){let A=n.get(D);r.deleteTexture(A.__webglTexture);let k=D.source,X=u.get(k);delete X[A.__cacheKey],o.memory.textures--}function S(D){let A=n.get(D);if(D.depthTexture&&(D.depthTexture.dispose(),n.remove(D.depthTexture)),D.isWebGLCubeRenderTarget)for(let X=0;X<6;X++){if(Array.isArray(A.__webglFramebuffer[X]))for(let et=0;et=i.maxTextures&&console.warn("THREE.WebGLTextures: Trying to use "+D+" texture units while this GPU supports only "+i.maxTextures),I+=1,D}function N(D){let A=[];return A.push(D.wrapS),A.push(D.wrapT),A.push(D.wrapR||0),A.push(D.magFilter),A.push(D.minFilter),A.push(D.anisotropy),A.push(D.internalFormat),A.push(D.format),A.push(D.type),A.push(D.generateMipmaps),A.push(D.premultiplyAlpha),A.push(D.flipY),A.push(D.unpackAlignment),A.push(D.colorSpace),A.join()}function z(D,A){let k=n.get(D);if(D.isVideoTexture&&ht(D),D.isRenderTargetTexture===!1&&D.isExternalTexture!==!0&&D.version>0&&k.__version!==D.version){let X=D.image;if(X===null)console.warn("THREE.WebGLRenderer: Texture marked for update but no image data found.");else if(X.complete===!1)console.warn("THREE.WebGLRenderer: Texture marked for update but image is incomplete");else{$(k,D,A);return}}else D.isExternalTexture&&(k.__webglTexture=D.sourceTexture?D.sourceTexture:null);e.bindTexture(r.TEXTURE_2D,k.__webglTexture,r.TEXTURE0+A)}function V(D,A){let k=n.get(D);if(D.isRenderTargetTexture===!1&&D.version>0&&k.__version!==D.version){$(k,D,A);return}e.bindTexture(r.TEXTURE_2D_ARRAY,k.__webglTexture,r.TEXTURE0+A)}function j(D,A){let k=n.get(D);if(D.isRenderTargetTexture===!1&&D.version>0&&k.__version!==D.version){$(k,D,A);return}e.bindTexture(r.TEXTURE_3D,k.__webglTexture,r.TEXTURE0+A)}function W(D,A){let k=n.get(D);if(D.version>0&&k.__version!==D.version){tt(k,D,A);return}e.bindTexture(r.TEXTURE_CUBE_MAP,k.__webglTexture,r.TEXTURE0+A)}let ct={[Ke]:r.REPEAT,[we]:r.CLAMP_TO_EDGE,[Ao]:r.MIRRORED_REPEAT},pt={[Vt]:r.NEAREST,[Od]:r.NEAREST_MIPMAP_NEAREST,[Us]:r.NEAREST_MIPMAP_LINEAR,[re]:r.LINEAR,[fa]:r.LINEAR_MIPMAP_NEAREST,[ai]:r.LINEAR_MIPMAP_LINEAR},_t={[Qg]:r.NEVER,[r0]:r.ALWAYS,[jg]:r.LESS,[Xd]:r.LEQUAL,[t0]:r.EQUAL,[i0]:r.GEQUAL,[e0]:r.GREATER,[n0]:r.NOTEQUAL};function Ht(D,A){if(A.type===$t&&t.has("OES_texture_float_linear")===!1&&(A.magFilter===re||A.magFilter===fa||A.magFilter===Us||A.magFilter===ai||A.minFilter===re||A.minFilter===fa||A.minFilter===Us||A.minFilter===ai)&&console.warn("THREE.WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),r.texParameteri(D,r.TEXTURE_WRAP_S,ct[A.wrapS]),r.texParameteri(D,r.TEXTURE_WRAP_T,ct[A.wrapT]),(D===r.TEXTURE_3D||D===r.TEXTURE_2D_ARRAY)&&r.texParameteri(D,r.TEXTURE_WRAP_R,ct[A.wrapR]),r.texParameteri(D,r.TEXTURE_MAG_FILTER,pt[A.magFilter]),r.texParameteri(D,r.TEXTURE_MIN_FILTER,pt[A.minFilter]),A.compareFunction&&(r.texParameteri(D,r.TEXTURE_COMPARE_MODE,r.COMPARE_REF_TO_TEXTURE),r.texParameteri(D,r.TEXTURE_COMPARE_FUNC,_t[A.compareFunction])),t.has("EXT_texture_filter_anisotropic")===!0){if(A.magFilter===Vt||A.minFilter!==Us&&A.minFilter!==ai||A.type===$t&&t.has("OES_texture_float_linear")===!1)return;if(A.anisotropy>1||n.get(A).__currentAnisotropy){let k=t.get("EXT_texture_filter_anisotropic");r.texParameterf(D,k.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(A.anisotropy,i.getMaxAnisotropy())),n.get(A).__currentAnisotropy=A.anisotropy}}}function ee(D,A){let k=!1;D.__webglInit===void 0&&(D.__webglInit=!0,A.addEventListener("dispose",T));let X=A.source,et=u.get(X);et===void 0&&(et={},u.set(X,et));let Y=N(A);if(Y!==D.__cacheKey){et[Y]===void 0&&(et[Y]={texture:r.createTexture(),usedTimes:0},o.memory.textures++,k=!0),et[Y].usedTimes++;let It=et[D.__cacheKey];It!==void 0&&(et[D.__cacheKey].usedTimes--,It.usedTimes===0&&M(A)),D.__cacheKey=Y,D.__webglTexture=et[Y].texture}return k}function he(D,A,k){return Math.floor(Math.floor(D/k)/A)}function Qt(D,A,k,X){let Y=D.updateRanges;if(Y.length===0)e.texSubImage2D(r.TEXTURE_2D,0,0,0,A.width,A.height,k,X,A.data);else{Y.sort((rt,yt)=>rt.start-yt.start);let It=0;for(let rt=1;rt0){U&&at&&e.texStorage2D(r.TEXTURE_2D,Tt,Dt,Jt[0].width,Jt[0].height);for(let st=0,Q=Jt.length;st0){let Ct=Tu(xt.width,xt.height,A.format,A.type);for(let Yt of A.layerUpdates){let Se=xt.data.subarray(Yt*Ct/xt.data.BYTES_PER_ELEMENT,(Yt+1)*Ct/xt.data.BYTES_PER_ELEMENT);e.compressedTexSubImage3D(r.TEXTURE_2D_ARRAY,st,0,0,Yt,xt.width,xt.height,1,yt,Se)}A.clearLayerUpdates()}else e.compressedTexSubImage3D(r.TEXTURE_2D_ARRAY,st,0,0,0,xt.width,xt.height,rt.depth,yt,xt.data)}else e.compressedTexImage3D(r.TEXTURE_2D_ARRAY,st,Dt,xt.width,xt.height,rt.depth,0,xt.data,0,0);else console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");else U?dt&&e.texSubImage3D(r.TEXTURE_2D_ARRAY,st,0,0,0,xt.width,xt.height,rt.depth,yt,zt,xt.data):e.texImage3D(r.TEXTURE_2D_ARRAY,st,Dt,xt.width,xt.height,rt.depth,0,yt,zt,xt.data)}else{U&&at&&e.texStorage2D(r.TEXTURE_2D,Tt,Dt,Jt[0].width,Jt[0].height);for(let st=0,Q=Jt.length;st0){let st=Tu(rt.width,rt.height,A.format,A.type);for(let Q of A.layerUpdates){let Ct=rt.data.subarray(Q*st/rt.data.BYTES_PER_ELEMENT,(Q+1)*st/rt.data.BYTES_PER_ELEMENT);e.texSubImage3D(r.TEXTURE_2D_ARRAY,0,0,0,Q,rt.width,rt.height,1,yt,zt,Ct)}A.clearLayerUpdates()}else e.texSubImage3D(r.TEXTURE_2D_ARRAY,0,0,0,0,rt.width,rt.height,rt.depth,yt,zt,rt.data)}else e.texImage3D(r.TEXTURE_2D_ARRAY,0,Dt,rt.width,rt.height,rt.depth,0,yt,zt,rt.data);else if(A.isData3DTexture)U?(at&&e.texStorage3D(r.TEXTURE_3D,Tt,Dt,rt.width,rt.height,rt.depth),dt&&e.texSubImage3D(r.TEXTURE_3D,0,0,0,0,rt.width,rt.height,rt.depth,yt,zt,rt.data)):e.texImage3D(r.TEXTURE_3D,0,Dt,rt.width,rt.height,rt.depth,0,yt,zt,rt.data);else if(A.isFramebufferTexture){if(at)if(U)e.texStorage2D(r.TEXTURE_2D,Tt,Dt,rt.width,rt.height);else{let st=rt.width,Q=rt.height;for(let Ct=0;Ct>=1,Q>>=1}}else if(Jt.length>0){if(U&&at){let st=Wt(Jt[0]);e.texStorage2D(r.TEXTURE_2D,Tt,Dt,st.width,st.height)}for(let st=0,Q=Jt.length;st0&&Tt++;let Q=Wt(yt[0]);e.texStorage2D(r.TEXTURE_CUBE_MAP,Tt,Jt,Q.width,Q.height)}for(let Q=0;Q<6;Q++)if(rt){U?dt&&e.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+Q,0,0,0,yt[Q].width,yt[Q].height,Dt,xt,yt[Q].data):e.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+Q,0,Jt,yt[Q].width,yt[Q].height,0,Dt,xt,yt[Q].data);for(let Ct=0;Ct>Y),zt=Math.max(1,A.height>>Y);et===r.TEXTURE_3D||et===r.TEXTURE_2D_ARRAY?e.texImage3D(et,Y,Et,yt,zt,A.depth,0,It,lt,null):e.texImage2D(et,Y,Et,yt,zt,0,It,lt,null)}e.bindFramebuffer(r.FRAMEBUFFER,D),it(A)?a.framebufferTexture2DMultisampleEXT(r.FRAMEBUFFER,X,et,rt.__webglTexture,0,ut(A)):(et===r.TEXTURE_2D||et>=r.TEXTURE_CUBE_MAP_POSITIVE_X&&et<=r.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&r.framebufferTexture2D(r.FRAMEBUFFER,X,et,rt.__webglTexture,Y),e.bindFramebuffer(r.FRAMEBUFFER,null)}function Pt(D,A,k){if(r.bindRenderbuffer(r.RENDERBUFFER,D),A.depthBuffer){let X=A.depthTexture,et=X&&X.isDepthTexture?X.type:null,Y=y(A.stencilBuffer,et),It=A.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT,lt=ut(A);it(A)?a.renderbufferStorageMultisampleEXT(r.RENDERBUFFER,lt,Y,A.width,A.height):k?r.renderbufferStorageMultisample(r.RENDERBUFFER,lt,Y,A.width,A.height):r.renderbufferStorage(r.RENDERBUFFER,Y,A.width,A.height),r.framebufferRenderbuffer(r.FRAMEBUFFER,It,r.RENDERBUFFER,D)}else{let X=A.textures;for(let et=0;et{delete A.__boundDepthTexture,delete A.__depthDisposeCallback,X.removeEventListener("dispose",et)};X.addEventListener("dispose",et),A.__depthDisposeCallback=et}A.__boundDepthTexture=X}if(D.depthTexture&&!A.__autoAllocateDepthBuffer){if(k)throw new Error("target.depthTexture not supported in Cube render targets");let X=D.texture.mipmaps;X&&X.length>0?wt(A.__webglFramebuffer[0],D):wt(A.__webglFramebuffer,D)}else if(k){A.__webglDepthbuffer=[];for(let X=0;X<6;X++)if(e.bindFramebuffer(r.FRAMEBUFFER,A.__webglFramebuffer[X]),A.__webglDepthbuffer[X]===void 0)A.__webglDepthbuffer[X]=r.createRenderbuffer(),Pt(A.__webglDepthbuffer[X],D,!1);else{let et=D.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT,Y=A.__webglDepthbuffer[X];r.bindRenderbuffer(r.RENDERBUFFER,Y),r.framebufferRenderbuffer(r.FRAMEBUFFER,et,r.RENDERBUFFER,Y)}}else{let X=D.texture.mipmaps;if(X&&X.length>0?e.bindFramebuffer(r.FRAMEBUFFER,A.__webglFramebuffer[0]):e.bindFramebuffer(r.FRAMEBUFFER,A.__webglFramebuffer),A.__webglDepthbuffer===void 0)A.__webglDepthbuffer=r.createRenderbuffer(),Pt(A.__webglDepthbuffer,D,!1);else{let et=D.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT,Y=A.__webglDepthbuffer;r.bindRenderbuffer(r.RENDERBUFFER,Y),r.framebufferRenderbuffer(r.FRAMEBUFFER,et,r.RENDERBUFFER,Y)}}e.bindFramebuffer(r.FRAMEBUFFER,null)}function fe(D,A,k){let X=n.get(D);A!==void 0&&St(X.__webglFramebuffer,D,D.texture,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,0),k!==void 0&&te(D)}function F(D){let A=D.texture,k=n.get(D),X=n.get(A);D.addEventListener("dispose",w);let et=D.textures,Y=D.isWebGLCubeRenderTarget===!0,It=et.length>1;if(It||(X.__webglTexture===void 0&&(X.__webglTexture=r.createTexture()),X.__version=A.version,o.memory.textures++),Y){k.__webglFramebuffer=[];for(let lt=0;lt<6;lt++)if(A.mipmaps&&A.mipmaps.length>0){k.__webglFramebuffer[lt]=[];for(let Et=0;Et0){k.__webglFramebuffer=[];for(let lt=0;lt0&&it(D)===!1){k.__webglMultisampledFramebuffer=r.createFramebuffer(),k.__webglColorRenderbuffer=[],e.bindFramebuffer(r.FRAMEBUFFER,k.__webglMultisampledFramebuffer);for(let lt=0;lt0)for(let Et=0;Et0)for(let Et=0;Et0){if(it(D)===!1){let A=D.textures,k=D.width,X=D.height,et=r.COLOR_BUFFER_BIT,Y=D.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT,It=n.get(D),lt=A.length>1;if(lt)for(let Rt=0;Rt0?e.bindFramebuffer(r.DRAW_FRAMEBUFFER,It.__webglFramebuffer[0]):e.bindFramebuffer(r.DRAW_FRAMEBUFFER,It.__webglFramebuffer);for(let Rt=0;Rt0&&t.has("WEBGL_multisampled_render_to_texture")===!0&&A.__useRenderToTexture!==!1}function ht(D){let A=o.render.frame;f.get(D)!==A&&(f.set(D,A),D.update())}function qt(D,A){let k=D.colorSpace,X=D.format,et=D.type;return D.isCompressedTexture===!0||D.isVideoTexture===!0||k!==yr&&k!==Ti&&(ie.getTransfer(k)===me?(X!==Gt||et!==on)&&console.warn("THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):console.error("THREE.WebGLTextures: Unsupported texture color space:",k)),A}function Wt(D){return typeof HTMLImageElement<"u"&&D instanceof HTMLImageElement?(l.width=D.naturalWidth||D.width,l.height=D.naturalHeight||D.height):typeof VideoFrame<"u"&&D instanceof VideoFrame?(l.width=D.displayWidth,l.height=D.displayHeight):(l.width=D.width,l.height=D.height),l}this.allocateTextureUnit=L,this.resetTextureUnits=P,this.setTexture2D=z,this.setTexture2DArray=V,this.setTexture3D=j,this.setTextureCube=W,this.rebindTextures=fe,this.setupRenderTarget=F,this.updateRenderTargetMipmap=nt,this.updateMultisampleRenderTarget=Z,this.setupDepthRenderbuffer=te,this.setupFrameBufferTexture=St,this.useMultisampledRTT=it}function Xw(r,t){function e(n,i=Ti){let s,o=ie.getTransfer(i);if(n===on)return r.UNSIGNED_BYTE;if(n===Yl)return r.UNSIGNED_SHORT_4_4_4_4;if(n===$l)return r.UNSIGNED_SHORT_5_5_5_1;if(n===kd)return r.UNSIGNED_INT_5_9_9_9_REV;if(n===Vd)return r.UNSIGNED_INT_10F_11F_11F_REV;if(n===Bs)return r.BYTE;if(n===da)return r.SHORT;if(n===Hi)return r.UNSIGNED_SHORT;if(n===Gi)return r.INT;if(n===an)return r.UNSIGNED_INT;if(n===$t)return r.FLOAT;if(n===Ge)return r.HALF_FLOAT;if(n===Hd)return r.ALPHA;if(n===Gd)return r.RGB;if(n===Gt)return r.RGBA;if(n===xs)return r.DEPTH_COMPONENT;if(n===zs)return r.DEPTH_STENCIL;if(n===Jn)return r.RED;if(n===Dr)return r.RED_INTEGER;if(n===Fr)return r.RG;if(n===Wi)return r.RG_INTEGER;if(n===Xi)return r.RGBA_INTEGER;if(n===pa||n===ma||n===ga||n===xa)if(o===me)if(s=t.get("WEBGL_compressed_texture_s3tc_srgb"),s!==null){if(n===pa)return s.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(n===ma)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(n===ga)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(n===xa)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(s=t.get("WEBGL_compressed_texture_s3tc"),s!==null){if(n===pa)return s.COMPRESSED_RGB_S3TC_DXT1_EXT;if(n===ma)return s.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(n===ga)return s.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(n===xa)return s.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(n===Zl||n===Jl||n===Kl||n===Ql)if(s=t.get("WEBGL_compressed_texture_pvrtc"),s!==null){if(n===Zl)return s.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(n===Jl)return s.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(n===Kl)return s.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(n===Ql)return s.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(n===jl||n===tu||n===eu)if(s=t.get("WEBGL_compressed_texture_etc"),s!==null){if(n===jl||n===tu)return o===me?s.COMPRESSED_SRGB8_ETC2:s.COMPRESSED_RGB8_ETC2;if(n===eu)return o===me?s.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:s.COMPRESSED_RGBA8_ETC2_EAC}else return null;if(n===nu||n===iu||n===ru||n===su||n===ou||n===au||n===cu||n===lu||n===uu||n===hu||n===fu||n===du||n===pu||n===mu)if(s=t.get("WEBGL_compressed_texture_astc"),s!==null){if(n===nu)return o===me?s.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:s.COMPRESSED_RGBA_ASTC_4x4_KHR;if(n===iu)return o===me?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:s.COMPRESSED_RGBA_ASTC_5x4_KHR;if(n===ru)return o===me?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:s.COMPRESSED_RGBA_ASTC_5x5_KHR;if(n===su)return o===me?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:s.COMPRESSED_RGBA_ASTC_6x5_KHR;if(n===ou)return o===me?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:s.COMPRESSED_RGBA_ASTC_6x6_KHR;if(n===au)return o===me?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:s.COMPRESSED_RGBA_ASTC_8x5_KHR;if(n===cu)return o===me?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:s.COMPRESSED_RGBA_ASTC_8x6_KHR;if(n===lu)return o===me?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:s.COMPRESSED_RGBA_ASTC_8x8_KHR;if(n===uu)return o===me?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:s.COMPRESSED_RGBA_ASTC_10x5_KHR;if(n===hu)return o===me?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:s.COMPRESSED_RGBA_ASTC_10x6_KHR;if(n===fu)return o===me?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:s.COMPRESSED_RGBA_ASTC_10x8_KHR;if(n===du)return o===me?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:s.COMPRESSED_RGBA_ASTC_10x10_KHR;if(n===pu)return o===me?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:s.COMPRESSED_RGBA_ASTC_12x10_KHR;if(n===mu)return o===me?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:s.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(n===gu||n===xu||n===vu)if(s=t.get("EXT_texture_compression_bptc"),s!==null){if(n===gu)return o===me?s.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:s.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(n===xu)return s.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(n===vu)return s.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(n===_u||n===yu||n===bu||n===Su)if(s=t.get("EXT_texture_compression_rgtc"),s!==null){if(n===_u)return s.COMPRESSED_RED_RGTC1_EXT;if(n===yu)return s.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(n===bu)return s.COMPRESSED_RED_GREEN_RGTC2_EXT;if(n===Su)return s.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return n===Os?r.UNSIGNED_INT_24_8:r[n]!==void 0?r[n]:null}return{convert:e}}var qw=` +void main() { + + gl_Position = vec4( position, 1.0 ); + +}`,Yw=` +uniform sampler2DArray depthColor; +uniform float depthWidth; +uniform float depthHeight; + +void main() { + + vec2 coord = vec2( gl_FragCoord.x / depthWidth, gl_FragCoord.y / depthHeight ); + + if ( coord.x >= 1.0 ) { + + gl_FragDepth = texture( depthColor, vec3( coord.x - 1.0, coord.y, 1 ) ).r; + + } else { + + gl_FragDepth = texture( depthColor, vec3( coord.x, coord.y, 0 ) ).r; + + } + +}`,fp=class{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(t,e){if(this.texture===null){let n=new zo(t.texture);(t.depthNear!==e.depthNear||t.depthFar!==e.depthFar)&&(this.depthNear=t.depthNear,this.depthFar=t.depthFar),this.texture=n}}getMesh(t){if(this.texture!==null&&this.mesh===null){let e=t.cameras[0].viewport,n=new Ue({vertexShader:qw,fragmentShader:Yw,uniforms:{depthColor:{value:this.texture},depthWidth:{value:e.z},depthHeight:{value:e.w}}});this.mesh=new Me(new Ps(20,20),n)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}},dp=class extends On{constructor(t,e){super();let n=this,i=null,s=1,o=null,a="local-floor",c=1,l=null,f=null,h=null,u=null,d=null,g=null,x=typeof XRWebGLBinding<"u",p=new fp,m={},v=e.getContextAttributes(),_=null,y=null,b=[],T=[],w=new q,E=null,M=new Re;M.viewport=new Kt;let S=new Re;S.viewport=new Kt;let I=[M,S],P=new Nl,L=null,N=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function($){let tt=b[$];return tt===void 0&&(tt=new Ts,b[$]=tt),tt.getTargetRaySpace()},this.getControllerGrip=function($){let tt=b[$];return tt===void 0&&(tt=new Ts,b[$]=tt),tt.getGripSpace()},this.getHand=function($){let tt=b[$];return tt===void 0&&(tt=new Ts,b[$]=tt),tt.getHandSpace()};function z($){let tt=T.indexOf($.inputSource);if(tt===-1)return;let St=b[tt];St!==void 0&&(St.update($.inputSource,$.frame,l||o),St.dispatchEvent({type:$.type,data:$.inputSource}))}function V(){i.removeEventListener("select",z),i.removeEventListener("selectstart",z),i.removeEventListener("selectend",z),i.removeEventListener("squeeze",z),i.removeEventListener("squeezestart",z),i.removeEventListener("squeezeend",z),i.removeEventListener("end",V),i.removeEventListener("inputsourceschange",j);for(let $=0;$=0&&(T[Pt]=null,b[Pt].disconnect(St))}for(let tt=0;tt<$.added.length;tt++){let St=$.added[tt],Pt=T.indexOf(St);if(Pt===-1){for(let te=0;te=T.length){T.push(St),Pt=te;break}else if(T[te]===null){T[te]=St,Pt=te;break}if(Pt===-1)break}let wt=b[Pt];wt&&wt.connect(St)}}let W=new R,ct=new R;function pt($,tt,St){W.setFromMatrixPosition(tt.matrixWorld),ct.setFromMatrixPosition(St.matrixWorld);let Pt=W.distanceTo(ct),wt=tt.projectionMatrix.elements,te=St.projectionMatrix.elements,fe=wt[14]/(wt[10]-1),F=wt[14]/(wt[10]+1),nt=(wt[9]+1)/wt[5],K=(wt[9]-1)/wt[5],J=(wt[8]-1)/wt[0],Z=(te[8]+1)/te[0],ut=fe*J,it=fe*Z,ht=Pt/(-J+Z),qt=ht*-J;if(tt.matrixWorld.decompose($.position,$.quaternion,$.scale),$.translateX(qt),$.translateZ(ht),$.matrixWorld.compose($.position,$.quaternion,$.scale),$.matrixWorldInverse.copy($.matrixWorld).invert(),wt[10]===-1)$.projectionMatrix.copy(tt.projectionMatrix),$.projectionMatrixInverse.copy(tt.projectionMatrixInverse);else{let Wt=fe+ht,D=F+ht,A=ut-qt,k=it+(Pt-qt),X=nt*F/D*Wt,et=K*F/D*Wt;$.projectionMatrix.makePerspective(A,k,X,et,Wt,D),$.projectionMatrixInverse.copy($.projectionMatrix).invert()}}function _t($,tt){tt===null?$.matrixWorld.copy($.matrix):$.matrixWorld.multiplyMatrices(tt.matrixWorld,$.matrix),$.matrixWorldInverse.copy($.matrixWorld).invert()}this.updateCamera=function($){if(i===null)return;let tt=$.near,St=$.far;p.texture!==null&&(p.depthNear>0&&(tt=p.depthNear),p.depthFar>0&&(St=p.depthFar)),P.near=S.near=M.near=tt,P.far=S.far=M.far=St,(L!==P.near||N!==P.far)&&(i.updateRenderState({depthNear:P.near,depthFar:P.far}),L=P.near,N=P.far),P.layers.mask=$.layers.mask|6,M.layers.mask=P.layers.mask&3,S.layers.mask=P.layers.mask&5;let Pt=$.parent,wt=P.cameras;_t(P,Pt);for(let te=0;te0&&(p.alphaTest.value=m.alphaTest);let v=t.get(m),_=v.envMap,y=v.envMapRotation;_&&(p.envMap.value=_,Ur.copy(y),Ur.x*=-1,Ur.y*=-1,Ur.z*=-1,_.isCubeTexture&&_.isRenderTargetTexture===!1&&(Ur.y*=-1,Ur.z*=-1),p.envMapRotation.value.setFromMatrix4($w.makeRotationFromEuler(Ur)),p.flipEnvMap.value=_.isCubeTexture&&_.isRenderTargetTexture===!1?-1:1,p.reflectivity.value=m.reflectivity,p.ior.value=m.ior,p.refractionRatio.value=m.refractionRatio),m.lightMap&&(p.lightMap.value=m.lightMap,p.lightMapIntensity.value=m.lightMapIntensity,e(m.lightMap,p.lightMapTransform)),m.aoMap&&(p.aoMap.value=m.aoMap,p.aoMapIntensity.value=m.aoMapIntensity,e(m.aoMap,p.aoMapTransform))}function o(p,m){p.diffuse.value.copy(m.color),p.opacity.value=m.opacity,m.map&&(p.map.value=m.map,e(m.map,p.mapTransform))}function a(p,m){p.dashSize.value=m.dashSize,p.totalSize.value=m.dashSize+m.gapSize,p.scale.value=m.scale}function c(p,m,v,_){p.diffuse.value.copy(m.color),p.opacity.value=m.opacity,p.size.value=m.size*v,p.scale.value=_*.5,m.map&&(p.map.value=m.map,e(m.map,p.uvTransform)),m.alphaMap&&(p.alphaMap.value=m.alphaMap,e(m.alphaMap,p.alphaMapTransform)),m.alphaTest>0&&(p.alphaTest.value=m.alphaTest)}function l(p,m){p.diffuse.value.copy(m.color),p.opacity.value=m.opacity,p.rotation.value=m.rotation,m.map&&(p.map.value=m.map,e(m.map,p.mapTransform)),m.alphaMap&&(p.alphaMap.value=m.alphaMap,e(m.alphaMap,p.alphaMapTransform)),m.alphaTest>0&&(p.alphaTest.value=m.alphaTest)}function f(p,m){p.specular.value.copy(m.specular),p.shininess.value=Math.max(m.shininess,1e-4)}function h(p,m){m.gradientMap&&(p.gradientMap.value=m.gradientMap)}function u(p,m){p.metalness.value=m.metalness,m.metalnessMap&&(p.metalnessMap.value=m.metalnessMap,e(m.metalnessMap,p.metalnessMapTransform)),p.roughness.value=m.roughness,m.roughnessMap&&(p.roughnessMap.value=m.roughnessMap,e(m.roughnessMap,p.roughnessMapTransform)),m.envMap&&(p.envMapIntensity.value=m.envMapIntensity)}function d(p,m,v){p.ior.value=m.ior,m.sheen>0&&(p.sheenColor.value.copy(m.sheenColor).multiplyScalar(m.sheen),p.sheenRoughness.value=m.sheenRoughness,m.sheenColorMap&&(p.sheenColorMap.value=m.sheenColorMap,e(m.sheenColorMap,p.sheenColorMapTransform)),m.sheenRoughnessMap&&(p.sheenRoughnessMap.value=m.sheenRoughnessMap,e(m.sheenRoughnessMap,p.sheenRoughnessMapTransform))),m.clearcoat>0&&(p.clearcoat.value=m.clearcoat,p.clearcoatRoughness.value=m.clearcoatRoughness,m.clearcoatMap&&(p.clearcoatMap.value=m.clearcoatMap,e(m.clearcoatMap,p.clearcoatMapTransform)),m.clearcoatRoughnessMap&&(p.clearcoatRoughnessMap.value=m.clearcoatRoughnessMap,e(m.clearcoatRoughnessMap,p.clearcoatRoughnessMapTransform)),m.clearcoatNormalMap&&(p.clearcoatNormalMap.value=m.clearcoatNormalMap,e(m.clearcoatNormalMap,p.clearcoatNormalMapTransform),p.clearcoatNormalScale.value.copy(m.clearcoatNormalScale),m.side===He&&p.clearcoatNormalScale.value.negate())),m.dispersion>0&&(p.dispersion.value=m.dispersion),m.iridescence>0&&(p.iridescence.value=m.iridescence,p.iridescenceIOR.value=m.iridescenceIOR,p.iridescenceThicknessMinimum.value=m.iridescenceThicknessRange[0],p.iridescenceThicknessMaximum.value=m.iridescenceThicknessRange[1],m.iridescenceMap&&(p.iridescenceMap.value=m.iridescenceMap,e(m.iridescenceMap,p.iridescenceMapTransform)),m.iridescenceThicknessMap&&(p.iridescenceThicknessMap.value=m.iridescenceThicknessMap,e(m.iridescenceThicknessMap,p.iridescenceThicknessMapTransform))),m.transmission>0&&(p.transmission.value=m.transmission,p.transmissionSamplerMap.value=v.texture,p.transmissionSamplerSize.value.set(v.width,v.height),m.transmissionMap&&(p.transmissionMap.value=m.transmissionMap,e(m.transmissionMap,p.transmissionMapTransform)),p.thickness.value=m.thickness,m.thicknessMap&&(p.thicknessMap.value=m.thicknessMap,e(m.thicknessMap,p.thicknessMapTransform)),p.attenuationDistance.value=m.attenuationDistance,p.attenuationColor.value.copy(m.attenuationColor)),m.anisotropy>0&&(p.anisotropyVector.value.set(m.anisotropy*Math.cos(m.anisotropyRotation),m.anisotropy*Math.sin(m.anisotropyRotation)),m.anisotropyMap&&(p.anisotropyMap.value=m.anisotropyMap,e(m.anisotropyMap,p.anisotropyMapTransform))),p.specularIntensity.value=m.specularIntensity,p.specularColor.value.copy(m.specularColor),m.specularColorMap&&(p.specularColorMap.value=m.specularColorMap,e(m.specularColorMap,p.specularColorMapTransform)),m.specularIntensityMap&&(p.specularIntensityMap.value=m.specularIntensityMap,e(m.specularIntensityMap,p.specularIntensityMapTransform))}function g(p,m){m.matcap&&(p.matcap.value=m.matcap)}function x(p,m){let v=t.get(m).light;p.referencePosition.value.setFromMatrixPosition(v.matrixWorld),p.nearDistance.value=v.shadow.camera.near,p.farDistance.value=v.shadow.camera.far}return{refreshFogUniforms:n,refreshMaterialUniforms:i}}function Jw(r,t,e,n){let i={},s={},o=[],a=r.getParameter(r.MAX_UNIFORM_BUFFER_BINDINGS);function c(v,_){let y=_.program;n.uniformBlockBinding(v,y)}function l(v,_){let y=i[v.id];y===void 0&&(g(v),y=f(v),i[v.id]=y,v.addEventListener("dispose",p));let b=_.program;n.updateUBOMapping(v,b);let T=t.render.frame;s[v.id]!==T&&(u(v),s[v.id]=T)}function f(v){let _=h();v.__bindingPointIndex=_;let y=r.createBuffer(),b=v.__size,T=v.usage;return r.bindBuffer(r.UNIFORM_BUFFER,y),r.bufferData(r.UNIFORM_BUFFER,b,T),r.bindBuffer(r.UNIFORM_BUFFER,null),r.bindBufferBase(r.UNIFORM_BUFFER,_,y),y}function h(){for(let v=0;v0&&(y+=b-T),v.__size=y,v.__cache={},this}function x(v){let _={boundary:0,storage:0};return typeof v=="number"||typeof v=="boolean"?(_.boundary=4,_.storage=4):v.isVector2?(_.boundary=8,_.storage=8):v.isVector3||v.isColor?(_.boundary=16,_.storage=12):v.isVector4?(_.boundary=16,_.storage=16):v.isMatrix3?(_.boundary=48,_.storage=48):v.isMatrix4?(_.boundary=64,_.storage=64):v.isTexture?console.warn("THREE.WebGLRenderer: Texture samplers can not be part of an uniforms group."):console.warn("THREE.WebGLRenderer: Unsupported uniform value type.",v),_}function p(v){let _=v.target;_.removeEventListener("dispose",p);let y=o.indexOf(_.__bindingPointIndex);o.splice(y,1),r.deleteBuffer(i[_.id]),delete i[_.id],delete s[_.id]}function m(){for(let v in i)r.deleteBuffer(i[v]);o=[],i={},s={}}return{bind:c,update:l,dispose:m}}var V0=class{constructor(t={}){let{canvas:e=s0(),context:n=null,depth:i=!0,stencil:s=!1,alpha:o=!1,antialias:a=!1,premultipliedAlpha:c=!0,preserveDrawingBuffer:l=!1,powerPreference:f="default",failIfMajorPerformanceCaveat:h=!1,reversedDepthBuffer:u=!1}=t;this.isWebGLRenderer=!0;let d;if(n!==null){if(typeof WebGLRenderingContext<"u"&&n instanceof WebGLRenderingContext)throw new Error("THREE.WebGLRenderer: WebGL 1 is not supported since r163.");d=n.getContextAttributes().alpha}else d=o;let g=new Uint32Array(4),x=new Int32Array(4),p=null,m=null,v=[],_=[];this.domElement=e,this.debug={checkShaderErrors:!0,onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this.toneMapping=Zn,this.toneMappingExposure=1,this.transmissionResolutionScale=1;let y=this,b=!1;this._outputColorSpace=vn;let T=0,w=0,E=null,M=-1,S=null,I=new Kt,P=new Kt,L=null,N=new ft(0),z=0,V=e.width,j=e.height,W=1,ct=null,pt=null,_t=new Kt(0,0,V,j),Ht=new Kt(0,0,V,j),ee=!1,he=new Oi,Qt=!1,$=!1,tt=new gt,St=new R,Pt=new Kt,wt={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0},te=!1;function fe(){return E===null?W:1}let F=n;function nt(C,B){return e.getContext(C,B)}try{let C={alpha:!0,depth:i,stencil:s,antialias:a,premultipliedAlpha:c,preserveDrawingBuffer:l,powerPreference:f,failIfMajorPerformanceCaveat:h};if("setAttribute"in e&&e.setAttribute("data-engine",`three.js r${"180"}`),e.addEventListener("webglcontextlost",dt,!1),e.addEventListener("webglcontextrestored",Tt,!1),e.addEventListener("webglcontextcreationerror",st,!1),F===null){let B="webgl2";if(F=nt(B,C),F===null)throw nt(B)?new Error("Error creating WebGL context with your selected attributes."):new Error("Error creating WebGL context.")}}catch(C){throw console.error("THREE.WebGLRenderer: "+C.message),C}let K,J,Z,ut,it,ht,qt,Wt,D,A,k,X,et,Y,It,lt,Et,Rt,rt,yt,zt,Dt,xt,Jt;function U(){K=new pT(F),K.init(),Dt=new Xw(F,K),J=new aT(F,K,t,Dt),Z=new Gw(F,K),J.reversedDepthBuffer&&u&&Z.buffers.depth.setReversed(!0),ut=new xT(F),it=new Iw,ht=new Ww(F,K,Z,it,J,Dt,ut),qt=new lT(y),Wt=new dT(y),D=new Mb(F),xt=new sT(F,D),A=new mT(F,D,ut,xt),k=new _T(F,A,D,ut),rt=new vT(F,J,ht),lt=new cT(it),X=new Cw(y,qt,Wt,K,J,xt,lt),et=new Zw(y,it),Y=new Dw,It=new Ow(K),Rt=new rT(y,qt,Wt,Z,k,d,c),Et=new Vw(y,k,J),Jt=new Jw(F,ut,J,Z),yt=new oT(F,K,ut),zt=new gT(F,K,ut),ut.programs=X.programs,y.capabilities=J,y.extensions=K,y.properties=it,y.renderLists=Y,y.shadowMap=Et,y.state=Z,y.info=ut}U();let at=new dp(y,F);this.xr=at,this.getContext=function(){return F},this.getContextAttributes=function(){return F.getContextAttributes()},this.forceContextLoss=function(){let C=K.get("WEBGL_lose_context");C&&C.loseContext()},this.forceContextRestore=function(){let C=K.get("WEBGL_lose_context");C&&C.restoreContext()},this.getPixelRatio=function(){return W},this.setPixelRatio=function(C){C!==void 0&&(W=C,this.setSize(V,j,!1))},this.getSize=function(C){return C.set(V,j)},this.setSize=function(C,B,H=!0){if(at.isPresenting){console.warn("THREE.WebGLRenderer: Can't change size while VR device is presenting.");return}V=C,j=B,e.width=Math.floor(C*W),e.height=Math.floor(B*W),H===!0&&(e.style.width=C+"px",e.style.height=B+"px"),this.setViewport(0,0,C,B)},this.getDrawingBufferSize=function(C){return C.set(V*W,j*W).floor()},this.setDrawingBufferSize=function(C,B,H){V=C,j=B,W=H,e.width=Math.floor(C*H),e.height=Math.floor(B*H),this.setViewport(0,0,C,B)},this.getCurrentViewport=function(C){return C.copy(I)},this.getViewport=function(C){return C.copy(_t)},this.setViewport=function(C,B,H,G){C.isVector4?_t.set(C.x,C.y,C.z,C.w):_t.set(C,B,H,G),Z.viewport(I.copy(_t).multiplyScalar(W).round())},this.getScissor=function(C){return C.copy(Ht)},this.setScissor=function(C,B,H,G){C.isVector4?Ht.set(C.x,C.y,C.z,C.w):Ht.set(C,B,H,G),Z.scissor(P.copy(Ht).multiplyScalar(W).round())},this.getScissorTest=function(){return ee},this.setScissorTest=function(C){Z.setScissorTest(ee=C)},this.setOpaqueSort=function(C){ct=C},this.setTransparentSort=function(C){pt=C},this.getClearColor=function(C){return C.copy(Rt.getClearColor())},this.setClearColor=function(){Rt.setClearColor(...arguments)},this.getClearAlpha=function(){return Rt.getClearAlpha()},this.setClearAlpha=function(){Rt.setClearAlpha(...arguments)},this.clear=function(C=!0,B=!0,H=!0){let G=0;if(C){let O=!1;if(E!==null){let ot=E.texture.format;O=ot===Xi||ot===Wi||ot===Dr}if(O){let ot=E.texture.type,vt=ot===on||ot===an||ot===Hi||ot===Os||ot===Yl||ot===$l,At=Rt.getClearColor(),Mt=Rt.getClearAlpha(),Ut=At.r,kt=At.g,Lt=At.b;vt?(g[0]=Ut,g[1]=kt,g[2]=Lt,g[3]=Mt,F.clearBufferuiv(F.COLOR,0,g)):(x[0]=Ut,x[1]=kt,x[2]=Lt,x[3]=Mt,F.clearBufferiv(F.COLOR,0,x))}else G|=F.COLOR_BUFFER_BIT}B&&(G|=F.DEPTH_BUFFER_BIT),H&&(G|=F.STENCIL_BUFFER_BIT,this.state.buffers.stencil.setMask(4294967295)),F.clear(G)},this.clearColor=function(){this.clear(!0,!1,!1)},this.clearDepth=function(){this.clear(!1,!0,!1)},this.clearStencil=function(){this.clear(!1,!1,!0)},this.dispose=function(){e.removeEventListener("webglcontextlost",dt,!1),e.removeEventListener("webglcontextrestored",Tt,!1),e.removeEventListener("webglcontextcreationerror",st,!1),Rt.dispose(),Y.dispose(),It.dispose(),it.dispose(),qt.dispose(),Wt.dispose(),k.dispose(),xt.dispose(),Jt.dispose(),X.dispose(),at.dispose(),at.removeEventListener("sessionstart",jn),at.removeEventListener("sessionend",nm),tr.stop()};function dt(C){C.preventDefault(),console.log("THREE.WebGLRenderer: Context Lost."),b=!0}function Tt(){console.log("THREE.WebGLRenderer: Context Restored."),b=!1;let C=ut.autoReset,B=Et.enabled,H=Et.autoUpdate,G=Et.needsUpdate,O=Et.type;U(),ut.autoReset=C,Et.enabled=B,Et.autoUpdate=H,Et.needsUpdate=G,Et.type=O}function st(C){console.error("THREE.WebGLRenderer: A WebGL context could not be created. Reason: ",C.statusMessage)}function Q(C){let B=C.target;B.removeEventListener("dispose",Q),Ct(B)}function Ct(C){Yt(C),it.remove(C)}function Yt(C){let B=it.get(C).programs;B!==void 0&&(B.forEach(function(H){X.releaseProgram(H)}),C.isShaderMaterial&&X.releaseShaderCache(C))}this.renderBufferDirect=function(C,B,H,G,O,ot){B===null&&(B=wt);let vt=O.isMesh&&O.matrixWorld.determinant()<0,At=Bv(C,B,H,G,O);Z.setMaterial(G,vt);let Mt=H.index,Ut=1;if(G.wireframe===!0){if(Mt=A.getWireframeAttribute(H),Mt===void 0)return;Ut=2}let kt=H.drawRange,Lt=H.attributes.position,ne=kt.start*Ut,ge=(kt.start+kt.count)*Ut;ot!==null&&(ne=Math.max(ne,ot.start*Ut),ge=Math.min(ge,(ot.start+ot.count)*Ut)),Mt!==null?(ne=Math.max(ne,0),ge=Math.min(ge,Mt.count)):Lt!=null&&(ne=Math.max(ne,0),ge=Math.min(ge,Lt.count));let Pe=ge-ne;if(Pe<0||Pe===1/0)return;xt.setup(O,G,At,H,Mt);let Te,_e=yt;if(Mt!==null&&(Te=D.get(Mt),_e=zt,_e.setIndex(Te)),O.isMesh)G.wireframe===!0?(Z.setLineWidth(G.wireframeLinewidth*fe()),_e.setMode(F.LINES)):_e.setMode(F.TRIANGLES);else if(O.isLine){let Nt=G.linewidth;Nt===void 0&&(Nt=1),Z.setLineWidth(Nt*fe()),O.isLineSegments?_e.setMode(F.LINES):O.isLineLoop?_e.setMode(F.LINE_LOOP):_e.setMode(F.LINE_STRIP)}else O.isPoints?_e.setMode(F.POINTS):O.isSprite&&_e.setMode(F.TRIANGLES);if(O.isBatchedMesh)if(O._multiDrawInstances!==null)ys("THREE.WebGLRenderer: renderMultiDrawInstances has been deprecated and will be removed in r184. Append to renderMultiDraw arguments and use indirection."),_e.renderMultiDrawInstances(O._multiDrawStarts,O._multiDrawCounts,O._multiDrawCount,O._multiDrawInstances);else if(K.get("WEBGL_multi_draw"))_e.renderMultiDraw(O._multiDrawStarts,O._multiDrawCounts,O._multiDrawCount);else{let Nt=O._multiDrawStarts,Ae=O._multiDrawCounts,ce=O._multiDrawCount,Tn=Mt?D.get(Mt).bytesPerElement:1,$r=it.get(G).currentProgram.getUniforms();for(let wn=0;wn{function ot(){if(G.forEach(function(vt){it.get(vt).currentProgram.isReady()&&G.delete(vt)}),G.size===0){O(C);return}setTimeout(ot,10)}K.get("KHR_parallel_shader_compile")!==null?ot():setTimeout(ot,10)})};let de=null;function ui(C){de&&de(C)}function jn(){tr.stop()}function nm(){tr.start()}let tr=new H0;tr.setAnimationLoop(ui),typeof self<"u"&&tr.setContext(self),this.setAnimationLoop=function(C){de=C,at.setAnimationLoop(C),C===null?tr.stop():tr.start()},at.addEventListener("sessionstart",jn),at.addEventListener("sessionend",nm),this.render=function(C,B){if(B!==void 0&&B.isCamera!==!0){console.error("THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.");return}if(b===!0)return;if(C.matrixWorldAutoUpdate===!0&&C.updateMatrixWorld(),B.parent===null&&B.matrixWorldAutoUpdate===!0&&B.updateMatrixWorld(),at.enabled===!0&&at.isPresenting===!0&&(at.cameraAutoUpdate===!0&&at.updateCamera(B),B=at.getCamera()),C.isScene===!0&&C.onBeforeRender(y,C,B,E),m=It.get(C,_.length),m.init(B),_.push(m),tt.multiplyMatrices(B.projectionMatrix,B.matrixWorldInverse),he.setFromProjectionMatrix(tt,Rn,B.reversedDepth),$=this.localClippingEnabled,Qt=lt.init(this.clippingPlanes,$),p=Y.get(C,v.length),p.init(),v.push(p),at.enabled===!0&&at.isPresenting===!0){let ot=y.xr.getDepthSensingMesh();ot!==null&&Lh(ot,B,-1/0,y.sortObjects)}Lh(C,B,0,y.sortObjects),p.finish(),y.sortObjects===!0&&p.sort(ct,pt),te=at.enabled===!1||at.isPresenting===!1||at.hasDepthSensing()===!1,te&&Rt.addToRenderList(p,C),this.info.render.frame++,Qt===!0&<.beginShadows();let H=m.state.shadowsArray;Et.render(H,C,B),Qt===!0&<.endShadows(),this.info.autoReset===!0&&this.info.reset();let G=p.opaque,O=p.transmissive;if(m.setupLights(),B.isArrayCamera){let ot=B.cameras;if(O.length>0)for(let vt=0,At=ot.length;vt0&&rm(G,O,C,B),te&&Rt.render(C),im(p,C,B);E!==null&&w===0&&(ht.updateMultisampleRenderTarget(E),ht.updateRenderTargetMipmap(E)),C.isScene===!0&&C.onAfterRender(y,C,B),xt.resetDefaultState(),M=-1,S=null,_.pop(),_.length>0?(m=_[_.length-1],Qt===!0&<.setGlobalState(y.clippingPlanes,m.state.camera)):m=null,v.pop(),v.length>0?p=v[v.length-1]:p=null};function Lh(C,B,H,G){if(C.visible===!1)return;if(C.layers.test(B.layers)){if(C.isGroup)H=C.renderOrder;else if(C.isLOD)C.autoUpdate===!0&&C.update(B);else if(C.isLight)m.pushLight(C),C.castShadow&&m.pushShadow(C);else if(C.isSprite){if(!C.frustumCulled||he.intersectsSprite(C)){G&&Pt.setFromMatrixPosition(C.matrixWorld).applyMatrix4(tt);let vt=k.update(C),At=C.material;At.visible&&p.push(C,vt,At,H,Pt.z,null)}}else if((C.isMesh||C.isLine||C.isPoints)&&(!C.frustumCulled||he.intersectsObject(C))){let vt=k.update(C),At=C.material;if(G&&(C.boundingSphere!==void 0?(C.boundingSphere===null&&C.computeBoundingSphere(),Pt.copy(C.boundingSphere.center)):(vt.boundingSphere===null&&vt.computeBoundingSphere(),Pt.copy(vt.boundingSphere.center)),Pt.applyMatrix4(C.matrixWorld).applyMatrix4(tt)),Array.isArray(At)){let Mt=vt.groups;for(let Ut=0,kt=Mt.length;Ut0&&Ba(O,B,H),ot.length>0&&Ba(ot,B,H),vt.length>0&&Ba(vt,B,H),Z.buffers.depth.setTest(!0),Z.buffers.depth.setMask(!0),Z.buffers.color.setMask(!0),Z.setPolygonOffset(!1)}function rm(C,B,H,G){if((H.isScene===!0?H.overrideMaterial:null)!==null)return;m.state.transmissionRenderTarget[G.id]===void 0&&(m.state.transmissionRenderTarget[G.id]=new ze(1,1,{generateMipmaps:!0,type:K.has("EXT_color_buffer_half_float")||K.has("EXT_color_buffer_float")?Ge:on,minFilter:ai,samples:4,stencilBuffer:s,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:ie.workingColorSpace}));let ot=m.state.transmissionRenderTarget[G.id],vt=G.viewport||I;ot.setSize(vt.z*y.transmissionResolutionScale,vt.w*y.transmissionResolutionScale);let At=y.getRenderTarget(),Mt=y.getActiveCubeFace(),Ut=y.getActiveMipmapLevel();y.setRenderTarget(ot),y.getClearColor(N),z=y.getClearAlpha(),z<1&&y.setClearColor(16777215,.5),y.clear(),te&&Rt.render(H);let kt=y.toneMapping;y.toneMapping=Zn;let Lt=G.viewport;if(G.viewport!==void 0&&(G.viewport=void 0),m.setupLightsView(G),Qt===!0&<.setGlobalState(y.clippingPlanes,G),Ba(C,H,G),ht.updateMultisampleRenderTarget(ot),ht.updateRenderTargetMipmap(ot),K.has("WEBGL_multisampled_render_to_texture")===!1){let ne=!1;for(let ge=0,Pe=B.length;ge0),Lt=!!H.morphAttributes.position,ne=!!H.morphAttributes.normal,ge=!!H.morphAttributes.color,Pe=Zn;G.toneMapped&&(E===null||E.isXRRenderTarget===!0)&&(Pe=y.toneMapping);let Te=H.morphAttributes.position||H.morphAttributes.normal||H.morphAttributes.color,_e=Te!==void 0?Te.length:0,Nt=it.get(G),Ae=m.state.lights;if(Qt===!0&&($===!0||C!==S)){let ln=C===S&&G.id===M;lt.setState(G,C,ln)}let ce=!1;G.version===Nt.__version?(Nt.needsLights&&Nt.lightsStateVersion!==Ae.state.version||Nt.outputColorSpace!==At||O.isBatchedMesh&&Nt.batching===!1||!O.isBatchedMesh&&Nt.batching===!0||O.isBatchedMesh&&Nt.batchingColor===!0&&O.colorTexture===null||O.isBatchedMesh&&Nt.batchingColor===!1&&O.colorTexture!==null||O.isInstancedMesh&&Nt.instancing===!1||!O.isInstancedMesh&&Nt.instancing===!0||O.isSkinnedMesh&&Nt.skinning===!1||!O.isSkinnedMesh&&Nt.skinning===!0||O.isInstancedMesh&&Nt.instancingColor===!0&&O.instanceColor===null||O.isInstancedMesh&&Nt.instancingColor===!1&&O.instanceColor!==null||O.isInstancedMesh&&Nt.instancingMorph===!0&&O.morphTexture===null||O.isInstancedMesh&&Nt.instancingMorph===!1&&O.morphTexture!==null||Nt.envMap!==Mt||G.fog===!0&&Nt.fog!==ot||Nt.numClippingPlanes!==void 0&&(Nt.numClippingPlanes!==lt.numPlanes||Nt.numIntersection!==lt.numIntersection)||Nt.vertexAlphas!==Ut||Nt.vertexTangents!==kt||Nt.morphTargets!==Lt||Nt.morphNormals!==ne||Nt.morphColors!==ge||Nt.toneMapping!==Pe||Nt.morphTargetsCount!==_e)&&(ce=!0):(ce=!0,Nt.__version=G.version);let Tn=Nt.currentProgram;ce===!0&&(Tn=Oa(G,B,O));let $r=!1,wn=!1,ao=!1,Ee=Tn.getUniforms(),Ln=Nt.uniforms;if(Z.useProgram(Tn.program)&&($r=!0,wn=!0,ao=!0),G.id!==M&&(M=G.id,wn=!0),$r||S!==C){Z.buffers.depth.getReversed()&&C.reversedDepth!==!0&&(C._reversedDepth=!0,C.updateProjectionMatrix()),Ee.setValue(F,"projectionMatrix",C.projectionMatrix),Ee.setValue(F,"viewMatrix",C.matrixWorldInverse);let mn=Ee.map.cameraPosition;mn!==void 0&&mn.setValue(F,St.setFromMatrixPosition(C.matrixWorld)),J.logarithmicDepthBuffer&&Ee.setValue(F,"logDepthBufFC",2/(Math.log(C.far+1)/Math.LN2)),(G.isMeshPhongMaterial||G.isMeshToonMaterial||G.isMeshLambertMaterial||G.isMeshBasicMaterial||G.isMeshStandardMaterial||G.isShaderMaterial)&&Ee.setValue(F,"isOrthographic",C.isOrthographicCamera===!0),S!==C&&(S=C,wn=!0,ao=!0)}if(O.isSkinnedMesh){Ee.setOptional(F,O,"bindMatrix"),Ee.setOptional(F,O,"bindMatrixInverse");let ln=O.skeleton;ln&&(ln.boneTexture===null&&ln.computeBoneTexture(),Ee.setValue(F,"boneTexture",ln.boneTexture,ht))}O.isBatchedMesh&&(Ee.setOptional(F,O,"batchingTexture"),Ee.setValue(F,"batchingTexture",O._matricesTexture,ht),Ee.setOptional(F,O,"batchingIdTexture"),Ee.setValue(F,"batchingIdTexture",O._indirectTexture,ht),Ee.setOptional(F,O,"batchingColorTexture"),O._colorsTexture!==null&&Ee.setValue(F,"batchingColorTexture",O._colorsTexture,ht));let Nn=H.morphAttributes;if((Nn.position!==void 0||Nn.normal!==void 0||Nn.color!==void 0)&&rt.update(O,H,Tn),(wn||Nt.receiveShadow!==O.receiveShadow)&&(Nt.receiveShadow=O.receiveShadow,Ee.setValue(F,"receiveShadow",O.receiveShadow)),G.isMeshGouraudMaterial&&G.envMap!==null&&(Ln.envMap.value=Mt,Ln.flipEnvMap.value=Mt.isCubeTexture&&Mt.isRenderTargetTexture===!1?-1:1),G.isMeshStandardMaterial&&G.envMap===null&&B.environment!==null&&(Ln.envMapIntensity.value=B.environmentIntensity),wn&&(Ee.setValue(F,"toneMappingExposure",y.toneMappingExposure),Nt.needsLights&&Ov(Ln,ao),ot&&G.fog===!0&&et.refreshFogUniforms(Ln,ot),et.refreshMaterialUniforms(Ln,G,W,j,m.state.transmissionRenderTarget[C.id]),Hs.upload(F,om(Nt),Ln,ht)),G.isShaderMaterial&&G.uniformsNeedUpdate===!0&&(Hs.upload(F,om(Nt),Ln,ht),G.uniformsNeedUpdate=!1),G.isSpriteMaterial&&Ee.setValue(F,"center",O.center),Ee.setValue(F,"modelViewMatrix",O.modelViewMatrix),Ee.setValue(F,"normalMatrix",O.normalMatrix),Ee.setValue(F,"modelMatrix",O.matrixWorld),G.isShaderMaterial||G.isRawShaderMaterial){let ln=G.uniformsGroups;for(let mn=0,Nh=ln.length;mn0&&ht.useMultisampledRTT(C)===!1?O=it.get(C).__webglMultisampledFramebuffer:Array.isArray(kt)?O=kt[H]:O=kt,I.copy(C.viewport),P.copy(C.scissor),L=C.scissorTest}else I.copy(_t).multiplyScalar(W).floor(),P.copy(Ht).multiplyScalar(W).floor(),L=ee;if(H!==0&&(O=kv),Z.bindFramebuffer(F.FRAMEBUFFER,O)&&G&&Z.drawBuffers(C,O),Z.viewport(I),Z.scissor(P),Z.setScissorTest(L),ot){let Mt=it.get(C.texture);F.framebufferTexture2D(F.FRAMEBUFFER,F.COLOR_ATTACHMENT0,F.TEXTURE_CUBE_MAP_POSITIVE_X+B,Mt.__webglTexture,H)}else if(vt){let Mt=B;for(let Ut=0;Ut=0&&B<=C.width-G&&H>=0&&H<=C.height-O&&(C.textures.length>1&&F.readBuffer(F.COLOR_ATTACHMENT0+At),F.readPixels(B,H,G,O,Dt.convert(kt),Dt.convert(Lt),ot))}finally{let Ut=E!==null?it.get(E).__webglFramebuffer:null;Z.bindFramebuffer(F.FRAMEBUFFER,Ut)}}},this.readRenderTargetPixelsAsync=async function(C,B,H,G,O,ot,vt,At=0){if(!(C&&C.isWebGLRenderTarget))throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let Mt=it.get(C).__webglFramebuffer;if(C.isWebGLCubeRenderTarget&&vt!==void 0&&(Mt=Mt[vt]),Mt)if(B>=0&&B<=C.width-G&&H>=0&&H<=C.height-O){Z.bindFramebuffer(F.FRAMEBUFFER,Mt);let Ut=C.textures[At],kt=Ut.format,Lt=Ut.type;if(!J.textureFormatReadable(kt))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");if(!J.textureTypeReadable(Lt))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");let ne=F.createBuffer();F.bindBuffer(F.PIXEL_PACK_BUFFER,ne),F.bufferData(F.PIXEL_PACK_BUFFER,ot.byteLength,F.STREAM_READ),C.textures.length>1&&F.readBuffer(F.COLOR_ATTACHMENT0+At),F.readPixels(B,H,G,O,Dt.convert(kt),Dt.convert(Lt),0);let ge=E!==null?it.get(E).__webglFramebuffer:null;Z.bindFramebuffer(F.FRAMEBUFFER,ge);let Pe=F.fenceSync(F.SYNC_GPU_COMMANDS_COMPLETE,0);return F.flush(),await o0(F,Pe,4),F.bindBuffer(F.PIXEL_PACK_BUFFER,ne),F.getBufferSubData(F.PIXEL_PACK_BUFFER,0,ot),F.deleteBuffer(ne),F.deleteSync(Pe),ot}else throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.")},this.copyFramebufferToTexture=function(C,B=null,H=0){let G=Math.pow(2,-H),O=Math.floor(C.image.width*G),ot=Math.floor(C.image.height*G),vt=B!==null?B.x:0,At=B!==null?B.y:0;ht.setTexture2D(C,0),F.copyTexSubImage2D(F.TEXTURE_2D,H,0,0,vt,At,O,ot),Z.unbindTexture()};let Vv=F.createFramebuffer(),Hv=F.createFramebuffer();this.copyTextureToTexture=function(C,B,H=null,G=null,O=0,ot=null){ot===null&&(O!==0?(ys("WebGLRenderer: copyTextureToTexture function signature has changed to support src and dst mipmap levels."),ot=O,O=0):ot=0);let vt,At,Mt,Ut,kt,Lt,ne,ge,Pe,Te=C.isCompressedTexture?C.mipmaps[ot]:C.image;if(H!==null)vt=H.max.x-H.min.x,At=H.max.y-H.min.y,Mt=H.isBox3?H.max.z-H.min.z:1,Ut=H.min.x,kt=H.min.y,Lt=H.isBox3?H.min.z:0;else{let Nn=Math.pow(2,-O);vt=Math.floor(Te.width*Nn),At=Math.floor(Te.height*Nn),C.isDataArrayTexture?Mt=Te.depth:C.isData3DTexture?Mt=Math.floor(Te.depth*Nn):Mt=1,Ut=0,kt=0,Lt=0}G!==null?(ne=G.x,ge=G.y,Pe=G.z):(ne=0,ge=0,Pe=0);let _e=Dt.convert(B.format),Nt=Dt.convert(B.type),Ae;B.isData3DTexture?(ht.setTexture3D(B,0),Ae=F.TEXTURE_3D):B.isDataArrayTexture||B.isCompressedArrayTexture?(ht.setTexture2DArray(B,0),Ae=F.TEXTURE_2D_ARRAY):(ht.setTexture2D(B,0),Ae=F.TEXTURE_2D),F.pixelStorei(F.UNPACK_FLIP_Y_WEBGL,B.flipY),F.pixelStorei(F.UNPACK_PREMULTIPLY_ALPHA_WEBGL,B.premultiplyAlpha),F.pixelStorei(F.UNPACK_ALIGNMENT,B.unpackAlignment);let ce=F.getParameter(F.UNPACK_ROW_LENGTH),Tn=F.getParameter(F.UNPACK_IMAGE_HEIGHT),$r=F.getParameter(F.UNPACK_SKIP_PIXELS),wn=F.getParameter(F.UNPACK_SKIP_ROWS),ao=F.getParameter(F.UNPACK_SKIP_IMAGES);F.pixelStorei(F.UNPACK_ROW_LENGTH,Te.width),F.pixelStorei(F.UNPACK_IMAGE_HEIGHT,Te.height),F.pixelStorei(F.UNPACK_SKIP_PIXELS,Ut),F.pixelStorei(F.UNPACK_SKIP_ROWS,kt),F.pixelStorei(F.UNPACK_SKIP_IMAGES,Lt);let Ee=C.isDataArrayTexture||C.isData3DTexture,Ln=B.isDataArrayTexture||B.isData3DTexture;if(C.isDepthTexture){let Nn=it.get(C),ln=it.get(B),mn=it.get(Nn.__renderTarget),Nh=it.get(ln.__renderTarget);Z.bindFramebuffer(F.READ_FRAMEBUFFER,mn.__webglFramebuffer),Z.bindFramebuffer(F.DRAW_FRAMEBUFFER,Nh.__webglFramebuffer);for(let er=0;ere&&(e=i,t=n)}return t}function gp(r,t){t.set(r)}function xp(r,t,e){let n,i;for(let s=0;s<3;s++){let o=s+3;n=r[s],i=t[s],e[s]=ni?n:i}}function ya(r,t,e){for(let n=0;n<3;n++){let i=t[r+2*n],s=t[r+2*n+1],o=i-s,a=i+s;oe[n+3]&&(e[n+3]=a)}}function Ws(r){let t=r[3]-r[0],e=r[4]-r[1],n=r[5]-r[2];return 2*(t*e+e*n+n*t)}function le(r,t){return t[r+15]===65535}function Ie(r,t){return t[r+6]}function Fe(r,t){return t[r+14]}function xe(r){return r+8}function ve(r,t){let e=t[r+6];return r+e*8}function Yi(r,t){return t[r+7]}function Pu(r,t,e,n,i){let s=1/0,o=1/0,a=1/0,c=-1/0,l=-1/0,f=-1/0,h=1/0,u=1/0,d=1/0,g=-1/0,x=-1/0,p=-1/0,m=r.offset||0;for(let v=(t-m)*6,_=(t+e-m)*6;v<_;v+=6){let y=r[v+0],b=r[v+1],T=y-b,w=y+b;Tc&&(c=w),yg&&(g=y);let E=r[v+2],M=r[v+3],S=E-M,I=E+M;Sl&&(l=I),Ex&&(x=E);let P=r[v+4],L=r[v+5],N=P-L,z=P+L;Nf&&(f=z),Pp&&(p=P)}n[0]=s,n[1]=o,n[2]=a,n[3]=c,n[4]=l,n[5]=f,i[0]=h,i[1]=u,i[2]=d,i[3]=g,i[4]=x,i[5]=p}var wi=32,jw=(r,t)=>r.candidate-t.candidate,$i=new Array(wi).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Du=new Float32Array(6);function J0(r,t,e,n,i,s){let o=-1,a=0;if(s===0)o=mp(t),o!==-1&&(a=(t[o]+t[o+3])/2);else if(s===1)o=mp(r),o!==-1&&(a=tA(e,n,i,o));else if(s===2){let c=Ws(r),l=1.25*i,f=e.offset||0,h=(n-f)*6,u=(n+i-f)*6;for(let d=0;d<3;d++){let g=t[d],m=(t[d+3]-g)/wi;if(i=E.candidate?ya(b,e,E.rightCacheBounds):(ya(b,e,E.leftCacheBounds),E.count++)}}for(let b=0;b=wi&&(w=wi-1);let E=$i[w];E.count++,ya(y,e,E.bounds)}let v=$i[wi-1];gp(v.bounds,v.rightCacheBounds);for(let y=wi-2;y>=0;y--){let b=$i[y],T=$i[y+1];xp(b.bounds,T.rightCacheBounds,b.rightCacheBounds)}let _=0;for(let y=0;y=c;)a--;if(oeA)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return Fu[e+6]=d,Fu[e+7]=c,_p(f,a)}}function nA(r,t,e,n,i){let{maxDepth:s,verbose:o,maxLeafSize:a,strategy:c,onProgress:l}=i,f=r.primitiveBuffer,h=r.primitiveBufferStride,u=new Float32Array(6),d=!1,g=new Xs;return Pu(t,e,n,g.boundingData,u),p(g,e,n,u),g;function x(m){l&&l(m/n)}function p(m,v,_,y=null,b=0){if(!d&&b>=s&&(d=!0,o&&console.warn(`BVH: Max depth of ${s} reached when generating BVH. Consider increasing maxDepth.`)),_<=a||b>=s)return x(v+_),m.offset=v,m.count=_,m;let T=J0(m.boundingData,y,t,v,_,c);if(T.axis===-1)return x(v+_),m.offset=v,m.count=_,m;let w=K0(f,h,t,v,_,T);if(w===v||w===v+_)x(v+_),m.offset=v,m.count=_;else{m.splitAxis=T.axis;let E=new Xs,M=v,S=w-v;m.left=E,Pu(t,M,S,E.boundingData,u),p(E,M,S,u,b+1);let I=new Xs,P=w,L=_-S;m.right=I,Pu(t,P,L,I.boundingData,u),p(I,P,L,u,b+1)}return m}}function ex(r,t){let e=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,n=r.getRootRanges(t.range),i=n[0],s=n[n.length-1],o={offset:i.offset,count:s.offset+s.count-i.offset},a=new Float32Array(6*o.count);a.offset=o.offset,r.computePrimitiveBounds(o.offset,o.count,a),r._roots=n.map(c=>{let l=nA(r,a,c.offset,c.count,t),f=Lu(l),h=new e(32*f);return tx(0,l,h),h})}var Zi=class{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){let t=this._primitives;return t.length===0?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}};var yp=class{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;let t=[],e=null;this.setBuffer=n=>{e&&t.push(e),e=n,this.float32Array=new Float32Array(n),this.uint16Array=new Uint16Array(n),this.uint32Array=new Uint32Array(n)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}},ae=new yp;var Ji,Ys,qs=[],Nu=new Zi(()=>new se);function nx(r,t,e,n,i,s){Ji=Nu.getPrimitive(),Ys=Nu.getPrimitive(),qs.push(Ji,Ys),ae.setBuffer(r._roots[t]);let o=bp(0,r.geometry,e,n,i,s);ae.clearBuffer(),Nu.releasePrimitive(Ji),Nu.releasePrimitive(Ys),qs.pop(),qs.pop();let a=qs.length;return a>0&&(Ys=qs[a-1],Ji=qs[a-2]),o}function bp(r,t,e,n,i=null,s=0,o=0){let{float32Array:a,uint16Array:c,uint32Array:l}=ae,f=r*2;if(le(f,c)){let u=Ie(r,l),d=Fe(f,c);return ye(r,a,Ji),n(u,d,!1,o,s+r/8,Ji)}else{let S=function(P){let{uint16Array:L,uint32Array:N}=ae,z=P*2;for(;!le(z,L);)P=xe(P),z=P*2;return Ie(P,N)},I=function(P){let{uint16Array:L,uint32Array:N}=ae,z=P*2;for(;!le(z,L);)P=ve(P,N),z=P*2;return Ie(P,N)+Fe(z,L)},u=xe(r),d=ve(r,l),g=u,x=d,p,m,v,_;if(i&&(v=Ji,_=Ys,ye(g,a,v),ye(x,a,_),p=i(v),m=i(_),m65535?new Uint32Array(new t(4*r)):new Uint16Array(new t(2*r))}function ix(r,t){if(!r.index){let e=r.attributes.position.count,n=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=Sp(e,n);r.setIndex(new Ot(i,1));for(let s=0;s({offset:e.start/t,count:e.count/t}))}function Sa(r,t,e){let n=rA(r,t,e),i=sA(r,e);if(!i.length)return[n];let s=[],o=n.offset,a=n.offset+n.count,c=ba(r)/e,l=[];for(let u of i){let{offset:d,count:g}=u,x=d,p=isFinite(g)?g:c-d,m=d+p;xo&&(l.push({pos:Math.max(o,x),isStart:!0}),l.push({pos:Math.min(a,m),isStart:!1}))}l.sort((u,d)=>u.pos!==d.pos?u.pos-d.pos:u.type==="end"?-1:1);let f=0,h=null;for(let u of l){let d=u.pos;f!==0&&d!==h&&s.push({offset:h,count:d-h}),f+=u.isStart?1:-1,h=d}return s}var rx=new se,Bu=class{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(t){t={...Iu,...t},ex(this,t)}getRootRanges(t){return Sa(this.geometry,t,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}shiftPrimitiveOffsets(t){let e=this._indirectBuffer;if(e)for(let n=0,i=e.length;n{ye(0,new Float32Array(n),rx),t.union(rx)}),t}shapecast(t){let{boundsTraverseOrder:e,intersectsBounds:n,intersectsRange:i,intersectsPrimitive:s,scratchPrimitive:o,iterate:a}=t;if(i&&s){let h=i;i=(u,d,g,x,p)=>h(u,d,g,x,p)?!0:a(u,d,this,s,g,x,o)}else i||(s?i=(h,u,d,g)=>a(h,u,this,s,d,g,o):i=(h,u,d)=>d);let c=!1,l=0,f=this._roots;for(let h=0,u=f.length;hi?c:i}this.min=n,this.max=i}setFromPoints(t,e){let n=1/0,i=-1/0;for(let s=0,o=e.length;si?c:i}this.min=n,this.max=i}isSeparated(t){return this.min>t.max||t.min>this.max}};Dn.prototype.setFromBox=(function(){let r=new R;return function(e,n){let i=n.min,s=n.max,o=1/0,a=-1/0;for(let c=0;c<=1;c++)for(let l=0;l<=1;l++)for(let f=0;f<=1;f++){r.x=i.x*c+s.x*(1-c),r.y=i.y*l+s.y*(1-l),r.z=i.z*f+s.z*(1-f);let h=e.dot(r);o=Math.min(h,o),a=Math.max(h,a)}this.min=o,this.max=a}})();var oA=(function(){let r=new R,t=new R,e=new R;return function(i,s,o){let a=i.start,c=r,l=s.start,f=t;e.subVectors(a,l),r.subVectors(i.end,i.start),t.subVectors(s.end,s.start);let h=e.dot(f),u=f.dot(c),d=f.dot(f),g=e.dot(c),p=c.dot(c)*d-u*u,m,v;p!==0?m=(h*u-g*d)/p:m=0,v=(h+m*u)/d,o.x=m,o.y=v}})(),Ma=(function(){let r=new q,t=new R,e=new R;return function(i,s,o,a){oA(i,s,r);let c=r.x,l=r.y;if(c>=0&&c<=1&&l>=0&&l<=1){i.at(c,o),s.at(l,a);return}else if(c>=0&&c<=1){l<0?s.at(0,a):s.at(1,a),i.closestPointToPoint(a,!0,o);return}else if(l>=0&&l<=1){c<0?i.at(0,o):i.at(1,o),s.closestPointToPoint(o,!0,a);return}else{let f;c<0?f=i.start:f=i.end;let h;l<0?h=s.start:h=s.end;let u=t,d=e;if(i.closestPointToPoint(h,!0,t),s.closestPointToPoint(f,!0,e),u.distanceToSquared(h)<=d.distanceToSquared(f)){o.copy(u),a.copy(h);return}else{o.copy(f),a.copy(d);return}}}})(),sx=(function(){let r=new R,t=new R,e=new _n,n=new dn;return function(s,o){let{radius:a,center:c}=s,{a:l,b:f,c:h}=o;if(n.start=l,n.end=f,n.closestPointToPoint(c,!0,r).distanceTo(c)<=a||(n.start=l,n.end=h,n.closestPointToPoint(c,!0,r).distanceTo(c)<=a)||(n.start=f,n.end=h,n.closestPointToPoint(c,!0,r).distanceTo(c)<=a))return!0;let x=o.getPlane(e);if(Math.abs(x.distanceToPoint(c))<=a){let m=x.projectPoint(c,t);if(o.containsPoint(m))return!0}return!1}})();var aA=["x","y","z"],Ai=1e-15,ox=Ai*Ai;function Vn(r){return Math.abs(r)new R),this.satBounds=new Array(4).fill().map(()=>new Dn),this.points=[this.a,this.b,this.c],this.plane=new _n,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new dn,this.needsUpdate=!0}intersectsSphere(t){return sx(t,this)}update(){let t=this.a,e=this.b,n=this.c,i=this.points,s=this.satAxes,o=this.satBounds,a=s[0],c=o[0];this.getNormal(a),c.setFromPoints(a,i);let l=s[1],f=o[1];l.subVectors(t,e),f.setFromPoints(l,i);let h=s[2],u=o[2];h.subVectors(e,n),u.setFromPoints(h,i);let d=s[3],g=o[3];d.subVectors(n,t),g.setFromPoints(d,i);let x=l.length(),p=h.length(),m=d.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,x0)d(_.c,_.a,_.b,T,y,b,I,M,S,P,L);else if(E>0)d(_.b,_.a,_.c,b,y,T,S,M,I,P,L);else if(S*I>0||M!=0)d(_.a,_.b,_.c,y,b,T,M,S,I,P,L);else if(S!=0)d(_.b,_.a,_.c,b,y,T,S,M,I,P,L);else if(I!=0)d(_.c,_.a,_.b,T,y,b,I,M,S,P,L);else return!0;return!1}function x(_,y,b,T){let w=y.degenerateSegment,E=_.plane.distanceToPoint(w.start),M=_.plane.distanceToPoint(w.end);return Vn(E)?Vn(M)?u(_,y,b,T):(b&&(b.start.copy(w.start),b.end.copy(w.start)),_.containsPoint(w.start)):Vn(M)?(b&&(b.start.copy(w.end),b.end.copy(w.end)),_.containsPoint(w.end)):_.plane.intersectLine(w,n)!=null?(b&&(b.start.copy(n),b.end.copy(n)),_.containsPoint(n)):!1}function p(_,y,b){let T=y.a;return Vn(_.plane.distanceToPoint(T))&&_.containsPoint(T)?(b&&(b.start.copy(T),b.end.copy(T)),!0):!1}function m(_,y,b){let T=_.degenerateSegment,w=y.a;return T.closestPointToPoint(w,!0,n),w.distanceToSquared(n)1||N<0||N>1)return!1;let z=w.start.z+M.z*L,V=E.start.z+S.z*N;return Vn(z-V)?(b&&(b.start.copy(w.start).addScaledVector(M,L),b.end.copy(w.start).addScaledVector(M,L)),!0):!1}else return y.isDegenerateIntoPoint?m(_,y,b):x(y,_,b,T);else{if(_.isDegenerateIntoPoint)return y.isDegenerateIntoPoint?y.a.distanceToSquared(_.a)0&&N>0)return!1;let z=E.distanceToPoint(y.a),V=E.distanceToPoint(y.b),j=E.distanceToPoint(y.c);Vn(z)&&(z=0),Vn(V)&&(V=0),Vn(j)&&(j=0);let W=z*V,ct=z*j;if(W>0&&ct>0)return!1;i.copy(E.normal),s.copy(M.normal);let pt=i.cross(s),_t=0,Ht=Math.abs(pt.x),ee=Math.abs(pt.y);ee>Ht&&(Ht=ee,_t=1),Math.abs(pt.z)>Ht&&(_t=2);let Qt=aA[_t],$=this.a[Qt],tt=this.b[Qt],St=this.c[Qt],Pt=y.a[Qt],wt=y.b[Qt],te=y.c[Qt];if(g(this,$,tt,St,L,N,S,I,P,f,a))return u(this,y,b,T);if(g(y,Pt,wt,te,W,ct,z,V,j,h,c))return u(this,y,b,T);if(f.yf.x?b.start.copy(c.start):b.start.copy(a.start),h.ynew R),this.satAxes=new Array(3).fill().map(()=>new R),this.satBounds=new Array(3).fill().map(()=>new Dn),this.alignedSatBounds=new Array(3).fill().map(()=>new Dn),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),n&&this.matrix.copy(n)}set(t,e,n){this.min.copy(t),this.max.copy(e),this.matrix.copy(n),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}};Le.prototype.update=(function(){return function(){let t=this.matrix,e=this.min,n=this.max,i=this.points;for(let l=0;l<=1;l++)for(let f=0;f<=1;f++)for(let h=0;h<=1;h++){let u=1*l|2*f|4*h,d=i[u];d.x=l?n.x:e.x,d.y=f?n.y:e.y,d.z=h?n.z:e.z,d.applyMatrix4(t)}let s=this.satBounds,o=this.satAxes,a=i[0];for(let l=0;l<3;l++){let f=o[l],h=s[l],u=1<new dn),e=new Array(12).fill().map(()=>new dn),n=new R,i=new R;return function(o,a=0,c=null,l=null){if(this.needsUpdate&&this.update(),this.intersectsBox(o))return(c||l)&&(o.getCenter(i),this.closestPointToPoint(i,n),o.closestPointToPoint(n,i),c&&c.copy(n),l&&l.copy(i)),0;let f=a*a,h=o.min,u=o.max,d=this.points,g=1/0;for(let p=0;p<8;p++){let m=d[p];i.copy(m).clamp(h,u);let v=m.distanceToSquared(i);if(vnew tn)}},pn=new Mp;var Ta=new R,Tp=new R;function ax(r,t,e={},n=0,i=1/0){let s=n*n,o=i*i,a=1/0,c=null;if(r.shapecast({boundsTraverseOrder:f=>(Ta.copy(t).clamp(f.min,f.max),Ta.distanceToSquared(t)),intersectsBounds:(f,h,u)=>u{f.closestPointToPoint(t,Ta);let u=t.distanceToSquared(Ta);return u=169,cA=parseInt("180")<=161,zr=new R,kr=new R,Vr=new R,zu=new q,ku=new q,Vu=new q,cx=new R,lx=new R,ux=new R,wa=new R;function lA(r,t,e,n,i,s,o,a){let c;if(s===He?c=r.intersectTriangle(n,e,t,!0,i):c=r.intersectTriangle(t,e,n,s!==Sn,i),c===null)return null;let l=r.origin.distanceTo(i);return la?null:{distance:l,point:i.clone()}}function hx(r,t,e,n,i,s,o,a,c,l,f){zr.fromBufferAttribute(t,s),kr.fromBufferAttribute(t,o),Vr.fromBufferAttribute(t,a);let h=lA(r,zr,kr,Vr,wa,c,l,f);if(h){if(n){zu.fromBufferAttribute(n,s),ku.fromBufferAttribute(n,o),Vu.fromBufferAttribute(n,a),h.uv=new q;let d=$e.getInterpolation(wa,zr,kr,Vr,zu,ku,Vu,h.uv);Ou||(h.uv=d)}if(i){zu.fromBufferAttribute(i,s),ku.fromBufferAttribute(i,o),Vu.fromBufferAttribute(i,a),h.uv1=new q;let d=$e.getInterpolation(wa,zr,kr,Vr,zu,ku,Vu,h.uv1);Ou||(h.uv1=d),cA&&(h.uv2=h.uv1)}if(e){cx.fromBufferAttribute(e,s),lx.fromBufferAttribute(e,o),ux.fromBufferAttribute(e,a),h.normal=new R;let d=$e.getInterpolation(wa,zr,kr,Vr,cx,lx,ux,h.normal);h.normal.dot(r.direction)>0&&h.normal.multiplyScalar(-1),Ou||(h.normal=d)}let u={a:s,b:o,c:a,normal:new R,materialIndex:0};if($e.getNormal(zr,kr,Vr,u.normal),h.face=u,h.faceIndex=s,Ou){let d=new R;$e.getBarycoord(wa,zr,kr,Vr,d),h.barycoord=d}}return h}function fx(r){return r&&r.isMaterial?r.side:r}function $s(r,t,e,n,i,s,o){let a=n*3,c=a+0,l=a+1,f=a+2,{index:h,groups:u}=r;r.index&&(c=h.getX(c),l=h.getX(l),f=h.getX(f));let{position:d,normal:g,uv:x,uv1:p}=r.attributes;if(Array.isArray(t)){let m=n*3;for(let v=0,_=u.length;v<_;v++){let{start:y,count:b,materialIndex:T}=u[v];if(m>=y&&mb&&(b=I),P<_&&(_=P),P>T&&(T=P),Lw&&(w=L)}return c[u+0]!==v||c[u+1]!==_||c[u+2]!==y||c[u+3]!==b||c[u+4]!==T||c[u+5]!==w?(c[u+0]=v,c[u+1]=_,c[u+2]=y,c[u+3]=b,c[u+4]=T,c[u+5]=w,!0):!1}else{let p=xe(u),m=ve(u,o),v=g,_=!1,y=!1;if(t){if(!v){let S=p/8+d/32,I=m/8+d/32;_=t.has(S),y=t.has(I),v=!_&&!y}}else _=!0,y=!0;let b=v||_,T=v||y,w=!1;b&&(w=h(p,d,v));let E=!1;T&&(E=h(m,d,v));let M=w||E;if(M)for(let S=0;S<3;S++){let I=p+S,P=m+S,L=c[I],N=c[I+3],z=c[P],V=c[P+3];c[u+S]=LV?N:V}return M}}}function Hn(r,t,e,n,i){let s,o,a,c,l,f,h=1/e.direction.x,u=1/e.direction.y,d=1/e.direction.z,g=e.origin.x,x=e.origin.y,p=e.origin.z,m=t[r],v=t[r+3],_=t[r+1],y=t[r+3+1],b=t[r+2],T=t[r+3+2];return h>=0?(s=(m-g)*h,o=(v-g)*h):(s=(v-g)*h,o=(m-g)*h),u>=0?(a=(_-x)*u,c=(y-x)*u):(a=(y-x)*u,c=(_-x)*u),s>c||a>o||((a>s||isNaN(s))&&(s=a),(c=0?(l=(b-p)*d,f=(T-p)*d):(l=(T-p)*d,f=(b-p)*d),s>f||l>o)?!1:((l>s||s!==s)&&(s=l),(f=n)}function xx(r,t,e,n,i,s,o,a){let{geometry:c,_indirectBuffer:l}=r;for(let f=n,h=n+i;f=0,x,p;g?(x=xe(r),p=ve(r,c)):(x=ve(r,c),p=xe(r));let v=Hn(x,o,n,i,s)?Ap(x,t,e,n,i,s):null;if(v){let b=v.point[u];if(g?b<=o[p+h]:b>=o[p+h+3])return v}let y=Hn(p,o,n,i,s)?Ap(p,t,e,n,i,s):null;return v&&y?v.distance<=y.distance?v:y:v||y||null}}var Hu=new se,Zs=new tn,Js=new tn,Aa=new gt,Sx=new Le,Gu=new Le;function Mx(r,t,e,n){ae.setBuffer(r._roots[t]);let i=Ep(0,r,e,n);return ae.clearBuffer(),i}function Ep(r,t,e,n,i=null){let{float32Array:s,uint16Array:o,uint32Array:a}=ae,c=r*2;if(i===null&&(e.boundingBox||e.computeBoundingBox(),Sx.set(e.boundingBox.min,e.boundingBox.max,n),i=Sx),le(c,o)){let f=t.geometry,h=f.index,u=f.attributes.position,d=e.index,g=e.attributes.position,x=Ie(r,a),p=Fe(c,o);if(Aa.copy(n).invert(),e.boundsTree)return ye(r,s,Gu),Gu.matrix.copy(Aa),Gu.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:v=>Gu.intersectsBox(v),intersectsTriangle:v=>{v.a.applyMatrix4(n),v.b.applyMatrix4(n),v.c.applyMatrix4(n),v.needsUpdate=!0;for(let _=x*3,y=(p+x)*3;_Rp.distanceToBox(b),intersectsBounds:(b,T,w)=>w{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:E=>Ea.distanceToBox(E),intersectsBounds:(E,M,S)=>S{for(let S=E,I=E+M;Sb&&(b=L),N<_&&(_=N),N>T&&(T=N),zw&&(w=z)}}return c[u+0]!==v||c[u+1]!==_||c[u+2]!==y||c[u+3]!==b||c[u+4]!==T||c[u+5]!==w?(c[u+0]=v,c[u+1]=_,c[u+2]=y,c[u+3]=b,c[u+4]=T,c[u+5]=w,!0):!1}else{let p=xe(u),m=ve(u,o),v=g,_=!1,y=!1;if(t){if(!v){let S=p/8+d/32,I=m/8+d/32;_=t.has(S),y=t.has(I),v=!_&&!y}}else _=!0,y=!0;let b=v||_,T=v||y,w=!1;b&&(w=h(p,d,v));let E=!1;T&&(E=h(m,d,v));let M=w||E;if(M)for(let S=0;S<3;S++){let I=p+S,P=m+S,L=c[I],N=c[I+3],z=c[P],V=c[P+3];c[u+S]=LV?N:V}return M}}}function Ax(r,t,e,n,i,s,o){ae.setBuffer(r._roots[t]),Cp(0,r,e,n,i,s,o),ae.clearBuffer()}function Cp(r,t,e,n,i,s,o){let{float32Array:a,uint16Array:c,uint32Array:l}=ae,f=r*2;if(le(f,c)){let u=Ie(r,l),d=Fe(f,c);xx(t,e,n,u,d,i,s,o)}else{let u=xe(r);Hn(u,a,n,s,o)&&Cp(u,t,e,n,i,s,o);let d=ve(r,l);Hn(d,a,n,s,o)&&Cp(d,t,e,n,i,s,o)}}var mA=["x","y","z"];function Ex(r,t,e,n,i,s){ae.setBuffer(r._roots[t]);let o=Ip(0,r,e,n,i,s);return ae.clearBuffer(),o}function Ip(r,t,e,n,i,s){let{float32Array:o,uint16Array:a,uint32Array:c}=ae,l=r*2;if(le(l,a)){let h=Ie(r,c),u=Fe(l,a);return vx(t,e,n,h,u,i,s)}else{let h=Yi(r,c),u=mA[h],g=n.direction[u]>=0,x,p;g?(x=xe(r),p=ve(r,c)):(x=ve(r,c),p=xe(r));let v=Hn(x,o,n,i,s)?Ip(x,t,e,n,i,s):null;if(v){let b=v.point[u];if(g?b<=o[p+h]:b>=o[p+h+3])return v}let y=Hn(p,o,n,i,s)?Ip(p,t,e,n,i,s):null;return v&&y?v.distance<=y.distance?v:y:v||y||null}}var Xu=new se,Ks=new tn,Qs=new tn,Ra=new gt,Rx=new Le,qu=new Le;function Cx(r,t,e,n){ae.setBuffer(r._roots[t]);let i=Pp(0,r,e,n);return ae.clearBuffer(),i}function Pp(r,t,e,n,i=null){let{float32Array:s,uint16Array:o,uint32Array:a}=ae,c=r*2;if(i===null&&(e.boundingBox||e.computeBoundingBox(),Rx.set(e.boundingBox.min,e.boundingBox.max,n),i=Rx),le(c,o)){let f=t.geometry,h=f.index,u=f.attributes.position,d=e.index,g=e.attributes.position,x=Ie(r,a),p=Fe(c,o);if(Ra.copy(n).invert(),e.boundsTree)return ye(r,s,qu),qu.matrix.copy(Ra),qu.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:v=>qu.intersectsBox(v),intersectsTriangle:v=>{v.a.applyMatrix4(n),v.b.applyMatrix4(n),v.c.applyMatrix4(n),v.needsUpdate=!0;for(let _=x,y=p+x;_Dp.distanceToBox(b),intersectsBounds:(b,T,w)=>w{if(t.boundsTree){let w=t.boundsTree;return w.shapecast({boundsTraverseOrder:E=>Ca.distanceToBox(E),intersectsBounds:(E,M,S)=>S{for(let S=E,I=E+M;Snew se),js=new se,to=new se,Fp=new se,Lp=new se,Np=!1;function Px(r,t,e,n){if(Np)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Np=!0;let i=r._roots,s=t._roots,o,a=0,c=0,l=new gt().copy(e).invert();for(let f=0,h=i.length;f2**16,i=r.reduce((l,f)=>l+f.count,0),s=n?4:2,o=t?new SharedArrayBuffer(i*s):new ArrayBuffer(i*s),a=n?new Uint32Array(o):new Uint16Array(o),c=0;for(let l=0;lthis._indirectBuffer[n]:n=>n,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,e={...Iu,...e},e[_a]||this.init(e)}init(t){let{geometry:e,primitiveStride:n}=this;if(t.indirect){let i=Sa(e,t.range,n),s=yA(i,t.useSharedArrayBuffer);this._indirectBuffer=s}else ix(e,t);super.init(t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new se))}computePrimitiveBounds(){throw new Error("BVH: computePrimitiveBounds() not implemented")}getRootRanges(t){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:Sa(this.geometry,t,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}shapecast(t){let{iterateDirect:e,iterateIndirect:n,...i}=t,s=this.indirect?n:e;return super.shapecast({...i,iterate:s})}};var Ju=new Le,Ku=new ii,Fx=new R,Lx=new gt,Nx=new R,Qu=class r extends Zu{static serialize(t,e={}){e={cloneBuffers:!0,...e};let n=t.geometry,i=t._roots,s=t._indirectBuffer,o=n.getIndex(),a={version:1,roots:null,index:null,indirectBuffer:null};return e.cloneBuffers?(a.roots=i.map(c=>c.slice()),a.index=o?o.array.slice():null,a.indirectBuffer=s?s.slice():null):(a.roots=i,a.index=o?o.array:null,a.indirectBuffer=s),a}static deserialize(t,e,n={}){n={setIndex:!0,indirect:!!t.indirectBuffer,...n};let{index:i,roots:s,indirectBuffer:o}=t;t.version||(console.warn("MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."),c(s));let a=new r(e,{...n,[_a]:!0});if(a._roots=s,a._indirectBuffer=o||null,n.setIndex){let l=e.getIndex();if(l===null){let f=new Ot(t.index,1,!1);e.setIndex(f)}else l.array!==i&&(l.array.set(i),l.needsUpdate=!0)}return a;function c(l){for(let f=0;fn.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");let l=o.array,f=o.offset||0,h=3;o.isInterleavedBufferAttribute&&(h=o.data.stride);let u=["getX","getY","getZ"],d=n.offset;for(let g=t,x=t+e;gI&&(I=E),M>I&&(I=M);let P=(I-S)/2,L=T*2;n[v+L+0]=S+P,n[v+L+1]=P+(Math.abs(S)+P)*Y0}}return n}raycastObject3D(t,e,n=[]){let{material:i}=t;if(i===void 0)return;Lx.copy(t.matrixWorld).invert(),Ku.copy(e.ray).applyMatrix4(Lx),Nx.setFromMatrixScale(t.matrixWorld),Fx.copy(Ku.direction).multiply(Nx);let s=Fx.length(),o=e.near/s,a=e.far/s;if(e.firstHitOnly===!0){let c=this.raycastFirst(Ku,i,o,a);c=Up(c,t,e),c&&n.push(c)}else{let c=this.raycast(Ku,i,o,a);for(let l=0,f=c.length;l{let x=this.resolveTriangleIndex(g);be(o,x*3,a,c)}:g=>{be(o,g*3,a,c)},f=pn.getPrimitive(),h=t.geometry.index,u=t.geometry.attributes.position,d=t.indirect?g=>{let x=t.resolveTriangleIndex(g);be(f,x*3,h,u)}:g=>{be(f,g*3,h,u)};if(s){let g=(x,p,m,v,_,y,b,T)=>{for(let w=m,E=m+v;wJu.intersectsBox(n),intersectsTriangle:n=>Ju.intersectsTriangle(n)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,n={},i={},s=0,o=1/0){return(this.indirect?Ix:Tx)(this,t,e,n,i,s,o)}closestPointToPoint(t,e={},n=0,i=1/0){return ax(this,t,e,n,i)}};function bA(r){switch(r){case 1:return"R";case 2:return"RG";case 3:return"RGBA";case 4:return"RGBA"}throw new Error}function SA(r){switch(r){case 1:return Jn;case 2:return Fr;case 3:return Gt;case 4:return Gt}}function Ux(r){switch(r){case 1:return Dr;case 2:return Wi;case 3:return Xi;case 4:return Xi}}var ju=class extends oe{constructor(){super(),this.minFilter=Vt,this.magFilter=Vt,this.generateMipmaps=!1,this.overrideItemSize=null,this._forcedType=null}updateFrom(t){let e=this.overrideItemSize,n=t.itemSize,i=t.count;if(e!==null){if(n*i%e!==0)throw new Error("VertexAttributeTexture: overrideItemSize must divide evenly into buffer length.");t.itemSize=e,t.count=i*n/e}let s=t.itemSize,o=t.count,a=t.normalized,c=t.array.constructor,l=c.BYTES_PER_ELEMENT,f=this._forcedType,h=s;if(f===null)switch(c){case Float32Array:f=$t;break;case Uint8Array:case Uint16Array:case Uint32Array:f=an;break;case Int8Array:case Int16Array:case Int32Array:f=Gi;break}let u,d,g,x,p=bA(s);switch(f){case $t:g=1,d=SA(s),a&&l===1?(x=c,p+="8",c===Uint8Array?u=on:(u=Bs,p+="_SNORM")):(x=Float32Array,p+="32F",u=$t);break;case Gi:p+=l*8+"I",g=a?Math.pow(2,c.BYTES_PER_ELEMENT*8-1):1,d=Ux(s),l===1?(x=Int8Array,u=Bs):l===2?(x=Int16Array,u=da):(x=Int32Array,u=Gi);break;case an:p+=l*8+"UI",g=a?Math.pow(2,c.BYTES_PER_ELEMENT*8-1):1,d=Ux(s),l===1?(x=Uint8Array,u=on):l===2?(x=Uint16Array,u=Hi):(x=Uint32Array,u=an);break}h===3&&(d===Gt||d===Xi)&&(h=4);let m=Math.ceil(Math.sqrt(o))||1,v=h*m*m,_=new x(v),y=t.normalized;t.normalized=!1;for(let b=0;b=2&&(_[T+1]=t.getY(b)/g),s>=3&&(_[T+2]=t.getZ(b)/g,h===4&&(_[T+3]=1)),s>=4&&(_[T+3]=t.getW(b)/g)}t.normalized=y,this.internalFormat=p,this.format=d,this.type=u,this.image.width=m,this.image.height=m,this.image.data=_,this.needsUpdate=!0,this.dispose(),t.itemSize=n,t.count=i}},eo=class extends ju{constructor(){super(),this._forcedType=an}};var no=class extends ju{constructor(){super(),this._forcedType=$t}};var th=class{constructor(){this.index=new eo,this.position=new no,this.bvhBounds=new oe,this.bvhContents=new oe,this._cachedIndexAttr=null,this.index.overrideItemSize=3}updateFrom(t){let{geometry:e}=t;if(TA(t,this.bvhBounds,this.bvhContents),this.position.updateFrom(e.attributes.position),t.indirect){let n=t._indirectBuffer;if(this._cachedIndexAttr===null||this._cachedIndexAttr.count!==n.length)if(e.index)this._cachedIndexAttr=e.index.clone();else{let i=Sp(ba(e));this._cachedIndexAttr=new Ot(i,1,!1)}MA(e,n,this._cachedIndexAttr),this.index.updateFrom(this._cachedIndexAttr)}else this.index.updateFrom(e.index)}dispose(){let{index:t,position:e,bvhBounds:n,bvhContents:i}=this;t&&t.dispose(),e&&e.dispose(),n&&n.dispose(),i&&i.dispose()}};function MA(r,t,e){let n=e.array,i=r.index?r.index.array:null;for(let s=0,o=t.length;sBx,bvh_ray_functions:()=>Op,bvh_struct_definitions:()=>Ox,common_functions:()=>Bp});var Bp=` + +// A stack of uint32 indices can can store the indices for +// a perfectly balanced tree with a depth up to 31. Lower stack +// depth gets higher performance. +// +// However not all trees are balanced. Best value to set this to +// is the trees max depth. +#ifndef BVH_STACK_DEPTH +#define BVH_STACK_DEPTH 60 +#endif + +#ifndef INFINITY +#define INFINITY 1e20 +#endif + +// Utilities +uvec4 uTexelFetch1D( usampler2D tex, uint index ) { + + uint width = uint( textureSize( tex, 0 ).x ); + uvec2 uv; + uv.x = index % width; + uv.y = index / width; + + return texelFetch( tex, ivec2( uv ), 0 ); + +} + +ivec4 iTexelFetch1D( isampler2D tex, uint index ) { + + uint width = uint( textureSize( tex, 0 ).x ); + uvec2 uv; + uv.x = index % width; + uv.y = index / width; + + return texelFetch( tex, ivec2( uv ), 0 ); + +} + +vec4 texelFetch1D( sampler2D tex, uint index ) { + + uint width = uint( textureSize( tex, 0 ).x ); + uvec2 uv; + uv.x = index % width; + uv.y = index / width; + + return texelFetch( tex, ivec2( uv ), 0 ); + +} + +vec4 textureSampleBarycoord( sampler2D tex, vec3 barycoord, uvec3 faceIndices ) { + + return + barycoord.x * texelFetch1D( tex, faceIndices.x ) + + barycoord.y * texelFetch1D( tex, faceIndices.y ) + + barycoord.z * texelFetch1D( tex, faceIndices.z ); + +} + +void ndcToCameraRay( + vec2 coord, mat4 cameraWorld, mat4 invProjectionMatrix, + out vec3 rayOrigin, out vec3 rayDirection +) { + + // get camera look direction and near plane for camera clipping + vec4 lookDirection = cameraWorld * vec4( 0.0, 0.0, - 1.0, 0.0 ); + vec4 nearVector = invProjectionMatrix * vec4( 0.0, 0.0, - 1.0, 1.0 ); + float near = abs( nearVector.z / nearVector.w ); + + // get the camera direction and position from camera matrices + vec4 origin = cameraWorld * vec4( 0.0, 0.0, 0.0, 1.0 ); + vec4 direction = invProjectionMatrix * vec4( coord, 0.5, 1.0 ); + direction /= direction.w; + direction = cameraWorld * direction - origin; + + // slide the origin along the ray until it sits at the near clip plane position + origin.xyz += direction.xyz * near / dot( direction, lookDirection ); + + rayOrigin = origin.xyz; + rayDirection = direction.xyz; + +} +`;var Bx=` + +float dot2( vec3 v ) { + + return dot( v, v ); + +} + +// https://www.shadertoy.com/view/ttfGWl +vec3 closestPointToTriangle( vec3 p, vec3 v0, vec3 v1, vec3 v2, out vec3 barycoord ) { + + vec3 v10 = v1 - v0; + vec3 v21 = v2 - v1; + vec3 v02 = v0 - v2; + + vec3 p0 = p - v0; + vec3 p1 = p - v1; + vec3 p2 = p - v2; + + vec3 nor = cross( v10, v02 ); + + // method 2, in barycentric space + vec3 q = cross( nor, p0 ); + float d = 1.0 / dot2( nor ); + float u = d * dot( q, v02 ); + float v = d * dot( q, v10 ); + float w = 1.0 - u - v; + + if( u < 0.0 ) { + + w = clamp( dot( p2, v02 ) / dot2( v02 ), 0.0, 1.0 ); + u = 0.0; + v = 1.0 - w; + + } else if( v < 0.0 ) { + + u = clamp( dot( p0, v10 ) / dot2( v10 ), 0.0, 1.0 ); + v = 0.0; + w = 1.0 - u; + + } else if( w < 0.0 ) { + + v = clamp( dot( p1, v21 ) / dot2( v21 ), 0.0, 1.0 ); + w = 0.0; + u = 1.0 - v; + + } + + barycoord = vec3( u, v, w ); + return u * v1 + v * v2 + w * v0; + +} + +float distanceToTriangles( + // geometry info and triangle range + sampler2D positionAttr, usampler2D indexAttr, uint offset, uint count, + + // point and cut off range + vec3 point, float closestDistanceSquared, + + // outputs + inout uvec4 faceIndices, inout vec3 faceNormal, inout vec3 barycoord, inout float side, inout vec3 outPoint +) { + + bool found = false; + vec3 localBarycoord; + for ( uint i = offset, l = offset + count; i < l; i ++ ) { + + uvec3 indices = uTexelFetch1D( indexAttr, i ).xyz; + vec3 a = texelFetch1D( positionAttr, indices.x ).rgb; + vec3 b = texelFetch1D( positionAttr, indices.y ).rgb; + vec3 c = texelFetch1D( positionAttr, indices.z ).rgb; + + // get the closest point and barycoord + vec3 closestPoint = closestPointToTriangle( point, a, b, c, localBarycoord ); + vec3 delta = point - closestPoint; + float sqDist = dot2( delta ); + if ( sqDist < closestDistanceSquared ) { + + // set the output results + closestDistanceSquared = sqDist; + faceIndices = uvec4( indices.xyz, i ); + faceNormal = normalize( cross( a - b, b - c ) ); + barycoord = localBarycoord; + outPoint = closestPoint; + side = sign( dot( faceNormal, delta ) ); + + } + + } + + return closestDistanceSquared; + +} + +float distanceSqToBounds( vec3 point, vec3 boundsMin, vec3 boundsMax ) { + + vec3 clampedPoint = clamp( point, boundsMin, boundsMax ); + vec3 delta = point - clampedPoint; + return dot( delta, delta ); + +} + +float distanceSqToBVHNodeBoundsPoint( vec3 point, sampler2D bvhBounds, uint currNodeIndex ) { + + uint cni2 = currNodeIndex * 2u; + vec3 boundsMin = texelFetch1D( bvhBounds, cni2 ).xyz; + vec3 boundsMax = texelFetch1D( bvhBounds, cni2 + 1u ).xyz; + return distanceSqToBounds( point, boundsMin, boundsMax ); + +} + +// use a macro to hide the fact that we need to expand the struct into separate fields +#define bvhClosestPointToPoint( bvh, point, maxDistance, faceIndices, faceNormal, barycoord, side, outPoint ) _bvhClosestPointToPoint( bvh.position, bvh.index, bvh.bvhBounds, bvh.bvhContents, point, maxDistance, faceIndices, faceNormal, barycoord, side, outPoint ) + +float _bvhClosestPointToPoint( + // bvh info + sampler2D bvh_position, usampler2D bvh_index, sampler2D bvh_bvhBounds, usampler2D bvh_bvhContents, + + // point to check + vec3 point, float maxDistance, + + // output variables + inout uvec4 faceIndices, inout vec3 faceNormal, inout vec3 barycoord, + inout float side, inout vec3 outPoint + ) { + + // stack needs to be twice as long as the deepest tree we expect because + // we push both the left and right child onto the stack every traversal + int ptr = 0; + uint stack[ BVH_STACK_DEPTH ]; + stack[ 0 ] = 0u; + + float closestDistanceSquared = maxDistance * maxDistance; + bool found = false; + while ( ptr > - 1 && ptr < BVH_STACK_DEPTH ) { + + uint currNodeIndex = stack[ ptr ]; + ptr --; + + // check if we intersect the current bounds + float boundsHitDistance = distanceSqToBVHNodeBoundsPoint( point, bvh_bvhBounds, currNodeIndex ); + if ( boundsHitDistance > closestDistanceSquared ) { + + continue; + + } + + uvec2 boundsInfo = uTexelFetch1D( bvh_bvhContents, currNodeIndex ).xy; + bool isLeaf = bool( boundsInfo.x & 0xffff0000u ); + if ( isLeaf ) { + + uint count = boundsInfo.x & 0x0000ffffu; + uint offset = boundsInfo.y; + closestDistanceSquared = distanceToTriangles( + bvh_position, bvh_index, offset, count, point, closestDistanceSquared, + + // outputs + faceIndices, faceNormal, barycoord, side, outPoint + ); + + } else { + + uint leftIndex = currNodeIndex + 1u; + uint splitAxis = boundsInfo.x & 0x0000ffffu; + uint rightIndex = currNodeIndex + boundsInfo.y; + bool leftToRight = distanceSqToBVHNodeBoundsPoint( point, bvh_bvhBounds, leftIndex ) < distanceSqToBVHNodeBoundsPoint( point, bvh_bvhBounds, rightIndex );//rayDirection[ splitAxis ] >= 0.0; + uint c1 = leftToRight ? leftIndex : rightIndex; + uint c2 = leftToRight ? rightIndex : leftIndex; + + // set c2 in the stack so we traverse it later. We need to keep track of a pointer in + // the stack while we traverse. The second pointer added is the one that will be + // traversed first + ptr ++; + stack[ ptr ] = c2; + ptr ++; + stack[ ptr ] = c1; + + } + + } + + return sqrt( closestDistanceSquared ); + +} +`;var Op=` + +#ifndef TRI_INTERSECT_EPSILON +#define TRI_INTERSECT_EPSILON 1e-5 +#endif + +// Raycasting +bool intersectsBounds( vec3 rayOrigin, vec3 rayDirection, vec3 boundsMin, vec3 boundsMax, out float dist ) { + + // https://www.reddit.com/r/opengl/comments/8ntzz5/fast_glsl_ray_box_intersection/ + // https://tavianator.com/2011/ray_box.html + vec3 invDir = 1.0 / rayDirection; + + // find intersection distances for each plane + vec3 tMinPlane = invDir * ( boundsMin - rayOrigin ); + vec3 tMaxPlane = invDir * ( boundsMax - rayOrigin ); + + // get the min and max distances from each intersection + vec3 tMinHit = min( tMaxPlane, tMinPlane ); + vec3 tMaxHit = max( tMaxPlane, tMinPlane ); + + // get the furthest hit distance + vec2 t = max( tMinHit.xx, tMinHit.yz ); + float t0 = max( t.x, t.y ); + + // get the minimum hit distance + t = min( tMaxHit.xx, tMaxHit.yz ); + float t1 = min( t.x, t.y ); + + // set distance to 0.0 if the ray starts inside the box + dist = max( t0, 0.0 ); + + return t1 >= dist; + +} + +bool intersectsTriangle( + vec3 rayOrigin, vec3 rayDirection, vec3 a, vec3 b, vec3 c, + out vec3 barycoord, out vec3 norm, out float dist, out float side +) { + + // https://stackoverflow.com/questions/42740765/intersection-between-line-and-triangle-in-3d + vec3 edge1 = b - a; + vec3 edge2 = c - a; + norm = cross( edge1, edge2 ); + + float det = - dot( rayDirection, norm ); + float invdet = 1.0 / det; + + vec3 AO = rayOrigin - a; + vec3 DAO = cross( AO, rayDirection ); + + vec4 uvt; + uvt.x = dot( edge2, DAO ) * invdet; + uvt.y = - dot( edge1, DAO ) * invdet; + uvt.z = dot( AO, norm ) * invdet; + uvt.w = 1.0 - uvt.x - uvt.y; + + // set the hit information + barycoord = uvt.wxy; // arranged in A, B, C order + dist = uvt.z; + side = sign( det ); + norm = side * normalize( norm ); + + // add an epsilon to avoid misses between triangles + uvt += vec4( TRI_INTERSECT_EPSILON ); + + return all( greaterThanEqual( uvt, vec4( 0.0 ) ) ); + +} + +bool intersectTriangles( + // geometry info and triangle range + sampler2D positionAttr, usampler2D indexAttr, uint offset, uint count, + + // ray + vec3 rayOrigin, vec3 rayDirection, + + // outputs + inout float minDistance, inout uvec4 faceIndices, inout vec3 faceNormal, inout vec3 barycoord, + inout float side, inout float dist +) { + + bool found = false; + vec3 localBarycoord, localNormal; + float localDist, localSide; + for ( uint i = offset, l = offset + count; i < l; i ++ ) { + + uvec3 indices = uTexelFetch1D( indexAttr, i ).xyz; + vec3 a = texelFetch1D( positionAttr, indices.x ).rgb; + vec3 b = texelFetch1D( positionAttr, indices.y ).rgb; + vec3 c = texelFetch1D( positionAttr, indices.z ).rgb; + + if ( + intersectsTriangle( rayOrigin, rayDirection, a, b, c, localBarycoord, localNormal, localDist, localSide ) + && localDist < minDistance + ) { + + found = true; + minDistance = localDist; + + faceIndices = uvec4( indices.xyz, i ); + faceNormal = localNormal; + + side = localSide; + barycoord = localBarycoord; + dist = localDist; + + } + + } + + return found; + +} + +bool intersectsBVHNodeBounds( vec3 rayOrigin, vec3 rayDirection, sampler2D bvhBounds, uint currNodeIndex, out float dist ) { + + uint cni2 = currNodeIndex * 2u; + vec3 boundsMin = texelFetch1D( bvhBounds, cni2 ).xyz; + vec3 boundsMax = texelFetch1D( bvhBounds, cni2 + 1u ).xyz; + return intersectsBounds( rayOrigin, rayDirection, boundsMin, boundsMax, dist ); + +} + +// use a macro to hide the fact that we need to expand the struct into separate fields +#define bvhIntersectFirstHit( bvh, rayOrigin, rayDirection, faceIndices, faceNormal, barycoord, side, dist ) _bvhIntersectFirstHit( bvh.position, bvh.index, bvh.bvhBounds, bvh.bvhContents, rayOrigin, rayDirection, faceIndices, faceNormal, barycoord, side, dist ) + +bool _bvhIntersectFirstHit( + // bvh info + sampler2D bvh_position, usampler2D bvh_index, sampler2D bvh_bvhBounds, usampler2D bvh_bvhContents, + + // ray + vec3 rayOrigin, vec3 rayDirection, + + // output variables split into separate variables due to output precision + inout uvec4 faceIndices, inout vec3 faceNormal, inout vec3 barycoord, + inout float side, inout float dist +) { + + // stack needs to be twice as long as the deepest tree we expect because + // we push both the left and right child onto the stack every traversal + int ptr = 0; + uint stack[ BVH_STACK_DEPTH ]; + stack[ 0 ] = 0u; + + float triangleDistance = INFINITY; + bool found = false; + while ( ptr > - 1 && ptr < BVH_STACK_DEPTH ) { + + uint currNodeIndex = stack[ ptr ]; + ptr --; + + // check if we intersect the current bounds + float boundsHitDistance; + if ( + ! intersectsBVHNodeBounds( rayOrigin, rayDirection, bvh_bvhBounds, currNodeIndex, boundsHitDistance ) + || boundsHitDistance > triangleDistance + ) { + + continue; + + } + + uvec2 boundsInfo = uTexelFetch1D( bvh_bvhContents, currNodeIndex ).xy; + bool isLeaf = bool( boundsInfo.x & 0xffff0000u ); + + if ( isLeaf ) { + + uint count = boundsInfo.x & 0x0000ffffu; + uint offset = boundsInfo.y; + + found = intersectTriangles( + bvh_position, bvh_index, offset, count, + rayOrigin, rayDirection, triangleDistance, + faceIndices, faceNormal, barycoord, side, dist + ) || found; + + } else { + + uint leftIndex = currNodeIndex + 1u; + uint splitAxis = boundsInfo.x & 0x0000ffffu; + uint rightIndex = currNodeIndex + boundsInfo.y; + + bool leftToRight = rayDirection[ splitAxis ] >= 0.0; + uint c1 = leftToRight ? leftIndex : rightIndex; + uint c2 = leftToRight ? rightIndex : leftIndex; + + // set c2 in the stack so we traverse it later. We need to keep track of a pointer in + // the stack while we traverse. The second pointer added is the one that will be + // traversed first + ptr ++; + stack[ ptr ] = c2; + + ptr ++; + stack[ ptr ] = c1; + + } + + } + + return found; + +} +`;var Ox=` +struct BVH { + + usampler2D index; + sampler2D position; + + sampler2D bvhBounds; + usampler2D bvhContents; + +}; +`;var pC=` + ${Bp} + ${Op} +`;function eh(r,t,e=0){if(r.isInterleavedBufferAttribute){let n=r.itemSize;for(let i=0,s=r.count;i=2&&t.setY(o,r.getY(i)),n>=3&&t.setZ(o,r.getZ(i)),n>=4&&t.setW(o,r.getW(i))}}else{let n=t.array,i=n.constructor,s=n.BYTES_PER_ELEMENT*r.itemSize*e;new i(n.buffer,s,r.array.length).set(r.array)}}function Gr(r,t=null){let e=r.array.constructor,n=r.normalized,i=r.itemSize,s=t===null?r.count:t;return new Ot(new e(i*s),i,n)}function ji(r,t){if(!r&&!t)return!0;if(!!r!=!!t)return!1;let e=r.count===t.count,n=r.normalized===t.normalized,i=r.array.constructor===t.array.constructor,s=r.itemSize===t.itemSize;return!(!e||!n||!i||!s)}function wA(r){let t=r[0].index!==null,e=new Set(Object.keys(r[0].attributes));if(!r[0].getAttribute("position"))throw new Error("StaticGeometryGenerator: position attribute is required.");for(let n=0;n{s.isMesh&&t(s)})}function DA(r){let t=[];for(let e=0,n=r.length;e{t.push(e)}),t.sort((e,n)=>e.uuid>n.uuid?1:e.uuid{t.delete(s)})}setObjects(t){Array.isArray(t)?this.objects=[...t]:this.objects=[t]}generate(t=new Ft){let{useGroups:e,overwriteIndex:n,_intermediateGeometry:i,_geometryMergeSets:s}=this,o=this._getMeshes(),a=[],c=[],l=s.get(t)||[];this._updateIntermediateGeometries();let f=!1;o.length!==l.length&&(f=!0);for(let u=0,d=o.length;u({version:u.version,uuid:u.uuid})));let h=ah;return f?h=Hp:a.includes(!1)&&(h=Vp),{changeType:h,materials:DA(o),geometry:t}}};function LA(r){let t=new Set;for(let e=0,n=r.length;e{o.visible&&(o.isRectAreaLight||o.isSpotLight||o.isPointLight||o.isDirectionalLight)&&(t.push(o),o.iesMap&&e.add(o.iesMap))});let n=Array.from(e).sort((i,s)=>i.uuids.uuid?-1:0);return{lights:t,iesTextures:n}}var ch=class{get initialized(){return!!this.bvh}constructor(t){this.bvhOptions={},this.attributes=["position","normal","tangent","color","uv","uv2"],this.generateBVH=!0,this.bvh=null,this.geometry=new Ft,this.staticGeometryGenerator=new oh(t),this._bvhWorker=null,this._pendingGenerate=null,this._buildAsync=!1,this._materialUuids=null}setObjects(t){this.staticGeometryGenerator.setObjects(t)}setBVHWorker(t){this._bvhWorker=t}async generateAsync(t=null){if(!this._bvhWorker)throw new Error('PathTracingSceneGenerator: "setBVHWorker" must be called before "generateAsync" can be called.');if(this.bvh instanceof Promise)return this._pendingGenerate||(this._pendingGenerate=new Promise(async()=>(await this.bvh,this._pendingGenerate=null,this.generateAsync(t)))),this._pendingGenerate;{this._buildAsync=!0;let e=this.generate(t);return this._buildAsync=!1,e.bvh=this.bvh=await e.bvh,e}}generate(t=null){let{staticGeometryGenerator:e,geometry:n,attributes:i}=this,s=e.objects;e.attributes=i,s.forEach(u=>{u.traverse(d=>{d.isSkinnedMesh&&d.skeleton&&d.skeleton.update()})});let o=e.generate(n),a=o.materials,c=o.changeType!==ah||this._materialUuids===null||this._materialUuids.length!==length;if(!c){for(let u=0,d=a.length;uu.uuid)),this.generateBVH){if(this.bvh instanceof Promise)throw new Error("PathTracingSceneGenerator: BVH is already building asynchronously.");if(o.changeType===Hp){let u={strategy:2,maxLeafTris:1,indirect:!0,onProgress:t,...this.bvhOptions};this._buildAsync?this.bvh=this._bvhWorker.generate(n,u):this.bvh=new Qu(n,u)}else o.changeType===Vp&&this.bvh.refit()}return{bvhChanged:o.changeType!==ah,bvh:this.bvh,needsMaterialIndexUpdate:c,lights:f,iesTextures:h,geometry:n,materials:a,textures:l,objects:s}}};var UA=new ki(-1,1,1,-1,0,1),Gp=class extends Ft{constructor(){super(),this.setAttribute("position",new bt([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new bt([0,2,0,0,2,0],2))}},BA=new Gp,Fn=class{constructor(t){this._mesh=new Me(BA,t)}dispose(){this._mesh.geometry.dispose()}render(t){t.render(this._mesh,UA)}get material(){return this._mesh.material}set material(t){this._mesh.material=t}};var li=class extends Ue{set needsUpdate(t){super.needsUpdate=!0,this.dispatchEvent({type:"recompilation"})}constructor(t){super(t);for(let e in this.uniforms)Object.defineProperty(this,e,{get(){return this.uniforms[e].value},set(n){this.uniforms[e].value=n}})}setDefine(t,e=void 0){if(e==null){if(t in this.defines)return delete this.defines[t],this.needsUpdate=!0,!0}else if(this.defines[t]!==e)return this.defines[t]=e,this.needsUpdate=!0,!0;return!1}};var lh=class extends li{constructor(t){super({blending:ke,uniforms:{target1:{value:null},target2:{value:null},opacity:{value:1}},vertexShader:` + + varying vec2 vUv; + + void main() { + + vUv = uv; + gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); + + }`,fragmentShader:` + + uniform float opacity; + + uniform sampler2D target1; + uniform sampler2D target2; + + varying vec2 vUv; + + void main() { + + vec4 color1 = texture2D( target1, vUv ); + vec4 color2 = texture2D( target2, vUv ); + + float invOpacity = 1.0 - opacity; + float totalAlpha = color1.a * invOpacity + color2.a * opacity; + + if ( color1.a != 0.0 || color2.a != 0.0 ) { + + gl_FragColor.rgb = color1.rgb * ( invOpacity * color1.a / totalAlpha ) + color2.rgb * ( opacity * color2.a / totalAlpha ); + gl_FragColor.a = totalAlpha; + + } else { + + gl_FragColor = vec4( 0.0 ); + + } + + }`}),this.setValues(t)}};function uh(r=1){let t="uint";return r>1&&(t="uvec"+r),` + ${t} sobolReverseBits( ${t} x ) { + + x = ( ( ( x & 0xaaaaaaaau ) >> 1 ) | ( ( x & 0x55555555u ) << 1 ) ); + x = ( ( ( x & 0xccccccccu ) >> 2 ) | ( ( x & 0x33333333u ) << 2 ) ); + x = ( ( ( x & 0xf0f0f0f0u ) >> 4 ) | ( ( x & 0x0f0f0f0fu ) << 4 ) ); + x = ( ( ( x & 0xff00ff00u ) >> 8 ) | ( ( x & 0x00ff00ffu ) << 8 ) ); + return ( ( x >> 16 ) | ( x << 16 ) ); + + } + + ${t} sobolHashCombine( uint seed, ${t} v ) { + + return seed ^ ( v + ${t}( ( seed << 6 ) + ( seed >> 2 ) ) ); + + } + + ${t} sobolLaineKarrasPermutation( ${t} x, ${t} seed ) { + + x += seed; + x ^= x * 0x6c50b47cu; + x ^= x * 0xb82f1e52u; + x ^= x * 0xc7afe638u; + x ^= x * 0x8d22f6e6u; + return x; + + } + + ${t} nestedUniformScrambleBase2( ${t} x, ${t} seed ) { + + x = sobolLaineKarrasPermutation( x, seed ); + x = sobolReverseBits( x ); + return x; + + } + `}function hh(r=1){let t="uint",e="float",n="",i=".r",s="1u";return r>1&&(t="uvec"+r,e="vec"+r,n=r+"",r===2?(i=".rg",s="uvec2( 1u, 2u )"):r===3?(i=".rgb",s="uvec3( 1u, 2u, 3u )"):(i="",s="uvec4( 1u, 2u, 3u, 4u )")),` + + ${e} sobol${n}( int effect ) { + + uint seed = sobolGetSeed( sobolBounceIndex, uint( effect ) ); + uint index = sobolPathIndex; + + uint shuffle_seed = sobolHashCombine( seed, 0u ); + uint shuffled_index = nestedUniformScrambleBase2( sobolReverseBits( index ), shuffle_seed ); + ${e} sobol_pt = sobolGetTexturePoint( shuffled_index )${i}; + ${t} result = ${t}( sobol_pt * 16777216.0 ); + + ${t} seed2 = sobolHashCombine( seed, ${s} ); + result = nestedUniformScrambleBase2( result, seed2 ); + + return SOBOL_FACTOR * ${e}( result >> 8 ); + + } + `}var fh=` + + // Utils + const float SOBOL_FACTOR = 1.0 / 16777216.0; + const uint SOBOL_MAX_POINTS = 256u * 256u; + + ${uh(1)} + ${uh(2)} + ${uh(3)} + ${uh(4)} + + uint sobolHash( uint x ) { + + // finalizer from murmurhash3 + x ^= x >> 16; + x *= 0x85ebca6bu; + x ^= x >> 13; + x *= 0xc2b2ae35u; + x ^= x >> 16; + return x; + + } + +`,Jx=` + + const uint SOBOL_DIRECTIONS_1[ 32 ] = uint[ 32 ]( + 0x80000000u, 0xc0000000u, 0xa0000000u, 0xf0000000u, + 0x88000000u, 0xcc000000u, 0xaa000000u, 0xff000000u, + 0x80800000u, 0xc0c00000u, 0xa0a00000u, 0xf0f00000u, + 0x88880000u, 0xcccc0000u, 0xaaaa0000u, 0xffff0000u, + 0x80008000u, 0xc000c000u, 0xa000a000u, 0xf000f000u, + 0x88008800u, 0xcc00cc00u, 0xaa00aa00u, 0xff00ff00u, + 0x80808080u, 0xc0c0c0c0u, 0xa0a0a0a0u, 0xf0f0f0f0u, + 0x88888888u, 0xccccccccu, 0xaaaaaaaau, 0xffffffffu + ); + + const uint SOBOL_DIRECTIONS_2[ 32 ] = uint[ 32 ]( + 0x80000000u, 0xc0000000u, 0x60000000u, 0x90000000u, + 0xe8000000u, 0x5c000000u, 0x8e000000u, 0xc5000000u, + 0x68800000u, 0x9cc00000u, 0xee600000u, 0x55900000u, + 0x80680000u, 0xc09c0000u, 0x60ee0000u, 0x90550000u, + 0xe8808000u, 0x5cc0c000u, 0x8e606000u, 0xc5909000u, + 0x6868e800u, 0x9c9c5c00u, 0xeeee8e00u, 0x5555c500u, + 0x8000e880u, 0xc0005cc0u, 0x60008e60u, 0x9000c590u, + 0xe8006868u, 0x5c009c9cu, 0x8e00eeeeu, 0xc5005555u + ); + + const uint SOBOL_DIRECTIONS_3[ 32 ] = uint[ 32 ]( + 0x80000000u, 0xc0000000u, 0x20000000u, 0x50000000u, + 0xf8000000u, 0x74000000u, 0xa2000000u, 0x93000000u, + 0xd8800000u, 0x25400000u, 0x59e00000u, 0xe6d00000u, + 0x78080000u, 0xb40c0000u, 0x82020000u, 0xc3050000u, + 0x208f8000u, 0x51474000u, 0xfbea2000u, 0x75d93000u, + 0xa0858800u, 0x914e5400u, 0xdbe79e00u, 0x25db6d00u, + 0x58800080u, 0xe54000c0u, 0x79e00020u, 0xb6d00050u, + 0x800800f8u, 0xc00c0074u, 0x200200a2u, 0x50050093u + ); + + const uint SOBOL_DIRECTIONS_4[ 32 ] = uint[ 32 ]( + 0x80000000u, 0x40000000u, 0x20000000u, 0xb0000000u, + 0xf8000000u, 0xdc000000u, 0x7a000000u, 0x9d000000u, + 0x5a800000u, 0x2fc00000u, 0xa1600000u, 0xf0b00000u, + 0xda880000u, 0x6fc40000u, 0x81620000u, 0x40bb0000u, + 0x22878000u, 0xb3c9c000u, 0xfb65a000u, 0xddb2d000u, + 0x78022800u, 0x9c0b3c00u, 0x5a0fb600u, 0x2d0ddb00u, + 0xa2878080u, 0xf3c9c040u, 0xdb65a020u, 0x6db2d0b0u, + 0x800228f8u, 0x400b3cdcu, 0x200fb67au, 0xb00ddb9du + ); + + uint getMaskedSobol( uint index, uint directions[ 32 ] ) { + + uint X = 0u; + for ( int bit = 0; bit < 32; bit ++ ) { + + uint mask = ( index >> bit ) & 1u; + X ^= mask * directions[ bit ]; + + } + return X; + + } + + vec4 generateSobolPoint( uint index ) { + + if ( index >= SOBOL_MAX_POINTS ) { + + return vec4( 0.0 ); + + } + + // NOTE: this sobol "direction" is also available but we can't write out 5 components + // uint x = index & 0x00ffffffu; + uint x = sobolReverseBits( getMaskedSobol( index, SOBOL_DIRECTIONS_1 ) ) & 0x00ffffffu; + uint y = sobolReverseBits( getMaskedSobol( index, SOBOL_DIRECTIONS_2 ) ) & 0x00ffffffu; + uint z = sobolReverseBits( getMaskedSobol( index, SOBOL_DIRECTIONS_3 ) ) & 0x00ffffffu; + uint w = sobolReverseBits( getMaskedSobol( index, SOBOL_DIRECTIONS_4 ) ) & 0x00ffffffu; + + return vec4( x, y, z, w ) * SOBOL_FACTOR; + + } + +`,Kx=` + + // Seeds + uniform sampler2D sobolTexture; + uint sobolPixelIndex = 0u; + uint sobolPathIndex = 0u; + uint sobolBounceIndex = 0u; + + uint sobolGetSeed( uint bounce, uint effect ) { + + return sobolHash( + sobolHashCombine( + sobolHashCombine( + sobolHash( bounce ), + sobolPixelIndex + ), + effect + ) + ); + + } + + vec4 sobolGetTexturePoint( uint index ) { + + if ( index >= SOBOL_MAX_POINTS ) { + + index = index % SOBOL_MAX_POINTS; + + } + + uvec2 dim = uvec2( textureSize( sobolTexture, 0 ).xy ); + uint y = index / dim.x; + uint x = index - y * dim.x; + vec2 uv = vec2( x, y ) / vec2( dim ); + return texture( sobolTexture, uv ); + + } + + ${hh(1)} + ${hh(2)} + ${hh(3)} + ${hh(4)} + +`;var Wp=class extends li{constructor(){super({blending:ke,uniforms:{resolution:{value:new q}},vertexShader:` + + varying vec2 vUv; + void main() { + + vUv = uv; + gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); + + } + `,fragmentShader:` + + ${fh} + ${Jx} + + varying vec2 vUv; + uniform vec2 resolution; + void main() { + + uint index = uint( gl_FragCoord.y ) * uint( resolution.x ) + uint( gl_FragCoord.x ); + gl_FragColor = generateSobolPoint( index ); + + } + `})}},dh=class{generate(t,e=256){let n=new ze(e,e,{type:$t,format:Gt,minFilter:Vt,magFilter:Vt,generateMipmaps:!1}),i=t.getRenderTarget();t.setRenderTarget(n);let s=new Fn(new Wp);return s.material.resolution.set(e,e),s.render(t),t.setRenderTarget(i),s.dispose(),n}};var Pa=class extends Re{set bokehSize(t){this.fStop=this.getFocalLength()/t}get bokehSize(){return this.getFocalLength()/this.fStop}constructor(...t){super(...t),this.fStop=1.4,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=25,this.anamorphicRatio=1}copy(t,e){return super.copy(t,e),this.fStop=t.fStop,this.apertureBlades=t.apertureBlades,this.apertureRotation=t.apertureRotation,this.focusDistance=t.focusDistance,this.anamorphicRatio=t.anamorphicRatio,this}};var ph=class{constructor(){this.bokehSize=0,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=10,this.anamorphicRatio=1}updateFrom(t){t instanceof Pa?(this.bokehSize=t.bokehSize,this.apertureBlades=t.apertureBlades,this.apertureRotation=t.apertureRotation,this.focusDistance=t.focusDistance,this.anamorphicRatio=t.anamorphicRatio):(this.bokehSize=0,this.apertureRotation=0,this.apertureBlades=0,this.focusDistance=10,this.anamorphicRatio=1)}};function mh(r){let t=new Uint16Array(r.length);for(let e=0,n=r.length;e>1;r[o]n)throw new Error;let s=r.length/t,o=r.constructor.BYTES_PER_ELEMENT*8,a=1;switch(r.constructor){case Uint8Array:case Uint16Array:case Uint32Array:a=2**o-1;break;case Int8Array:case Int16Array:case Int32Array:a=2**(o-1)-1;break}for(let c=0;c=h+1?r[f+h]/a:0}}var vh=class extends Ui{constructor(){super(),this._textures=[],this.type=$t,this.format=Gt,this.internalFormat="RGBA32F"}updateAttribute(t,e){let n=this._textures[t];n.updateFrom(e);let i=n.image,s=this.image;if(i.width!==s.width||i.height!==s.height)throw new Error("FloatAttributeTextureArray: Attribute must be the same dimensions when updating single layer.");let{width:o,height:a,data:c}=s,f=o*a*4*t,h=e.itemSize;h===3&&(h=4),ev(n.image.data,h,c,4,f),this.dispose(),this.needsUpdate=!0}setAttributes(t){let e=t[0].count,n=t.length;for(let h=0,u=n;hn;)i.pop();for(let h=0,u=n;ht.uuid?-1:0}function yh(r){return`${r.source.uuid}:${r.colorSpace}`}function qA(r){let t=new Set,e=[];for(let n=0,i=r.length;nn.iesMap||null).filter(n=>n),e=new Set(t);return Array.from(e).sort(qp)}function iv(r){let t=new Set;for(let n=0,i=r.length;n{e.visible&&(e.isRectAreaLight||e.isSpotLight||e.isPointLight||e.isDirectionalLight)&&t.push(e)}),t.sort(qp)}var Sh=47,sv=Sh*4,Yp=class{constructor(){this._features={}}isUsed(t){return t in this._features}setUsed(t,e=!0){e===!1?delete this._features[t]:this._features[t]=!0}reset(){this._features={}}},bh=class extends oe{constructor(){super(new Float32Array(4),1,1),this.format=Gt,this.type=$t,this.wrapS=we,this.wrapT=we,this.minFilter=Vt,this.magFilter=Vt,this.generateMipmaps=!1,this.features=new Yp}updateFrom(t,e){function n(g,x,p=-1){if(x in g&&g[x]){let m=yh(g[x]);return h[m]}else return p}function i(g,x,p){return x in g?g[x]:p}function s(g,x,p,m){let v=g[x]&&g[x].isTexture?g[x]:null;if(v){v.matrixAutoUpdate&&v.updateMatrix();let _=v.matrix.elements,y=0;p[m+y++]=_[0],p[m+y++]=_[3],p[m+y++]=_[6],y++,p[m+y++]=_[1],p[m+y++]=_[4],p[m+y++]=_[7],y++}return 8}let o=0,a=t.length*Sh,c=Math.ceil(Math.sqrt(a))||1,{image:l,features:f}=this,h={};for(let g=0,x=e.length;g0)u[o++]=0;else switch(p.side){case yn:u[o++]=1;break;case He:u[o++]=-1;break;case Sn:u[o++]=0;break}u[o++]=Number(i(p,"matte",!1)),u[o++]=Number(i(p,"castShadow",!0)),u[o++]=Number(p.vertexColors)|Number(p.flatShading)<<1,u[o++]=Number(p.transparent),o+=s(p,"map",u,o),o+=s(p,"metalnessMap",u,o),o+=s(p,"roughnessMap",u,o),o+=s(p,"transmissionMap",u,o),o+=s(p,"emissiveMap",u,o),o+=s(p,"normalMap",u,o),o+=s(p,"clearcoatMap",u,o),o+=s(p,"clearcoatNormalMap",u,o),o+=s(p,"clearcoatRoughnessMap",u,o),o+=s(p,"sheenColorMap",u,o),o+=s(p,"sheenRoughnessMap",u,o),o+=s(p,"iridescenceMap",u,o),o+=s(p,"iridescenceThicknessMap",u,o),o+=s(p,"specularColorMap",u,o),o+=s(p,"specularIntensityMap",u,o),o+=s(p,"alphaMap",u,o)}let d=io(u.buffer);return this.hash!==d?(this.hash=d,this.needsUpdate=!0,!0):!1}};var ov=new ft;function YA(r){return r?`${r.uuid}:${r.version}`:null}function $A(r,t){for(let e in t)e in r&&(r[e]=t[e])}var Da=class extends Do{constructor(t,e,n){let i={format:Gt,type:on,minFilter:re,magFilter:re,wrapS:Ke,wrapT:Ke,generateMipmaps:!1,...n};super(t,e,1,i),$A(this.texture,i),this.texture.setTextures=(...o)=>{this.setTextures(...o)},this.hashes=[null];let s=new Fn(new $p);this.fsQuad=s}setTextures(t,e,n=this.width,i=this.height){let s=t.getRenderTarget(),o=t.toneMapping,a=t.getClearAlpha();t.getClearColor(ov);let c=e.length||1;(n!==this.width||i!==this.height||this.depth!==c)&&(this.setSize(n,i,c),this.hashes=new Array(c).fill(null)),t.setClearColor(0,0),t.toneMapping=Zn;let l=this.fsQuad,f=this.hashes,h=!1;for(let u=0,d=c;u0;e--){let n=Math.floor(t()*(e+1)),i=r[e];r[e]=r[n],r[n]=i}return r}var Mh=class{constructor(t,e,n=Math.random){let i=t**e,s=new Uint16Array(i),o=i;for(let a=0;a=s.length&&(ZA(s,n),this.reshuffle());let c=s[o++];for(let l=0;lthis.stableNoise?this.generator.nextFloat():Math.random(),this.init(t,e,n)}init(t=this.image.height,e=this.image.width,n=this.strata){let{image:i}=this;if(i.width===e&&i.height===t&&this.sampler!==null)return;let s=new Array(t*e).fill(4),o=new Th(n,s,this.random);i.width=e,i.height=t,i.data=o.samples,this.sampler=o,this.dispose(),this.next()}next(){this.sampler.next(),this.needsUpdate=!0}reset(){this.sampler.reset(),this.generator.seed=0}};function av(r,t=Math.random){for(let e=r.length-1;e>0;e--){let n=~~((t()-1e-6)*e),i=r[e];r[e]=r[n],r[n]=i}}function cv(r,t){r.fill(0);for(let e=0;en&&(n=a,i=s)}return i}setSigma(t){if(t===this.sigma)return;let e=~~(Math.sqrt(20*t**2)+1),n=2*e+1,i=new Float32Array(n*n),s=t*t;for(let o=-e;o<=e;o++)for(let a=-e;a<=e;a++){let c=(e+a)*n+o+e,l=o*o+a*a;i[c]=Math.E**(-l/(2*s))}this.lookupTable=i,this.sigma=t,this.radius=e}resize(t){this.size!==t&&(this.size=t,this.score=new Float32Array(t*t),this.binaryPattern=new Uint8Array(t*t))}invert(){let{binaryPattern:t,score:e,size:n}=this;e.fill(0);for(let i=0,s=t.length;i=0;){let h=t.findCluster();t.removePointIndex(h),c[h]=l,l--}let f=s*s;for(l=e.count;l=3?4:r}function KA(r){switch(r){case 1:return Jn;case 2:return Fr;default:return Gt}}var Eh=class extends oe{constructor(t=64,e=1){super(new Float32Array(4),1,1,Gt,$t),this.minFilter=Vt,this.magFilter=Vt,this.size=t,this.channels=e,this.update()}update(){let t=this.channels,e=this.size,n=new Ah;n.channels=t,n.size=e;let i=JA(t),s=KA(i);(this.image.width!==e||s!==this.format)&&(this.image.width=e,this.image.height=e,this.image.data=new Float32Array(e**2*i),this.format=s,this.dispose());let o=this.image.data;for(let a=0,c=t;a 0.0 ) { + + distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) ); + + } + + return distanceFalloff; + + } + + float getPhotometricAttenuation( sampler2DArray iesProfiles, int iesProfile, vec3 posToLight, vec3 lightDir, vec3 u, vec3 v ) { + + float cosTheta = dot( posToLight, lightDir ); + float angle = acos( cosTheta ) / PI; + + return texture2D( iesProfiles, vec3( angle, 0.0, iesProfile ) ).r; + + } + + struct LightRecord { + + float dist; + vec3 direction; + float pdf; + vec3 emission; + int type; + + }; + + bool intersectLightAtIndex( sampler2D lights, vec3 rayOrigin, vec3 rayDirection, uint l, inout LightRecord lightRec ) { + + bool didHit = false; + Light light = readLightInfo( lights, l ); + + vec3 u = light.u; + vec3 v = light.v; + + // check for backface + vec3 normal = normalize( cross( u, v ) ); + if ( dot( normal, rayDirection ) > 0.0 ) { + + u *= 1.0 / dot( u, u ); + v *= 1.0 / dot( v, v ); + + float dist; + + // MIS / light intersection is not supported for punctual lights. + if( + ( light.type == RECT_AREA_LIGHT_TYPE && intersectsRectangle( light.position, normal, u, v, rayOrigin, rayDirection, dist ) ) || + ( light.type == CIRC_AREA_LIGHT_TYPE && intersectsCircle( light.position, normal, u, v, rayOrigin, rayDirection, dist ) ) + ) { + + float cosTheta = dot( rayDirection, normal ); + didHit = true; + lightRec.dist = dist; + lightRec.pdf = ( dist * dist ) / ( light.area * cosTheta ); + lightRec.emission = light.color * light.intensity; + lightRec.direction = rayDirection; + lightRec.type = light.type; + + } + + } + + return didHit; + + } + + LightRecord randomAreaLightSample( Light light, vec3 rayOrigin, vec2 ruv ) { + + vec3 randomPos; + if( light.type == RECT_AREA_LIGHT_TYPE ) { + + // rectangular area light + randomPos = light.position + light.u * ( ruv.x - 0.5 ) + light.v * ( ruv.y - 0.5 ); + + } else if( light.type == CIRC_AREA_LIGHT_TYPE ) { + + // circular area light + float r = 0.5 * sqrt( ruv.x ); + float theta = ruv.y * 2.0 * PI; + float x = r * cos( theta ); + float y = r * sin( theta ); + + randomPos = light.position + light.u * x + light.v * y; + + } + + vec3 toLight = randomPos - rayOrigin; + float lightDistSq = dot( toLight, toLight ); + float dist = sqrt( lightDistSq ); + vec3 direction = toLight / dist; + vec3 lightNormal = normalize( cross( light.u, light.v ) ); + + LightRecord lightRec; + lightRec.type = light.type; + lightRec.emission = light.color * light.intensity; + lightRec.dist = dist; + lightRec.direction = direction; + + // TODO: the denominator is potentially zero + lightRec.pdf = lightDistSq / ( light.area * dot( direction, lightNormal ) ); + + return lightRec; + + } + + LightRecord randomSpotLightSample( Light light, sampler2DArray iesProfiles, vec3 rayOrigin, vec2 ruv ) { + + float radius = light.radius * sqrt( ruv.x ); + float theta = ruv.y * 2.0 * PI; + float x = radius * cos( theta ); + float y = radius * sin( theta ); + + vec3 u = light.u; + vec3 v = light.v; + vec3 normal = normalize( cross( u, v ) ); + + float angle = acos( light.coneCos ); + float angleTan = tan( angle ); + float startDistance = light.radius / max( angleTan, EPSILON ); + + vec3 randomPos = light.position - normal * startDistance + u * x + v * y; + vec3 toLight = randomPos - rayOrigin; + float lightDistSq = dot( toLight, toLight ); + float dist = sqrt( lightDistSq ); + + vec3 direction = toLight / max( dist, EPSILON ); + float cosTheta = dot( direction, normal ); + + float spotAttenuation = light.iesProfile != - 1 ? + getPhotometricAttenuation( iesProfiles, light.iesProfile, direction, normal, u, v ) : + getSpotAttenuation( light.coneCos, light.penumbraCos, cosTheta ); + + float distanceAttenuation = getDistanceAttenuation( dist, light.distance, light.decay ); + LightRecord lightRec; + lightRec.type = light.type; + lightRec.dist = dist; + lightRec.direction = direction; + lightRec.emission = light.color * light.intensity * distanceAttenuation * spotAttenuation; + lightRec.pdf = 1.0; + + return lightRec; + + } + + LightRecord randomLightSample( sampler2D lights, sampler2DArray iesProfiles, uint lightCount, vec3 rayOrigin, vec3 ruv ) { + + LightRecord result; + + // pick a random light + uint l = uint( ruv.x * float( lightCount ) ); + Light light = readLightInfo( lights, l ); + + if ( light.type == SPOT_LIGHT_TYPE ) { + + result = randomSpotLightSample( light, iesProfiles, rayOrigin, ruv.yz ); + + } else if ( light.type == POINT_LIGHT_TYPE ) { + + vec3 lightRay = light.u - rayOrigin; + float lightDist = length( lightRay ); + float cutoffDistance = light.distance; + float distanceFalloff = 1.0 / max( pow( lightDist, light.decay ), 0.01 ); + if ( cutoffDistance > 0.0 ) { + + distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDist / cutoffDistance ) ) ); + + } + + LightRecord rec; + rec.direction = normalize( lightRay ); + rec.dist = length( lightRay ); + rec.pdf = 1.0; + rec.emission = light.color * light.intensity * distanceFalloff; + rec.type = light.type; + result = rec; + + } else if ( light.type == DIR_LIGHT_TYPE ) { + + LightRecord rec; + rec.dist = 1e10; + rec.direction = light.u; + rec.pdf = 1.0; + rec.emission = light.color * light.intensity; + rec.type = light.type; + + result = rec; + + } else { + + // sample the light + result = randomAreaLightSample( light, rayOrigin, ruv.yz ); + + } + + return result; + + } + +`;var gv=` + + vec3 sampleHemisphere( vec3 n, vec2 uv ) { + + // https://www.rorydriscoll.com/2009/01/07/better-sampling/ + // https://graphics.pixar.com/library/OrthonormalB/paper.pdf + float sign = n.z == 0.0 ? 1.0 : sign( n.z ); + float a = - 1.0 / ( sign + n.z ); + float b = n.x * n.y * a; + vec3 b1 = vec3( 1.0 + sign * n.x * n.x * a, sign * b, - sign * n.x ); + vec3 b2 = vec3( b, sign + n.y * n.y * a, - n.y ); + + float r = sqrt( uv.x ); + float theta = 2.0 * PI * uv.y; + float x = r * cos( theta ); + float y = r * sin( theta ); + return x * b1 + y * b2 + sqrt( 1.0 - uv.x ) * n; + + } + + vec2 sampleTriangle( vec2 a, vec2 b, vec2 c, vec2 r ) { + + // get the edges of the triangle and the diagonal across the + // center of the parallelogram + vec2 e1 = a - b; + vec2 e2 = c - b; + vec2 diag = normalize( e1 + e2 ); + + // pick the point in the parallelogram + if ( r.x + r.y > 1.0 ) { + + r = vec2( 1.0 ) - r; + + } + + return e1 * r.x + e2 * r.y; + + } + + vec2 sampleCircle( vec2 uv ) { + + float angle = 2.0 * PI * uv.x; + float radius = sqrt( uv.y ); + return vec2( cos( angle ), sin( angle ) ) * radius; + + } + + vec3 sampleSphere( vec2 uv ) { + + float u = ( uv.x - 0.5 ) * 2.0; + float t = uv.y * PI * 2.0; + float f = sqrt( 1.0 - u * u ); + + return vec3( f * cos( t ), f * sin( t ), u ); + + } + + vec2 sampleRegularPolygon( int sides, vec3 uvw ) { + + sides = max( sides, 3 ); + + vec3 r = uvw; + float anglePerSegment = 2.0 * PI / float( sides ); + float segment = floor( float( sides ) * r.x ); + + float angle1 = anglePerSegment * segment; + float angle2 = angle1 + anglePerSegment; + vec2 a = vec2( sin( angle1 ), cos( angle1 ) ); + vec2 b = vec2( 0.0, 0.0 ); + vec2 c = vec2( sin( angle2 ), cos( angle2 ) ); + + return sampleTriangle( a, b, c, r.yz ); + + } + + // samples an aperture shape with the given number of sides. 0 means circle + vec2 sampleAperture( int blades, vec3 uvw ) { + + return blades == 0 ? + sampleCircle( uvw.xy ) : + sampleRegularPolygon( blades, uvw ); + + } + + +`;var xv=` + + bool totalInternalReflection( float cosTheta, float eta ) { + + float sinTheta = sqrt( 1.0 - cosTheta * cosTheta ); + return eta * sinTheta > 1.0; + + } + + // https://google.github.io/filament/Filament.md.html#materialsystem/diffusebrdf + float schlickFresnel( float cosine, float f0 ) { + + return f0 + ( 1.0 - f0 ) * pow( 1.0 - cosine, 5.0 ); + + } + + vec3 schlickFresnel( float cosine, vec3 f0 ) { + + return f0 + ( 1.0 - f0 ) * pow( 1.0 - cosine, 5.0 ); + + } + + vec3 schlickFresnel( float cosine, vec3 f0, vec3 f90 ) { + + return f0 + ( f90 - f0 ) * pow( 1.0 - cosine, 5.0 ); + + } + + float dielectricFresnel( float cosThetaI, float eta ) { + + // https://schuttejoe.github.io/post/disneybsdf/ + float ni = eta; + float nt = 1.0; + + // Check for total internal reflection + float sinThetaISq = 1.0f - cosThetaI * cosThetaI; + float sinThetaTSq = eta * eta * sinThetaISq; + if( sinThetaTSq >= 1.0 ) { + + return 1.0; + + } + + float sinThetaT = sqrt( sinThetaTSq ); + + float cosThetaT = sqrt( max( 0.0, 1.0f - sinThetaT * sinThetaT ) ); + float rParallel = ( ( nt * cosThetaI ) - ( ni * cosThetaT ) ) / ( ( nt * cosThetaI ) + ( ni * cosThetaT ) ); + float rPerpendicular = ( ( ni * cosThetaI ) - ( nt * cosThetaT ) ) / ( ( ni * cosThetaI ) + ( nt * cosThetaT ) ); + return ( rParallel * rParallel + rPerpendicular * rPerpendicular ) / 2.0; + + } + + // https://raytracing.github.io/books/RayTracingInOneWeekend.html#dielectrics/schlickapproximation + float iorRatioToF0( float eta ) { + + return pow( ( 1.0 - eta ) / ( 1.0 + eta ), 2.0 ); + + } + + vec3 evaluateFresnel( float cosTheta, float eta, vec3 f0, vec3 f90 ) { + + if ( totalInternalReflection( cosTheta, eta ) ) { + + return f90; + + } + + return schlickFresnel( cosTheta, f0, f90 ); + + } + + // TODO: disney fresnel was removed and replaced with this fresnel function to better align with + // the glTF but is causing blown out pixels. Should be revisited + // float evaluateFresnelWeight( float cosTheta, float eta, float f0 ) { + + // if ( totalInternalReflection( cosTheta, eta ) ) { + + // return 1.0; + + // } + + // return schlickFresnel( cosTheta, f0 ); + + // } + + // https://schuttejoe.github.io/post/disneybsdf/ + float disneyFresnel( vec3 wo, vec3 wi, vec3 wh, float f0, float eta, float metalness ) { + + float dotHV = dot( wo, wh ); + if ( totalInternalReflection( dotHV, eta ) ) { + + return 1.0; + + } + + float dotHL = dot( wi, wh ); + float dielectricFresnel = dielectricFresnel( abs( dotHV ), eta ); + float metallicFresnel = schlickFresnel( dotHL, f0 ); + + return mix( dielectricFresnel, metallicFresnel, metalness ); + + } + +`;var vv=` + + // Fast arccos approximation used to remove banding artifacts caused by numerical errors in acos. + // This is a cubic Lagrange interpolating polynomial for x = [-1, -1/2, 0, 1/2, 1]. + // For more information see: https://github.com/gkjohnson/three-gpu-pathtracer/pull/171#issuecomment-1152275248 + float acosApprox( float x ) { + + x = clamp( x, -1.0, 1.0 ); + return ( - 0.69813170079773212 * x * x - 0.87266462599716477 ) * x + 1.5707963267948966; + + } + + // An acos with input values bound to the range [-1, 1]. + float acosSafe( float x ) { + + return acos( clamp( x, -1.0, 1.0 ) ); + + } + + float saturateCos( float val ) { + + return clamp( val, 0.001, 1.0 ); + + } + + float square( float t ) { + + return t * t; + + } + + vec2 square( vec2 t ) { + + return t * t; + + } + + vec3 square( vec3 t ) { + + return t * t; + + } + + vec4 square( vec4 t ) { + + return t * t; + + } + + vec2 rotateVector( vec2 v, float t ) { + + float ac = cos( t ); + float as = sin( t ); + return vec2( + v.x * ac - v.y * as, + v.x * as + v.y * ac + ); + + } + + // forms a basis with the normal vector as Z + mat3 getBasisFromNormal( vec3 normal ) { + + vec3 other; + if ( abs( normal.x ) > 0.5 ) { + + other = vec3( 0.0, 1.0, 0.0 ); + + } else { + + other = vec3( 1.0, 0.0, 0.0 ); + + } + + vec3 ortho = normalize( cross( normal, other ) ); + vec3 ortho2 = normalize( cross( normal, ortho ) ); + return mat3( ortho2, ortho, normal ); + + } + +`;var _v=` + + // Finds the point where the ray intersects the plane defined by u and v and checks if this point + // falls in the bounds of the rectangle on that same plane. + // Plane intersection: https://lousodrome.net/blog/light/2020/07/03/intersection-of-a-ray-and-a-plane/ + bool intersectsRectangle( vec3 center, vec3 normal, vec3 u, vec3 v, vec3 rayOrigin, vec3 rayDirection, inout float dist ) { + + float t = dot( center - rayOrigin, normal ) / dot( rayDirection, normal ); + + if ( t > EPSILON ) { + + vec3 p = rayOrigin + rayDirection * t; + vec3 vi = p - center; + + // check if p falls inside the rectangle + float a1 = dot( u, vi ); + if ( abs( a1 ) <= 0.5 ) { + + float a2 = dot( v, vi ); + if ( abs( a2 ) <= 0.5 ) { + + dist = t; + return true; + + } + + } + + } + + return false; + + } + + // Finds the point where the ray intersects the plane defined by u and v and checks if this point + // falls in the bounds of the circle on that same plane. See above URL for a description of the plane intersection algorithm. + bool intersectsCircle( vec3 position, vec3 normal, vec3 u, vec3 v, vec3 rayOrigin, vec3 rayDirection, inout float dist ) { + + float t = dot( position - rayOrigin, normal ) / dot( rayDirection, normal ); + + if ( t > EPSILON ) { + + vec3 hit = rayOrigin + rayDirection * t; + vec3 vi = hit - position; + + float a1 = dot( u, vi ); + float a2 = dot( v, vi ); + + if( length( vec2( a1, a2 ) ) <= 0.5 ) { + + dist = t; + return true; + + } + + } + + return false; + + } + +`;var yv=` + + // add texel fetch functions for texture arrays + vec4 texelFetch1D( sampler2DArray tex, int layer, uint index ) { + + uint width = uint( textureSize( tex, 0 ).x ); + uvec2 uv; + uv.x = index % width; + uv.y = index / width; + + return texelFetch( tex, ivec3( uv, layer ), 0 ); + + } + + vec4 textureSampleBarycoord( sampler2DArray tex, int layer, vec3 barycoord, uvec3 faceIndices ) { + + return + barycoord.x * texelFetch1D( tex, layer, faceIndices.x ) + + barycoord.y * texelFetch1D( tex, layer, faceIndices.y ) + + barycoord.z * texelFetch1D( tex, layer, faceIndices.z ); + + } + +`;var Rh=` + + // TODO: possibly this should be renamed something related to material or path tracing logic + + #ifndef RAY_OFFSET + #define RAY_OFFSET 1e-4 + #endif + + // adjust the hit point by the surface normal by a factor of some offset and the + // maximum component-wise value of the current point to accommodate floating point + // error as values increase. + vec3 stepRayOrigin( vec3 rayOrigin, vec3 rayDirection, vec3 offset, float dist ) { + + vec3 point = rayOrigin + rayDirection * dist; + vec3 absPoint = abs( point ); + float maxPoint = max( absPoint.x, max( absPoint.y, absPoint.z ) ); + return point + offset * ( maxPoint + 1.0 ) * RAY_OFFSET; + + } + + // https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_volume/README.md#attenuation + vec3 transmissionAttenuation( float dist, vec3 attColor, float attDist ) { + + vec3 ot = - log( attColor ) / attDist; + return exp( - ot * dist ); + + } + + vec3 getHalfVector( vec3 wi, vec3 wo, float eta ) { + + // get the half vector - assuming if the light incident vector is on the other side + // of the that it's transmissive. + vec3 h; + if ( wi.z > 0.0 ) { + + h = normalize( wi + wo ); + + } else { + + // Scale by the ior ratio to retrieve the appropriate half vector + // From Section 2.2 on computing the transmission half vector: + // https://blog.selfshadow.com/publications/s2015-shading-course/burley/s2015_pbs_disney_bsdf_notes.pdf + h = normalize( wi + wo * eta ); + + } + + h *= sign( h.z ); + return h; + + } + + vec3 getHalfVector( vec3 a, vec3 b ) { + + return normalize( a + b ); + + } + + // The discrepancy between interpolated surface normal and geometry normal can cause issues when a ray + // is cast that is on the top side of the geometry normal plane but below the surface normal plane. If + // we find a ray like that we ignore it to avoid artifacts. + // This function returns if the direction is on the same side of both planes. + bool isDirectionValid( vec3 direction, vec3 surfaceNormal, vec3 geometryNormal ) { + + bool aboveSurfaceNormal = dot( direction, surfaceNormal ) > 0.0; + bool aboveGeometryNormal = dot( direction, geometryNormal ) > 0.0; + return aboveSurfaceNormal == aboveGeometryNormal; + + } + + // ray sampling x and z are swapped to align with expected background view + vec2 equirectDirectionToUv( vec3 direction ) { + + // from Spherical.setFromCartesianCoords + vec2 uv = vec2( atan( direction.z, direction.x ), acos( direction.y ) ); + uv /= vec2( 2.0 * PI, PI ); + + // apply adjustments to get values in range [0, 1] and y right side up + uv.x += 0.5; + uv.y = 1.0 - uv.y; + return uv; + + } + + vec3 equirectUvToDirection( vec2 uv ) { + + // undo above adjustments + uv.x -= 0.5; + uv.y = 1.0 - uv.y; + + // from Vector3.setFromSphericalCoords + float theta = uv.x * 2.0 * PI; + float phi = uv.y * PI; + + float sinPhi = sin( phi ); + + return vec3( sinPhi * cos( theta ), cos( phi ), sinPhi * sin( theta ) ); + + } + + // power heuristic for multiple importance sampling + float misHeuristic( float a, float b ) { + + float aa = a * a; + float bb = b * b; + return aa / ( aa + bb ); + + } + + // tentFilter from Peter Shirley's 'Realistic Ray Tracing (2nd Edition)' book, pg. 60 + // erichlof/THREE.js-PathTracing-Renderer/ + float tentFilter( float x ) { + + return x < 0.5 ? sqrt( 2.0 * x ) - 1.0 : 1.0 - sqrt( 2.0 - ( 2.0 * x ) ); + + } +`;var Jp=` + + // https://www.shadertoy.com/view/wltcRS + uvec4 WHITE_NOISE_SEED; + + void rng_initialize( vec2 p, int frame ) { + + // white noise seed + WHITE_NOISE_SEED = uvec4( p, uint( frame ), uint( p.x ) + uint( p.y ) ); + + } + + // https://www.pcg-random.org/ + void pcg4d( inout uvec4 v ) { + + v = v * 1664525u + 1013904223u; + v.x += v.y * v.w; + v.y += v.z * v.x; + v.z += v.x * v.y; + v.w += v.y * v.z; + v = v ^ ( v >> 16u ); + v.x += v.y*v.w; + v.y += v.z*v.x; + v.z += v.x*v.y; + v.w += v.y*v.z; + + } + + // returns [ 0, 1 ] + float pcgRand() { + + pcg4d( WHITE_NOISE_SEED ); + return float( WHITE_NOISE_SEED.x ) / float( 0xffffffffu ); + + } + + vec2 pcgRand2() { + + pcg4d( WHITE_NOISE_SEED ); + return vec2( WHITE_NOISE_SEED.xy ) / float(0xffffffffu); + + } + + vec3 pcgRand3() { + + pcg4d( WHITE_NOISE_SEED ); + return vec3( WHITE_NOISE_SEED.xyz ) / float( 0xffffffffu ); + + } + + vec4 pcgRand4() { + + pcg4d( WHITE_NOISE_SEED ); + return vec4( WHITE_NOISE_SEED ) / float( 0xffffffffu ); + + } +`;var bv=` + + uniform sampler2D stratifiedTexture; + uniform sampler2D stratifiedOffsetTexture; + + uint sobolPixelIndex = 0u; + uint sobolPathIndex = 0u; + uint sobolBounceIndex = 0u; + vec4 pixelSeed = vec4( 0 ); + + vec4 rand4( int v ) { + + ivec2 uv = ivec2( v, sobolBounceIndex ); + vec4 stratifiedSample = texelFetch( stratifiedTexture, uv, 0 ); + return fract( stratifiedSample + pixelSeed.r ); // blue noise + stratified samples + + } + + vec3 rand3( int v ) { + + return rand4( v ).xyz; + + } + + vec2 rand2( int v ) { + + return rand4( v ).xy; + + } + + float rand( int v ) { + + return rand4( v ).x; + + } + + void rng_initialize( vec2 screenCoord, int frame ) { + + // tile the small noise texture across the entire screen + ivec2 noiseSize = ivec2( textureSize( stratifiedOffsetTexture, 0 ) ); + ivec2 pixel = ivec2( screenCoord.xy ) % noiseSize; + vec2 pixelWidth = 1.0 / vec2( noiseSize ); + vec2 uv = vec2( pixel ) * pixelWidth + pixelWidth * 0.5; + + // note that using "texelFetch" here seems to break Android for some reason + pixelSeed = texture( stratifiedOffsetTexture, uv ); + + } + +`;var Sv=` + + // diffuse + float diffuseEval( vec3 wo, vec3 wi, vec3 wh, SurfaceRecord surf, inout vec3 color ) { + + // https://schuttejoe.github.io/post/disneybsdf/ + float fl = schlickFresnel( wi.z, 0.0 ); + float fv = schlickFresnel( wo.z, 0.0 ); + + float metalFactor = ( 1.0 - surf.metalness ); + float transFactor = ( 1.0 - surf.transmission ); + float rr = 0.5 + 2.0 * surf.roughness * fl * fl; + float retro = rr * ( fl + fv + fl * fv * ( rr - 1.0f ) ); + float lambert = ( 1.0f - 0.5f * fl ) * ( 1.0f - 0.5f * fv ); + + // TODO: subsurface approx? + + // float F = evaluateFresnelWeight( dot( wo, wh ), surf.eta, surf.f0 ); + float F = disneyFresnel( wo, wi, wh, surf.f0, surf.eta, surf.metalness ); + color = ( 1.0 - F ) * transFactor * metalFactor * wi.z * surf.color * ( retro + lambert ) / PI; + + return wi.z / PI; + + } + + vec3 diffuseDirection( vec3 wo, SurfaceRecord surf ) { + + vec3 lightDirection = sampleSphere( rand2( 11 ) ); + lightDirection.z += 1.0; + lightDirection = normalize( lightDirection ); + + return lightDirection; + + } + + // specular + float specularEval( vec3 wo, vec3 wi, vec3 wh, SurfaceRecord surf, inout vec3 color ) { + + // if roughness is set to 0 then D === NaN which results in black pixels + float metalness = surf.metalness; + float roughness = surf.filteredRoughness; + + float eta = surf.eta; + float f0 = surf.f0; + + vec3 f0Color = mix( f0 * surf.specularColor * surf.specularIntensity, surf.color, surf.metalness ); + vec3 f90Color = vec3( mix( surf.specularIntensity, 1.0, surf.metalness ) ); + vec3 F = evaluateFresnel( dot( wo, wh ), eta, f0Color, f90Color ); + + vec3 iridescenceF = evalIridescence( 1.0, surf.iridescenceIor, dot( wi, wh ), surf.iridescenceThickness, f0Color ); + F = mix( F, iridescenceF, surf.iridescence ); + + // PDF + // See 14.1.1 Microfacet BxDFs in https://www.pbr-book.org/ + float incidentTheta = acos( wo.z ); + float G = ggxShadowMaskG2( wi, wo, roughness ); + float D = ggxDistribution( wh, roughness ); + float G1 = ggxShadowMaskG1( incidentTheta, roughness ); + float ggxPdf = D * G1 * max( 0.0, abs( dot( wo, wh ) ) ) / abs ( wo.z ); + + color = wi.z * F * G * D / ( 4.0 * abs( wi.z * wo.z ) ); + return ggxPdf / ( 4.0 * dot( wo, wh ) ); + + } + + vec3 specularDirection( vec3 wo, SurfaceRecord surf ) { + + // sample ggx vndf distribution which gives a new normal + float roughness = surf.filteredRoughness; + vec3 halfVector = ggxDirection( + wo, + vec2( roughness ), + rand2( 12 ) + ); + + // apply to new ray by reflecting off the new normal + return - reflect( wo, halfVector ); + + } + + + // transmission + /* + float transmissionEval( vec3 wo, vec3 wi, vec3 wh, SurfaceRecord surf, inout vec3 color ) { + + // See section 4.2 in https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.pdf + + float filteredRoughness = surf.filteredRoughness; + float eta = surf.eta; + bool frontFace = surf.frontFace; + bool thinFilm = surf.thinFilm; + + color = surf.transmission * surf.color; + + float denom = pow( eta * dot( wi, wh ) + dot( wo, wh ), 2.0 ); + return ggxPDF( wo, wh, filteredRoughness ) / denom; + + } + + vec3 transmissionDirection( vec3 wo, SurfaceRecord surf ) { + + float filteredRoughness = surf.filteredRoughness; + float eta = surf.eta; + bool frontFace = surf.frontFace; + + // sample ggx vndf distribution which gives a new normal + vec3 halfVector = ggxDirection( + wo, + vec2( filteredRoughness ), + rand2( 13 ) + ); + + vec3 lightDirection = refract( normalize( - wo ), halfVector, eta ); + if ( surf.thinFilm ) { + + lightDirection = - refract( normalize( - lightDirection ), - vec3( 0.0, 0.0, 1.0 ), 1.0 / eta ); + + } + + return normalize( lightDirection ); + + } + */ + + // TODO: This is just using a basic cosine-weighted specular distribution with an + // incorrect PDF value at the moment. Update it to correctly use a GGX distribution + float transmissionEval( vec3 wo, vec3 wi, vec3 wh, SurfaceRecord surf, inout vec3 color ) { + + color = surf.transmission * surf.color; + + // PDF + // float F = evaluateFresnelWeight( dot( wo, wh ), surf.eta, surf.f0 ); + // float F = disneyFresnel( wo, wi, wh, surf.f0, surf.eta, surf.metalness ); + // if ( F >= 1.0 ) { + + // return 0.0; + + // } + + // return 1.0 / ( 1.0 - F ); + + // reverted to previous to transmission. The above was causing black pixels + float eta = surf.eta; + float f0 = surf.f0; + float cosTheta = min( wo.z, 1.0 ); + float sinTheta = sqrt( 1.0 - cosTheta * cosTheta ); + float reflectance = schlickFresnel( cosTheta, f0 ); + bool cannotRefract = eta * sinTheta > 1.0; + if ( cannotRefract ) { + + return 0.0; + + } + + return 1.0 / ( 1.0 - reflectance ); + + } + + vec3 transmissionDirection( vec3 wo, SurfaceRecord surf ) { + + float roughness = surf.filteredRoughness; + float eta = surf.eta; + vec3 halfVector = normalize( vec3( 0.0, 0.0, 1.0 ) + sampleSphere( rand2( 13 ) ) * roughness ); + vec3 lightDirection = refract( normalize( - wo ), halfVector, eta ); + + if ( surf.thinFilm ) { + + lightDirection = - refract( normalize( - lightDirection ), - vec3( 0.0, 0.0, 1.0 ), 1.0 / eta ); + + } + return normalize( lightDirection ); + + } + + // clearcoat + float clearcoatEval( vec3 wo, vec3 wi, vec3 wh, SurfaceRecord surf, inout vec3 color ) { + + float ior = 1.5; + float f0 = iorRatioToF0( ior ); + bool frontFace = surf.frontFace; + float roughness = surf.filteredClearcoatRoughness; + + float eta = frontFace ? 1.0 / ior : ior; + float G = ggxShadowMaskG2( wi, wo, roughness ); + float D = ggxDistribution( wh, roughness ); + float F = schlickFresnel( dot( wi, wh ), f0 ); + + float fClearcoat = F * D * G / ( 4.0 * abs( wi.z * wo.z ) ); + color = color * ( 1.0 - surf.clearcoat * F ) + fClearcoat * surf.clearcoat * wi.z; + + // PDF + // See equation (27) in http://jcgt.org/published/0003/02/03/ + return ggxPDF( wo, wh, roughness ) / ( 4.0 * dot( wi, wh ) ); + + } + + vec3 clearcoatDirection( vec3 wo, SurfaceRecord surf ) { + + // sample ggx vndf distribution which gives a new normal + float roughness = surf.filteredClearcoatRoughness; + vec3 halfVector = ggxDirection( + wo, + vec2( roughness ), + rand2( 14 ) + ); + + // apply to new ray by reflecting off the new normal + return - reflect( wo, halfVector ); + + } + + // sheen + vec3 sheenColor( vec3 wo, vec3 wi, vec3 wh, SurfaceRecord surf ) { + + float cosThetaO = saturateCos( wo.z ); + float cosThetaI = saturateCos( wi.z ); + float cosThetaH = wh.z; + + float D = velvetD( cosThetaH, surf.sheenRoughness ); + float G = velvetG( cosThetaO, cosThetaI, surf.sheenRoughness ); + + // See equation (1) in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf + vec3 color = surf.sheenColor; + color *= D * G / ( 4.0 * abs( cosThetaO * cosThetaI ) ); + color *= wi.z; + + return color; + + } + + // bsdf + void getLobeWeights( + vec3 wo, vec3 wi, vec3 wh, vec3 clearcoatWo, SurfaceRecord surf, + inout float diffuseWeight, inout float specularWeight, inout float transmissionWeight, inout float clearcoatWeight + ) { + + float metalness = surf.metalness; + float transmission = surf.transmission; + // float fEstimate = evaluateFresnelWeight( dot( wo, wh ), surf.eta, surf.f0 ); + float fEstimate = disneyFresnel( wo, wi, wh, surf.f0, surf.eta, surf.metalness ); + + float transSpecularProb = mix( max( 0.25, fEstimate ), 1.0, metalness ); + float diffSpecularProb = 0.5 + 0.5 * metalness; + + diffuseWeight = ( 1.0 - transmission ) * ( 1.0 - diffSpecularProb ); + specularWeight = transmission * transSpecularProb + ( 1.0 - transmission ) * diffSpecularProb; + transmissionWeight = transmission * ( 1.0 - transSpecularProb ); + clearcoatWeight = surf.clearcoat * schlickFresnel( clearcoatWo.z, 0.04 ); + + float totalWeight = diffuseWeight + specularWeight + transmissionWeight + clearcoatWeight; + diffuseWeight /= totalWeight; + specularWeight /= totalWeight; + transmissionWeight /= totalWeight; + clearcoatWeight /= totalWeight; + } + + float bsdfEval( + vec3 wo, vec3 clearcoatWo, vec3 wi, vec3 clearcoatWi, SurfaceRecord surf, + float diffuseWeight, float specularWeight, float transmissionWeight, float clearcoatWeight, inout float specularPdf, inout vec3 color + ) { + + float metalness = surf.metalness; + float transmission = surf.transmission; + + float spdf = 0.0; + float dpdf = 0.0; + float tpdf = 0.0; + float cpdf = 0.0; + color = vec3( 0.0 ); + + vec3 halfVector = getHalfVector( wi, wo, surf.eta ); + + // diffuse + if ( diffuseWeight > 0.0 && wi.z > 0.0 ) { + + dpdf = diffuseEval( wo, wi, halfVector, surf, color ); + color *= 1.0 - surf.transmission; + + } + + // ggx specular + if ( specularWeight > 0.0 && wi.z > 0.0 ) { + + vec3 outColor; + spdf = specularEval( wo, wi, getHalfVector( wi, wo ), surf, outColor ); + color += outColor; + + } + + // transmission + if ( transmissionWeight > 0.0 && wi.z < 0.0 ) { + + tpdf = transmissionEval( wo, wi, halfVector, surf, color ); + + } + + // sheen + color *= mix( 1.0, sheenAlbedoScaling( wo, wi, surf ), surf.sheen ); + color += sheenColor( wo, wi, halfVector, surf ) * surf.sheen; + + // clearcoat + if ( clearcoatWi.z >= 0.0 && clearcoatWeight > 0.0 ) { + + vec3 clearcoatHalfVector = getHalfVector( clearcoatWo, clearcoatWi ); + cpdf = clearcoatEval( clearcoatWo, clearcoatWi, clearcoatHalfVector, surf, color ); + + } + + float pdf = + dpdf * diffuseWeight + + spdf * specularWeight + + tpdf * transmissionWeight + + cpdf * clearcoatWeight; + + // retrieve specular rays for the shadows flag + specularPdf = spdf * specularWeight + cpdf * clearcoatWeight; + + return pdf; + + } + + float bsdfResult( vec3 worldWo, vec3 worldWi, SurfaceRecord surf, inout vec3 color ) { + + if ( surf.volumeParticle ) { + + color = surf.color / ( 4.0 * PI ); + return 1.0 / ( 4.0 * PI ); + + } + + vec3 wo = normalize( surf.normalInvBasis * worldWo ); + vec3 wi = normalize( surf.normalInvBasis * worldWi ); + + vec3 clearcoatWo = normalize( surf.clearcoatInvBasis * worldWo ); + vec3 clearcoatWi = normalize( surf.clearcoatInvBasis * worldWi ); + + vec3 wh = getHalfVector( wo, wi, surf.eta ); + float diffuseWeight; + float specularWeight; + float transmissionWeight; + float clearcoatWeight; + getLobeWeights( wo, wi, wh, clearcoatWo, surf, diffuseWeight, specularWeight, transmissionWeight, clearcoatWeight ); + + float specularPdf; + return bsdfEval( wo, clearcoatWo, wi, clearcoatWi, surf, diffuseWeight, specularWeight, transmissionWeight, clearcoatWeight, specularPdf, color ); + + } + + ScatterRecord bsdfSample( vec3 worldWo, SurfaceRecord surf ) { + + if ( surf.volumeParticle ) { + + ScatterRecord sampleRec; + sampleRec.specularPdf = 0.0; + sampleRec.pdf = 1.0 / ( 4.0 * PI ); + sampleRec.direction = sampleSphere( rand2( 16 ) ); + sampleRec.color = surf.color / ( 4.0 * PI ); + return sampleRec; + + } + + vec3 wo = normalize( surf.normalInvBasis * worldWo ); + vec3 clearcoatWo = normalize( surf.clearcoatInvBasis * worldWo ); + mat3 normalBasis = surf.normalBasis; + mat3 invBasis = surf.normalInvBasis; + mat3 clearcoatNormalBasis = surf.clearcoatBasis; + mat3 clearcoatInvBasis = surf.clearcoatInvBasis; + + float diffuseWeight; + float specularWeight; + float transmissionWeight; + float clearcoatWeight; + // using normal and basically-reflected ray since we don't have proper half vector here + getLobeWeights( wo, wo, vec3( 0, 0, 1 ), clearcoatWo, surf, diffuseWeight, specularWeight, transmissionWeight, clearcoatWeight ); + + float pdf[4]; + pdf[0] = diffuseWeight; + pdf[1] = specularWeight; + pdf[2] = transmissionWeight; + pdf[3] = clearcoatWeight; + + float cdf[4]; + cdf[0] = pdf[0]; + cdf[1] = pdf[1] + cdf[0]; + cdf[2] = pdf[2] + cdf[1]; + cdf[3] = pdf[3] + cdf[2]; + + if( cdf[3] != 0.0 ) { + + float invMaxCdf = 1.0 / cdf[3]; + cdf[0] *= invMaxCdf; + cdf[1] *= invMaxCdf; + cdf[2] *= invMaxCdf; + cdf[3] *= invMaxCdf; + + } else { + + cdf[0] = 1.0; + cdf[1] = 0.0; + cdf[2] = 0.0; + cdf[3] = 0.0; + + } + + vec3 wi; + vec3 clearcoatWi; + + float r = rand( 15 ); + if ( r <= cdf[0] ) { // diffuse + + wi = diffuseDirection( wo, surf ); + clearcoatWi = normalize( clearcoatInvBasis * normalize( normalBasis * wi ) ); + + } else if ( r <= cdf[1] ) { // specular + + wi = specularDirection( wo, surf ); + clearcoatWi = normalize( clearcoatInvBasis * normalize( normalBasis * wi ) ); + + } else if ( r <= cdf[2] ) { // transmission / refraction + + wi = transmissionDirection( wo, surf ); + clearcoatWi = normalize( clearcoatInvBasis * normalize( normalBasis * wi ) ); + + } else if ( r <= cdf[3] ) { // clearcoat + + clearcoatWi = clearcoatDirection( clearcoatWo, surf ); + wi = normalize( invBasis * normalize( clearcoatNormalBasis * clearcoatWi ) ); + + } + + ScatterRecord result; + result.pdf = bsdfEval( wo, clearcoatWo, wi, clearcoatWi, surf, diffuseWeight, specularWeight, transmissionWeight, clearcoatWeight, result.specularPdf, result.color ); + result.direction = normalize( surf.normalBasis * wi ); + + return result; + + } + +`;var Mv=` + + // returns the hit distance given the material density + float intersectFogVolume( Material material, float u ) { + + // https://raytracing.github.io/books/RayTracingTheNextWeek.html#volumes/constantdensitymediums + return material.opacity == 0.0 ? INFINITY : ( - 1.0 / material.opacity ) * log( u ); + + } + + ScatterRecord sampleFogVolume( SurfaceRecord surf, vec2 uv ) { + + ScatterRecord sampleRec; + sampleRec.specularPdf = 0.0; + sampleRec.pdf = 1.0 / ( 2.0 * PI ); + sampleRec.direction = sampleSphere( uv ); + sampleRec.color = surf.color; + return sampleRec; + + } + +`;var Tv=` + + // The GGX functions provide sampling and distribution information for normals as output so + // in order to get probability of scatter direction the half vector must be computed and provided. + // [0] https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.pdf + // [1] https://hal.archives-ouvertes.fr/hal-01509746/document + // [2] http://jcgt.org/published/0007/04/01/ + // [4] http://jcgt.org/published/0003/02/03/ + + // trowbridge-reitz === GGX === GTR + + vec3 ggxDirection( vec3 incidentDir, vec2 roughness, vec2 uv ) { + + // TODO: try GGXVNDF implementation from reference [2], here. Needs to update ggxDistribution + // function below, as well + + // Implementation from reference [1] + // stretch view + vec3 V = normalize( vec3( roughness * incidentDir.xy, incidentDir.z ) ); + + // orthonormal basis + vec3 T1 = ( V.z < 0.9999 ) ? normalize( cross( V, vec3( 0.0, 0.0, 1.0 ) ) ) : vec3( 1.0, 0.0, 0.0 ); + vec3 T2 = cross( T1, V ); + + // sample point with polar coordinates (r, phi) + float a = 1.0 / ( 1.0 + V.z ); + float r = sqrt( uv.x ); + float phi = ( uv.y < a ) ? uv.y / a * PI : PI + ( uv.y - a ) / ( 1.0 - a ) * PI; + float P1 = r * cos( phi ); + float P2 = r * sin( phi ) * ( ( uv.y < a ) ? 1.0 : V.z ); + + // compute normal + vec3 N = P1 * T1 + P2 * T2 + V * sqrt( max( 0.0, 1.0 - P1 * P1 - P2 * P2 ) ); + + // unstretch + N = normalize( vec3( roughness * N.xy, max( 0.0, N.z ) ) ); + + return N; + + } + + // Below are PDF and related functions for use in a Monte Carlo path tracer + // as specified in Appendix B of the following paper + // See equation (34) from reference [0] + float ggxLamda( float theta, float roughness ) { + + float tanTheta = tan( theta ); + float tanTheta2 = tanTheta * tanTheta; + float alpha2 = roughness * roughness; + + float numerator = - 1.0 + sqrt( 1.0 + alpha2 * tanTheta2 ); + return numerator / 2.0; + + } + + // See equation (34) from reference [0] + float ggxShadowMaskG1( float theta, float roughness ) { + + return 1.0 / ( 1.0 + ggxLamda( theta, roughness ) ); + + } + + // See equation (125) from reference [4] + float ggxShadowMaskG2( vec3 wi, vec3 wo, float roughness ) { + + float incidentTheta = acos( wi.z ); + float scatterTheta = acos( wo.z ); + return 1.0 / ( 1.0 + ggxLamda( incidentTheta, roughness ) + ggxLamda( scatterTheta, roughness ) ); + + } + + // See equation (33) from reference [0] + float ggxDistribution( vec3 halfVector, float roughness ) { + + float a2 = roughness * roughness; + a2 = max( EPSILON, a2 ); + float cosTheta = halfVector.z; + float cosTheta4 = pow( cosTheta, 4.0 ); + + if ( cosTheta == 0.0 ) return 0.0; + + float theta = acosSafe( halfVector.z ); + float tanTheta = tan( theta ); + float tanTheta2 = pow( tanTheta, 2.0 ); + + float denom = PI * cosTheta4 * pow( a2 + tanTheta2, 2.0 ); + return ( a2 / denom ); + + } + + // See equation (3) from reference [2] + float ggxPDF( vec3 wi, vec3 halfVector, float roughness ) { + + float incidentTheta = acos( wi.z ); + float D = ggxDistribution( halfVector, roughness ); + float G1 = ggxShadowMaskG1( incidentTheta, roughness ); + + return D * G1 * max( 0.0, dot( wi, halfVector ) ) / wi.z; + + } + +`;var wv=` + + // XYZ to sRGB color space + const mat3 XYZ_TO_REC709 = mat3( + 3.2404542, -0.9692660, 0.0556434, + -1.5371385, 1.8760108, -0.2040259, + -0.4985314, 0.0415560, 1.0572252 + ); + + vec3 fresnel0ToIor( vec3 fresnel0 ) { + + vec3 sqrtF0 = sqrt( fresnel0 ); + return ( vec3( 1.0 ) + sqrtF0 ) / ( vec3( 1.0 ) - sqrtF0 ); + + } + + // Conversion FO/IOR + vec3 iorToFresnel0( vec3 transmittedIor, float incidentIor ) { + + return square( ( transmittedIor - vec3( incidentIor ) ) / ( transmittedIor + vec3( incidentIor ) ) ); + + } + + // ior is a value between 1.0 and 3.0. 1.0 is air interface + float iorToFresnel0( float transmittedIor, float incidentIor ) { + + return square( ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor ) ); + + } + + // Fresnel equations for dielectric/dielectric interfaces. See https://belcour.github.io/blog/research/2017/05/01/brdf-thin-film.html + vec3 evalSensitivity( float OPD, vec3 shift ) { + + float phase = 2.0 * PI * OPD * 1.0e-9; + + vec3 val = vec3( 5.4856e-13, 4.4201e-13, 5.2481e-13 ); + vec3 pos = vec3( 1.6810e+06, 1.7953e+06, 2.2084e+06 ); + vec3 var = vec3( 4.3278e+09, 9.3046e+09, 6.6121e+09 ); + + vec3 xyz = val * sqrt( 2.0 * PI * var ) * cos( pos * phase + shift ) * exp( - square( phase ) * var ); + xyz.x += 9.7470e-14 * sqrt( 2.0 * PI * 4.5282e+09 ) * cos( 2.2399e+06 * phase + shift[ 0 ] ) * exp( - 4.5282e+09 * square( phase ) ); + xyz /= 1.0685e-7; + + vec3 srgb = XYZ_TO_REC709 * xyz; + return srgb; + + } + + // See Section 4. Analytic Spectral Integration, A Practical Extension to Microfacet Theory for the Modeling of Varying Iridescence, https://hal.archives-ouvertes.fr/hal-01518344/document + vec3 evalIridescence( float outsideIOR, float eta2, float cosTheta1, float thinFilmThickness, vec3 baseF0 ) { + + vec3 I; + + // Force iridescenceIor -> outsideIOR when thinFilmThickness -> 0.0 + float iridescenceIor = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) ); + + // Evaluate the cosTheta on the base layer (Snell law) + float sinTheta2Sq = square( outsideIOR / iridescenceIor ) * ( 1.0 - square( cosTheta1 ) ); + + // Handle TIR: + float cosTheta2Sq = 1.0 - sinTheta2Sq; + if ( cosTheta2Sq < 0.0 ) { + + return vec3( 1.0 ); + + } + + float cosTheta2 = sqrt( cosTheta2Sq ); + + // First interface + float R0 = iorToFresnel0( iridescenceIor, outsideIOR ); + float R12 = schlickFresnel( cosTheta1, R0 ); + float R21 = R12; + float T121 = 1.0 - R12; + float phi12 = 0.0; + if ( iridescenceIor < outsideIOR ) { + + phi12 = PI; + + } + + float phi21 = PI - phi12; + + // Second interface + vec3 baseIOR = fresnel0ToIor( clamp( baseF0, 0.0, 0.9999 ) ); // guard against 1.0 + vec3 R1 = iorToFresnel0( baseIOR, iridescenceIor ); + vec3 R23 = schlickFresnel( cosTheta2, R1 ); + vec3 phi23 = vec3( 0.0 ); + if ( baseIOR[0] < iridescenceIor ) { + + phi23[ 0 ] = PI; + + } + + if ( baseIOR[1] < iridescenceIor ) { + + phi23[ 1 ] = PI; + + } + + if ( baseIOR[2] < iridescenceIor ) { + + phi23[ 2 ] = PI; + + } + + // Phase shift + float OPD = 2.0 * iridescenceIor * thinFilmThickness * cosTheta2; + vec3 phi = vec3( phi21 ) + phi23; + + // Compound terms + vec3 R123 = clamp( R12 * R23, 1e-5, 0.9999 ); + vec3 r123 = sqrt( R123 ); + vec3 Rs = square( T121 ) * R23 / ( vec3( 1.0 ) - R123 ); + + // Reflectance term for m = 0 (DC term amplitude) + vec3 C0 = R12 + Rs; + I = C0; + + // Reflectance term for m > 0 (pairs of diracs) + vec3 Cm = Rs - T121; + for ( int m = 1; m <= 2; ++ m ) { + + Cm *= r123; + vec3 Sm = 2.0 * evalSensitivity( float( m ) * OPD, float( m ) * phi ); + I += Cm * Sm; + + } + + // Since out of gamut colors might be produced, negative color values are clamped to 0. + return max( I, vec3( 0.0 ) ); + + } + +`;var Av=` + + // See equation (2) in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf + float velvetD( float cosThetaH, float roughness ) { + + float alpha = max( roughness, 0.07 ); + alpha = alpha * alpha; + + float invAlpha = 1.0 / alpha; + + float sqrCosThetaH = cosThetaH * cosThetaH; + float sinThetaH = max( 1.0 - sqrCosThetaH, 0.001 ); + + return ( 2.0 + invAlpha ) * pow( sinThetaH, 0.5 * invAlpha ) / ( 2.0 * PI ); + + } + + float velvetParamsInterpolate( int i, float oneMinusAlphaSquared ) { + + const float p0[5] = float[5]( 25.3245, 3.32435, 0.16801, -1.27393, -4.85967 ); + const float p1[5] = float[5]( 21.5473, 3.82987, 0.19823, -1.97760, -4.32054 ); + + return mix( p1[i], p0[i], oneMinusAlphaSquared ); + + } + + float velvetL( float x, float alpha ) { + + float oneMinusAlpha = 1.0 - alpha; + float oneMinusAlphaSquared = oneMinusAlpha * oneMinusAlpha; + + float a = velvetParamsInterpolate( 0, oneMinusAlphaSquared ); + float b = velvetParamsInterpolate( 1, oneMinusAlphaSquared ); + float c = velvetParamsInterpolate( 2, oneMinusAlphaSquared ); + float d = velvetParamsInterpolate( 3, oneMinusAlphaSquared ); + float e = velvetParamsInterpolate( 4, oneMinusAlphaSquared ); + + return a / ( 1.0 + b * pow( abs( x ), c ) ) + d * x + e; + + } + + // See equation (3) in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf + float velvetLambda( float cosTheta, float alpha ) { + + return abs( cosTheta ) < 0.5 ? exp( velvetL( cosTheta, alpha ) ) : exp( 2.0 * velvetL( 0.5, alpha ) - velvetL( 1.0 - cosTheta, alpha ) ); + + } + + // See Section 3, Shadowing Term, in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf + float velvetG( float cosThetaO, float cosThetaI, float roughness ) { + + float alpha = max( roughness, 0.07 ); + alpha = alpha * alpha; + + return 1.0 / ( 1.0 + velvetLambda( cosThetaO, alpha ) + velvetLambda( cosThetaI, alpha ) ); + + } + + float directionalAlbedoSheen( float cosTheta, float alpha ) { + + cosTheta = saturate( cosTheta ); + + float c = 1.0 - cosTheta; + float c3 = c * c * c; + + return 0.65584461 * c3 + 1.0 / ( 4.16526551 + exp( -7.97291361 * sqrt( alpha ) + 6.33516894 ) ); + + } + + float sheenAlbedoScaling( vec3 wo, vec3 wi, SurfaceRecord surf ) { + + float alpha = max( surf.sheenRoughness, 0.07 ); + alpha = alpha * alpha; + + float maxSheenColor = max( max( surf.sheenColor.r, surf.sheenColor.g ), surf.sheenColor.b ); + + float eWo = directionalAlbedoSheen( saturateCos( wo.z ), alpha ); + float eWi = directionalAlbedoSheen( saturateCos( wi.z ), alpha ); + + return min( 1.0 - maxSheenColor * eWo, 1.0 - maxSheenColor * eWi ); + + } + + // See Section 5, Layering, in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf + float sheenAlbedoScaling( vec3 wo, SurfaceRecord surf ) { + + float alpha = max( surf.sheenRoughness, 0.07 ); + alpha = alpha * alpha; + + float maxSheenColor = max( max( surf.sheenColor.r, surf.sheenColor.g ), surf.sheenColor.b ); + + float eWo = directionalAlbedoSheen( saturateCos( wo.z ), alpha ); + + return 1.0 - maxSheenColor * eWo; + + } + +`;var Ev=` + +#ifndef FOG_CHECK_ITERATIONS +#define FOG_CHECK_ITERATIONS 30 +#endif + +// returns whether the given material is a fog material or not +bool isMaterialFogVolume( sampler2D materials, uint materialIndex ) { + + uint i = materialIndex * uint( MATERIAL_PIXELS ); + vec4 s14 = texelFetch1D( materials, i + 14u ); + return bool( int( s14.b ) & 4 ); + +} + +// returns true if we're within the first fog volume we hit +bool bvhIntersectFogVolumeHit( + vec3 rayOrigin, vec3 rayDirection, + usampler2D materialIndexAttribute, sampler2D materials, + inout Material material +) { + + material.fogVolume = false; + + for ( int i = 0; i < FOG_CHECK_ITERATIONS; i ++ ) { + + // find nearest hit + uvec4 faceIndices = uvec4( 0u ); + vec3 faceNormal = vec3( 0.0, 0.0, 1.0 ); + vec3 barycoord = vec3( 0.0 ); + float side = 1.0; + float dist = 0.0; + bool hit = bvhIntersectFirstHit( bvh, rayOrigin, rayDirection, faceIndices, faceNormal, barycoord, side, dist ); + if ( hit ) { + + // if it's a fog volume return whether we hit the front or back face + uint materialIndex = uTexelFetch1D( materialIndexAttribute, faceIndices.x ).r; + if ( isMaterialFogVolume( materials, materialIndex ) ) { + + material = readMaterialInfo( materials, materialIndex ); + return side == - 1.0; + + } else { + + // move the ray forward + rayOrigin = stepRayOrigin( rayOrigin, rayDirection, - faceNormal, dist ); + + } + + } else { + + return false; + + } + + } + + return false; + +} + +`;var Rv=` + + // step through multiple surface hits and accumulate color attenuation based on transmissive surfaces + // returns true if a solid surface was hit + bool attenuateHit( + RenderState state, + Ray ray, float rayDist, + out vec3 color + ) { + + // store the original bounce index so we can reset it after + uint originalBounceIndex = sobolBounceIndex; + + int traversals = state.traversals; + int transmissiveTraversals = state.transmissiveTraversals; + bool isShadowRay = state.isShadowRay; + Material fogMaterial = state.fogMaterial; + + vec3 startPoint = ray.origin; + + // hit results + SurfaceHit surfaceHit; + + color = vec3( 1.0 ); + + bool result = true; + for ( int i = 0; i < traversals; i ++ ) { + + sobolBounceIndex ++; + + int hitType = traceScene( ray, fogMaterial, surfaceHit ); + + if ( hitType == FOG_HIT ) { + + result = true; + break; + + } else if ( hitType == SURFACE_HIT ) { + + float totalDist = distance( startPoint, ray.origin + ray.direction * surfaceHit.dist ); + if ( totalDist > rayDist ) { + + result = false; + break; + + } + + // TODO: attenuate the contribution based on the PDF of the resulting ray including refraction values + // Should be able to work using the material BSDF functions which will take into account specularity, etc. + // TODO: should we account for emissive surfaces here? + + uint materialIndex = uTexelFetch1D( materialIndexAttribute, surfaceHit.faceIndices.x ).r; + Material material = readMaterialInfo( materials, materialIndex ); + + // adjust the ray to the new surface + bool isEntering = surfaceHit.side == 1.0; + ray.origin = stepRayOrigin( ray.origin, ray.direction, - surfaceHit.faceNormal, surfaceHit.dist ); + + #if FEATURE_FOG + + if ( material.fogVolume ) { + + fogMaterial = material; + fogMaterial.fogVolume = surfaceHit.side == 1.0; + i -= sign( transmissiveTraversals ); + transmissiveTraversals --; + continue; + + } + + #endif + + if ( ! material.castShadow && isShadowRay ) { + + continue; + + } + + vec2 uv = textureSampleBarycoord( attributesArray, ATTR_UV, surfaceHit.barycoord, surfaceHit.faceIndices.xyz ).xy; + vec4 vertexColor = textureSampleBarycoord( attributesArray, ATTR_COLOR, surfaceHit.barycoord, surfaceHit.faceIndices.xyz ); + + // albedo + vec4 albedo = vec4( material.color, material.opacity ); + if ( material.map != - 1 ) { + + vec3 uvPrime = material.mapTransform * vec3( uv, 1 ); + albedo *= texture2D( textures, vec3( uvPrime.xy, material.map ) ); + + } + + if ( material.vertexColors ) { + + albedo *= vertexColor; + + } + + // alphaMap + if ( material.alphaMap != - 1 ) { + + vec3 uvPrime = material.alphaMapTransform * vec3( uv, 1 ); + albedo.a *= texture2D( textures, vec3( uvPrime.xy, material.alphaMap ) ).x; + + } + + // transmission + float transmission = material.transmission; + if ( material.transmissionMap != - 1 ) { + + vec3 uvPrime = material.transmissionMapTransform * vec3( uv, 1 ); + transmission *= texture2D( textures, vec3( uvPrime.xy, material.transmissionMap ) ).r; + + } + + // metalness + float metalness = material.metalness; + if ( material.metalnessMap != - 1 ) { + + vec3 uvPrime = material.metalnessMapTransform * vec3( uv, 1 ); + metalness *= texture2D( textures, vec3( uvPrime.xy, material.metalnessMap ) ).b; + + } + + float alphaTest = material.alphaTest; + bool useAlphaTest = alphaTest != 0.0; + float transmissionFactor = ( 1.0 - metalness ) * transmission; + if ( + transmissionFactor < rand( 9 ) && ! ( + // material sidedness + material.side != 0.0 && surfaceHit.side == material.side + + // alpha test + || useAlphaTest && albedo.a < alphaTest + + // opacity + || material.transparent && ! useAlphaTest && albedo.a < rand( 10 ) + ) + ) { + + result = true; + break; + + } + + if ( surfaceHit.side == 1.0 && isEntering ) { + + // only attenuate by surface color on the way in + color *= mix( vec3( 1.0 ), albedo.rgb, transmissionFactor ); + + } else if ( surfaceHit.side == - 1.0 ) { + + // attenuate by medium once we hit the opposite side of the model + color *= transmissionAttenuation( surfaceHit.dist, material.attenuationColor, material.attenuationDistance ); + + } + + bool isTransmissiveRay = dot( ray.direction, surfaceHit.faceNormal * surfaceHit.side ) < 0.0; + if ( ( isTransmissiveRay || isEntering ) && transmissiveTraversals > 0 ) { + + i -= sign( transmissiveTraversals ); + transmissiveTraversals --; + + } + + } else { + + result = false; + break; + + } + + } + + // reset the bounce index + sobolBounceIndex = originalBounceIndex; + return result; + + } + +`;var Cv=` + + vec3 ndcToRayOrigin( vec2 coord ) { + + vec4 rayOrigin4 = cameraWorldMatrix * invProjectionMatrix * vec4( coord, - 1.0, 1.0 ); + return rayOrigin4.xyz / rayOrigin4.w; + } + + Ray getCameraRay() { + + vec2 ssd = vec2( 1.0 ) / resolution; + + // Jitter the camera ray by finding a uv coordinate at a random sample + // around this pixel's UV coordinate for AA + vec2 ruv = rand2( 0 ); + vec2 jitteredUv = vUv + vec2( tentFilter( ruv.x ) * ssd.x, tentFilter( ruv.y ) * ssd.y ); + Ray ray; + + #if CAMERA_TYPE == 2 + + // Equirectangular projection + vec4 rayDirection4 = vec4( equirectUvToDirection( jitteredUv ), 0.0 ); + vec4 rayOrigin4 = vec4( 0.0, 0.0, 0.0, 1.0 ); + + rayDirection4 = cameraWorldMatrix * rayDirection4; + rayOrigin4 = cameraWorldMatrix * rayOrigin4; + + ray.direction = normalize( rayDirection4.xyz ); + ray.origin = rayOrigin4.xyz / rayOrigin4.w; + + #else + + // get [- 1, 1] normalized device coordinates + vec2 ndc = 2.0 * jitteredUv - vec2( 1.0 ); + ray.origin = ndcToRayOrigin( ndc ); + + #if CAMERA_TYPE == 1 + + // Orthographic projection + ray.direction = ( cameraWorldMatrix * vec4( 0.0, 0.0, - 1.0, 0.0 ) ).xyz; + ray.direction = normalize( ray.direction ); + + #else + + // Perspective projection + ray.direction = normalize( mat3( cameraWorldMatrix ) * ( invProjectionMatrix * vec4( ndc, 0.0, 1.0 ) ).xyz ); + + #endif + + #endif + + #if FEATURE_DOF + { + + // depth of field + vec3 focalPoint = ray.origin + normalize( ray.direction ) * physicalCamera.focusDistance; + + // get the aperture sample + // if blades === 0 then we assume a circle + vec3 shapeUVW= rand3( 1 ); + int blades = physicalCamera.apertureBlades; + float anamorphicRatio = physicalCamera.anamorphicRatio; + vec2 apertureSample = sampleAperture( blades, shapeUVW ); + apertureSample *= physicalCamera.bokehSize * 0.5 * 1e-3; + + // rotate the aperture shape + apertureSample = + rotateVector( apertureSample, physicalCamera.apertureRotation ) * + saturate( vec2( anamorphicRatio, 1.0 / anamorphicRatio ) ); + + // create the new ray + ray.origin += ( cameraWorldMatrix * vec4( apertureSample, 0.0, 0.0 ) ).xyz; + ray.direction = focalPoint - ray.origin; + + } + #endif + + ray.direction = normalize( ray.direction ); + + return ray; + + } + +`;var Iv=` + + vec3 directLightContribution( vec3 worldWo, SurfaceRecord surf, RenderState state, vec3 rayOrigin ) { + + vec3 result = vec3( 0.0 ); + + // uniformly pick a light or environment map + if( lightsDenom != 0.0 && rand( 5 ) < float( lights.count ) / lightsDenom ) { + + // sample a light or environment + LightRecord lightRec = randomLightSample( lights.tex, iesProfiles, lights.count, rayOrigin, rand3( 6 ) ); + + bool isSampleBelowSurface = ! surf.volumeParticle && dot( surf.faceNormal, lightRec.direction ) < 0.0; + if ( isSampleBelowSurface ) { + + lightRec.pdf = 0.0; + + } + + // check if a ray could even reach the light area + Ray lightRay; + lightRay.origin = rayOrigin; + lightRay.direction = lightRec.direction; + vec3 attenuatedColor; + if ( + lightRec.pdf > 0.0 && + isDirectionValid( lightRec.direction, surf.normal, surf.faceNormal ) && + ! attenuateHit( state, lightRay, lightRec.dist, attenuatedColor ) + ) { + + // get the material pdf + vec3 sampleColor; + float lightMaterialPdf = bsdfResult( worldWo, lightRec.direction, surf, sampleColor ); + bool isValidSampleColor = all( greaterThanEqual( sampleColor, vec3( 0.0 ) ) ); + if ( lightMaterialPdf > 0.0 && isValidSampleColor ) { + + // weight the direct light contribution + float lightPdf = lightRec.pdf / lightsDenom; + float misWeight = lightRec.type == SPOT_LIGHT_TYPE || lightRec.type == DIR_LIGHT_TYPE || lightRec.type == POINT_LIGHT_TYPE ? 1.0 : misHeuristic( lightPdf, lightMaterialPdf ); + result = attenuatedColor * lightRec.emission * state.throughputColor * sampleColor * misWeight / lightPdf; + + } + + } + + } else if ( envMapInfo.totalSum != 0.0 && environmentIntensity != 0.0 ) { + + // find a sample in the environment map to include in the contribution + vec3 envColor, envDirection; + float envPdf = sampleEquirectProbability( rand2( 7 ), envColor, envDirection ); + envDirection = invEnvRotation3x3 * envDirection; + + // this env sampling is not set up for transmissive sampling and yields overly bright + // results so we ignore the sample in this case. + // TODO: this should be improved but how? The env samples could traverse a few layers? + bool isSampleBelowSurface = ! surf.volumeParticle && dot( surf.faceNormal, envDirection ) < 0.0; + if ( isSampleBelowSurface ) { + + envPdf = 0.0; + + } + + // check if a ray could even reach the surface + Ray envRay; + envRay.origin = rayOrigin; + envRay.direction = envDirection; + vec3 attenuatedColor; + if ( + envPdf > 0.0 && + isDirectionValid( envDirection, surf.normal, surf.faceNormal ) && + ! attenuateHit( state, envRay, INFINITY, attenuatedColor ) + ) { + + // get the material pdf + vec3 sampleColor; + float envMaterialPdf = bsdfResult( worldWo, envDirection, surf, sampleColor ); + bool isValidSampleColor = all( greaterThanEqual( sampleColor, vec3( 0.0 ) ) ); + if ( envMaterialPdf > 0.0 && isValidSampleColor ) { + + // weight the direct light contribution + envPdf /= lightsDenom; + float misWeight = misHeuristic( envPdf, envMaterialPdf ); + result = attenuatedColor * environmentIntensity * envColor * state.throughputColor * sampleColor * misWeight / envPdf; + + } + + } + + } + + // Function changed to have a single return statement to potentially help with crashes on Mac OS. + // See issue #470 + return result; + + } + +`;var Pv=` + + #define SKIP_SURFACE 0 + #define HIT_SURFACE 1 + int getSurfaceRecord( + Material material, SurfaceHit surfaceHit, sampler2DArray attributesArray, + float accumulatedRoughness, + inout SurfaceRecord surf + ) { + + if ( material.fogVolume ) { + + vec3 normal = vec3( 0, 0, 1 ); + + SurfaceRecord fogSurface; + fogSurface.volumeParticle = true; + fogSurface.color = material.color; + fogSurface.emission = material.emissiveIntensity * material.emissive; + fogSurface.normal = normal; + fogSurface.faceNormal = normal; + fogSurface.clearcoatNormal = normal; + + surf = fogSurface; + return HIT_SURFACE; + + } + + // uv coord for textures + vec2 uv = textureSampleBarycoord( attributesArray, ATTR_UV, surfaceHit.barycoord, surfaceHit.faceIndices.xyz ).xy; + vec4 vertexColor = textureSampleBarycoord( attributesArray, ATTR_COLOR, surfaceHit.barycoord, surfaceHit.faceIndices.xyz ); + + // albedo + vec4 albedo = vec4( material.color, material.opacity ); + if ( material.map != - 1 ) { + + vec3 uvPrime = material.mapTransform * vec3( uv, 1 ); + albedo *= texture2D( textures, vec3( uvPrime.xy, material.map ) ); + + } + + if ( material.vertexColors ) { + + albedo *= vertexColor; + + } + + // alphaMap + if ( material.alphaMap != - 1 ) { + + vec3 uvPrime = material.alphaMapTransform * vec3( uv, 1 ); + albedo.a *= texture2D( textures, vec3( uvPrime.xy, material.alphaMap ) ).x; + + } + + // possibly skip this sample if it's transparent, alpha test is enabled, or we hit the wrong material side + // and it's single sided. + // - alpha test is disabled when it === 0 + // - the material sidedness test is complicated because we want light to pass through the back side but still + // be able to see the front side. This boolean checks if the side we hit is the front side on the first ray + // and we're rendering the other then we skip it. Do the opposite on subsequent bounces to get incoming light. + float alphaTest = material.alphaTest; + bool useAlphaTest = alphaTest != 0.0; + if ( + // material sidedness + material.side != 0.0 && surfaceHit.side != material.side + + // alpha test + || useAlphaTest && albedo.a < alphaTest + + // opacity + || material.transparent && ! useAlphaTest && albedo.a < rand( 3 ) + ) { + + return SKIP_SURFACE; + + } + + // fetch the interpolated smooth normal + vec3 normal = normalize( textureSampleBarycoord( + attributesArray, + ATTR_NORMAL, + surfaceHit.barycoord, + surfaceHit.faceIndices.xyz + ).xyz ); + + // roughness + float roughness = material.roughness; + if ( material.roughnessMap != - 1 ) { + + vec3 uvPrime = material.roughnessMapTransform * vec3( uv, 1 ); + roughness *= texture2D( textures, vec3( uvPrime.xy, material.roughnessMap ) ).g; + + } + + // metalness + float metalness = material.metalness; + if ( material.metalnessMap != - 1 ) { + + vec3 uvPrime = material.metalnessMapTransform * vec3( uv, 1 ); + metalness *= texture2D( textures, vec3( uvPrime.xy, material.metalnessMap ) ).b; + + } + + // emission + vec3 emission = material.emissiveIntensity * material.emissive; + if ( material.emissiveMap != - 1 ) { + + vec3 uvPrime = material.emissiveMapTransform * vec3( uv, 1 ); + emission *= texture2D( textures, vec3( uvPrime.xy, material.emissiveMap ) ).xyz; + + } + + // transmission + float transmission = material.transmission; + if ( material.transmissionMap != - 1 ) { + + vec3 uvPrime = material.transmissionMapTransform * vec3( uv, 1 ); + transmission *= texture2D( textures, vec3( uvPrime.xy, material.transmissionMap ) ).r; + + } + + // normal + if ( material.flatShading ) { + + // if we're rendering a flat shaded object then use the face normals - the face normal + // is provided based on the side the ray hits the mesh so flip it to align with the + // interpolated vertex normals. + normal = surfaceHit.faceNormal * surfaceHit.side; + + } + + vec3 baseNormal = normal; + if ( material.normalMap != - 1 ) { + + vec4 tangentSample = textureSampleBarycoord( + attributesArray, + ATTR_TANGENT, + surfaceHit.barycoord, + surfaceHit.faceIndices.xyz + ); + + // some provided tangents can be malformed (0, 0, 0) causing the normal to be degenerate + // resulting in NaNs and slow path tracing. + if ( length( tangentSample.xyz ) > 0.0 ) { + + vec3 tangent = normalize( tangentSample.xyz ); + vec3 bitangent = normalize( cross( normal, tangent ) * tangentSample.w ); + mat3 vTBN = mat3( tangent, bitangent, normal ); + + vec3 uvPrime = material.normalMapTransform * vec3( uv, 1 ); + vec3 texNormal = texture2D( textures, vec3( uvPrime.xy, material.normalMap ) ).xyz * 2.0 - 1.0; + texNormal.xy *= material.normalScale; + normal = vTBN * texNormal; + + } + + } + + normal *= surfaceHit.side; + + // clearcoat + float clearcoat = material.clearcoat; + if ( material.clearcoatMap != - 1 ) { + + vec3 uvPrime = material.clearcoatMapTransform * vec3( uv, 1 ); + clearcoat *= texture2D( textures, vec3( uvPrime.xy, material.clearcoatMap ) ).r; + + } + + // clearcoatRoughness + float clearcoatRoughness = material.clearcoatRoughness; + if ( material.clearcoatRoughnessMap != - 1 ) { + + vec3 uvPrime = material.clearcoatRoughnessMapTransform * vec3( uv, 1 ); + clearcoatRoughness *= texture2D( textures, vec3( uvPrime.xy, material.clearcoatRoughnessMap ) ).g; + + } + + // clearcoatNormal + vec3 clearcoatNormal = baseNormal; + if ( material.clearcoatNormalMap != - 1 ) { + + vec4 tangentSample = textureSampleBarycoord( + attributesArray, + ATTR_TANGENT, + surfaceHit.barycoord, + surfaceHit.faceIndices.xyz + ); + + // some provided tangents can be malformed (0, 0, 0) causing the normal to be degenerate + // resulting in NaNs and slow path tracing. + if ( length( tangentSample.xyz ) > 0.0 ) { + + vec3 tangent = normalize( tangentSample.xyz ); + vec3 bitangent = normalize( cross( clearcoatNormal, tangent ) * tangentSample.w ); + mat3 vTBN = mat3( tangent, bitangent, clearcoatNormal ); + + vec3 uvPrime = material.clearcoatNormalMapTransform * vec3( uv, 1 ); + vec3 texNormal = texture2D( textures, vec3( uvPrime.xy, material.clearcoatNormalMap ) ).xyz * 2.0 - 1.0; + texNormal.xy *= material.clearcoatNormalScale; + clearcoatNormal = vTBN * texNormal; + + } + + } + + clearcoatNormal *= surfaceHit.side; + + // sheenColor + vec3 sheenColor = material.sheenColor; + if ( material.sheenColorMap != - 1 ) { + + vec3 uvPrime = material.sheenColorMapTransform * vec3( uv, 1 ); + sheenColor *= texture2D( textures, vec3( uvPrime.xy, material.sheenColorMap ) ).rgb; + + } + + // sheenRoughness + float sheenRoughness = material.sheenRoughness; + if ( material.sheenRoughnessMap != - 1 ) { + + vec3 uvPrime = material.sheenRoughnessMapTransform * vec3( uv, 1 ); + sheenRoughness *= texture2D( textures, vec3( uvPrime.xy, material.sheenRoughnessMap ) ).a; + + } + + // iridescence + float iridescence = material.iridescence; + if ( material.iridescenceMap != - 1 ) { + + vec3 uvPrime = material.iridescenceMapTransform * vec3( uv, 1 ); + iridescence *= texture2D( textures, vec3( uvPrime.xy, material.iridescenceMap ) ).r; + + } + + // iridescence thickness + float iridescenceThickness = material.iridescenceThicknessMaximum; + if ( material.iridescenceThicknessMap != - 1 ) { + + vec3 uvPrime = material.iridescenceThicknessMapTransform * vec3( uv, 1 ); + float iridescenceThicknessSampled = texture2D( textures, vec3( uvPrime.xy, material.iridescenceThicknessMap ) ).g; + iridescenceThickness = mix( material.iridescenceThicknessMinimum, material.iridescenceThicknessMaximum, iridescenceThicknessSampled ); + + } + + iridescence = iridescenceThickness == 0.0 ? 0.0 : iridescence; + + // specular color + vec3 specularColor = material.specularColor; + if ( material.specularColorMap != - 1 ) { + + vec3 uvPrime = material.specularColorMapTransform * vec3( uv, 1 ); + specularColor *= texture2D( textures, vec3( uvPrime.xy, material.specularColorMap ) ).rgb; + + } + + // specular intensity + float specularIntensity = material.specularIntensity; + if ( material.specularIntensityMap != - 1 ) { + + vec3 uvPrime = material.specularIntensityMapTransform * vec3( uv, 1 ); + specularIntensity *= texture2D( textures, vec3( uvPrime.xy, material.specularIntensityMap ) ).a; + + } + + surf.volumeParticle = false; + + surf.faceNormal = surfaceHit.faceNormal; + surf.normal = normal; + + surf.metalness = metalness; + surf.color = albedo.rgb; + surf.emission = emission; + + surf.ior = material.ior; + surf.transmission = transmission; + surf.thinFilm = material.thinFilm; + surf.attenuationColor = material.attenuationColor; + surf.attenuationDistance = material.attenuationDistance; + + surf.clearcoatNormal = clearcoatNormal; + surf.clearcoat = clearcoat; + + surf.sheen = material.sheen; + surf.sheenColor = sheenColor; + + surf.iridescence = iridescence; + surf.iridescenceIor = material.iridescenceIor; + surf.iridescenceThickness = iridescenceThickness; + + surf.specularColor = specularColor; + surf.specularIntensity = specularIntensity; + + // apply perceptual roughness factor from gltf. sheen perceptual roughness is + // applied by its brdf function + // https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#microfacet-surfaces + surf.roughness = roughness * roughness; + surf.clearcoatRoughness = clearcoatRoughness * clearcoatRoughness; + surf.sheenRoughness = sheenRoughness; + + // frontFace is used to determine transmissive properties and PDF. If no transmission is used + // then we can just always assume this is a front face. + surf.frontFace = surfaceHit.side == 1.0 || transmission == 0.0; + surf.eta = material.thinFilm || surf.frontFace ? 1.0 / material.ior : material.ior; + surf.f0 = iorRatioToF0( surf.eta ); + + // Compute the filtered roughness value to use during specular reflection computations. + // The accumulated roughness value is scaled by a user setting and a "magic value" of 5.0. + // If we're exiting something transmissive then scale the factor down significantly so we can retain + // sharp internal reflections + surf.filteredRoughness = applyFilteredGlossy( surf.roughness, accumulatedRoughness ); + surf.filteredClearcoatRoughness = applyFilteredGlossy( surf.clearcoatRoughness, accumulatedRoughness ); + + // get the normal frames + surf.normalBasis = getBasisFromNormal( surf.normal ); + surf.normalInvBasis = inverse( surf.normalBasis ); + + surf.clearcoatBasis = getBasisFromNormal( surf.clearcoatNormal ); + surf.clearcoatInvBasis = inverse( surf.clearcoatBasis ); + + return HIT_SURFACE; + + } +`;var Dv=` + + struct Ray { + + vec3 origin; + vec3 direction; + + }; + + struct SurfaceHit { + + uvec4 faceIndices; + vec3 barycoord; + vec3 faceNormal; + float side; + float dist; + + }; + + struct RenderState { + + bool firstRay; + bool transmissiveRay; + bool isShadowRay; + float accumulatedRoughness; + int transmissiveTraversals; + int traversals; + uint depth; + vec3 throughputColor; + Material fogMaterial; + + }; + + RenderState initRenderState() { + + RenderState result; + result.firstRay = true; + result.transmissiveRay = true; + result.isShadowRay = false; + result.accumulatedRoughness = 0.0; + result.transmissiveTraversals = 0; + result.traversals = 0; + result.throughputColor = vec3( 1.0 ); + result.depth = 0u; + result.fogMaterial.fogVolume = false; + return result; + + } + +`;var Fv=` + + #define NO_HIT 0 + #define SURFACE_HIT 1 + #define LIGHT_HIT 2 + #define FOG_HIT 3 + + // Passing the global variable 'lights' into this function caused shader program errors. + // So global variables like 'lights' and 'bvh' were moved out of the function parameters. + // For more information, refer to: https://github.com/gkjohnson/three-gpu-pathtracer/pull/457 + int traceScene( + Ray ray, Material fogMaterial, inout SurfaceHit surfaceHit + ) { + + int result = NO_HIT; + bool hit = bvhIntersectFirstHit( bvh, ray.origin, ray.direction, surfaceHit.faceIndices, surfaceHit.faceNormal, surfaceHit.barycoord, surfaceHit.side, surfaceHit.dist ); + + #if FEATURE_FOG + + if ( fogMaterial.fogVolume ) { + + // offset the distance so we don't run into issues with particles on the same surface + // as other objects + float particleDist = intersectFogVolume( fogMaterial, rand( 1 ) ); + if ( particleDist + RAY_OFFSET < surfaceHit.dist ) { + + surfaceHit.side = 1.0; + surfaceHit.faceNormal = normalize( - ray.direction ); + surfaceHit.dist = particleDist; + return FOG_HIT; + + } + + } + + #endif + + if ( hit ) { + + result = SURFACE_HIT; + + } + + return result; + + } + +`;var Ch=class extends li{onBeforeRender(){this.setDefine("FEATURE_DOF",this.physicalCamera.bokehSize===0?0:1),this.setDefine("FEATURE_BACKGROUND_MAP",this.backgroundMap?1:0),this.setDefine("FEATURE_FOG",this.materials.features.isUsed("FOG")?1:0)}constructor(t){super({transparent:!0,depthWrite:!1,defines:{FEATURE_MIS:1,FEATURE_RUSSIAN_ROULETTE:1,FEATURE_DOF:1,FEATURE_BACKGROUND_MAP:0,FEATURE_FOG:1,RANDOM_TYPE:2,CAMERA_TYPE:0,DEBUG_MODE:0,ATTR_NORMAL:0,ATTR_TANGENT:1,ATTR_UV:2,ATTR_COLOR:3,MATERIAL_PIXELS:Sh},uniforms:{resolution:{value:new q},opacity:{value:1},bounces:{value:10},transmissiveBounces:{value:10},filterGlossyFactor:{value:0},physicalCamera:{value:new ph},cameraWorldMatrix:{value:new gt},invProjectionMatrix:{value:new gt},bvh:{value:new th},attributesArray:{value:new _h},materialIndexAttribute:{value:new eo},materials:{value:new bh},textures:{value:new Da().texture},lights:{value:new xh},iesProfiles:{value:new Da(360,180,{type:Ge,wrapS:we,wrapT:we}).texture},environmentIntensity:{value:1},environmentRotation:{value:new gt},envMapInfo:{value:new gh},backgroundBlur:{value:0},backgroundMap:{value:null},backgroundAlpha:{value:1},backgroundIntensity:{value:1},backgroundRotation:{value:new gt},seed:{value:0},sobolTexture:{value:null},stratifiedTexture:{value:new wh},stratifiedOffsetTexture:{value:new Eh(64,1)}},vertexShader:` + + varying vec2 vUv; + void main() { + + vec4 mvPosition = vec4( position, 1.0 ); + mvPosition = modelViewMatrix * mvPosition; + gl_Position = projectionMatrix * mvPosition; + + vUv = uv; + + } + + `,fragmentShader:` + #define RAY_OFFSET 1e-4 + #define INFINITY 1e20 + + precision highp isampler2D; + precision highp usampler2D; + precision highp sampler2DArray; + vec4 envMapTexelToLinear( vec4 a ) { return a; } + #include + + // bvh intersection + ${Hr.common_functions} + ${Hr.bvh_struct_definitions} + ${Hr.bvh_ray_functions} + + // uniform structs + ${lv} + ${hv} + ${uv} + ${fv} + ${dv} + + // random + #if RANDOM_TYPE == 2 // Stratified List + + ${bv} + + #elif RANDOM_TYPE == 1 // Sobol + + ${Jp} + ${fh} + ${Kx} + + #define rand(v) sobol(v) + #define rand2(v) sobol2(v) + #define rand3(v) sobol3(v) + #define rand4(v) sobol4(v) + + #else // PCG + + ${Jp} + + // Using the sobol functions seems to break the the compiler on MacOS + // - specifically the "sobolReverseBits" function. + uint sobolPixelIndex = 0u; + uint sobolPathIndex = 0u; + uint sobolBounceIndex = 0u; + + #define rand(v) pcgRand() + #define rand2(v) pcgRand2() + #define rand3(v) pcgRand3() + #define rand4(v) pcgRand4() + + #endif + + // common + ${yv} + ${xv} + ${Rh} + ${vv} + ${_v} + + // environment + uniform EquirectHdrInfo envMapInfo; + uniform mat4 environmentRotation; + uniform float environmentIntensity; + + // lighting + uniform sampler2DArray iesProfiles; + uniform LightsInfo lights; + + // background + uniform float backgroundBlur; + uniform float backgroundAlpha; + #if FEATURE_BACKGROUND_MAP + + uniform sampler2D backgroundMap; + uniform mat4 backgroundRotation; + uniform float backgroundIntensity; + + #endif + + // camera + uniform mat4 cameraWorldMatrix; + uniform mat4 invProjectionMatrix; + #if FEATURE_DOF + + uniform PhysicalCamera physicalCamera; + + #endif + + // geometry + uniform sampler2DArray attributesArray; + uniform usampler2D materialIndexAttribute; + uniform sampler2D materials; + uniform sampler2DArray textures; + uniform BVH bvh; + + // path tracer + uniform int bounces; + uniform int transmissiveBounces; + uniform float filterGlossyFactor; + uniform int seed; + + // image + uniform vec2 resolution; + uniform float opacity; + + varying vec2 vUv; + + // globals + mat3 envRotation3x3; + mat3 invEnvRotation3x3; + float lightsDenom; + + // sampling + ${gv} + ${pv} + ${mv} + + ${Ev} + ${Tv} + ${Av} + ${wv} + ${Mv} + ${Sv} + + float applyFilteredGlossy( float roughness, float accumulatedRoughness ) { + + return clamp( + max( + roughness, + accumulatedRoughness * filterGlossyFactor * 5.0 ), + 0.0, + 1.0 + ); + + } + + vec3 sampleBackground( vec3 direction, vec2 uv ) { + + vec3 sampleDir = sampleHemisphere( direction, uv ) * 0.5 * backgroundBlur; + + #if FEATURE_BACKGROUND_MAP + + sampleDir = normalize( mat3( backgroundRotation ) * direction + sampleDir ); + return backgroundIntensity * sampleEquirectColor( backgroundMap, sampleDir ); + + #else + + sampleDir = normalize( envRotation3x3 * direction + sampleDir ); + return environmentIntensity * sampleEquirectColor( envMapInfo.map, sampleDir ); + + #endif + + } + + ${Dv} + ${Cv} + ${Fv} + ${Rv} + ${Iv} + ${Pv} + + void main() { + + // init + rng_initialize( gl_FragCoord.xy, seed ); + sobolPixelIndex = ( uint( gl_FragCoord.x ) << 16 ) | uint( gl_FragCoord.y ); + sobolPathIndex = uint( seed ); + + // get camera ray + Ray ray = getCameraRay(); + + // inverse environment rotation + envRotation3x3 = mat3( environmentRotation ); + invEnvRotation3x3 = inverse( envRotation3x3 ); + lightsDenom = + ( environmentIntensity == 0.0 || envMapInfo.totalSum == 0.0 ) && lights.count != 0u ? + float( lights.count ) : + float( lights.count + 1u ); + + // final color + gl_FragColor = vec4( 0, 0, 0, 1 ); + + // surface results + SurfaceHit surfaceHit; + ScatterRecord scatterRec; + + // path tracing state + RenderState state = initRenderState(); + state.transmissiveTraversals = transmissiveBounces; + #if FEATURE_FOG + + state.fogMaterial.fogVolume = bvhIntersectFogVolumeHit( + ray.origin, - ray.direction, + materialIndexAttribute, materials, + state.fogMaterial + ); + + #endif + + for ( int i = 0; i < bounces; i ++ ) { + + sobolBounceIndex ++; + + state.depth ++; + state.traversals = bounces - i; + state.firstRay = i == 0 && state.transmissiveTraversals == transmissiveBounces; + + int hitType = traceScene( ray, state.fogMaterial, surfaceHit ); + + // check if we intersect any lights and accumulate the light contribution + // TODO: we can add support for light surface rendering in the else condition if we + // add the ability to toggle visibility of the the light + if ( ! state.firstRay && ! state.transmissiveRay ) { + + LightRecord lightRec; + float lightDist = hitType == NO_HIT ? INFINITY : surfaceHit.dist; + for ( uint i = 0u; i < lights.count; i ++ ) { + + if ( + intersectLightAtIndex( lights.tex, ray.origin, ray.direction, i, lightRec ) && + lightRec.dist < lightDist + ) { + + #if FEATURE_MIS + + // weight the contribution + // NOTE: Only area lights are supported for forward sampling and can be hit + float misWeight = misHeuristic( scatterRec.pdf, lightRec.pdf / lightsDenom ); + gl_FragColor.rgb += lightRec.emission * state.throughputColor * misWeight; + + #else + + gl_FragColor.rgb += lightRec.emission * state.throughputColor; + + #endif + + } + + } + + } + + if ( hitType == NO_HIT ) { + + if ( state.firstRay || state.transmissiveRay ) { + + gl_FragColor.rgb += sampleBackground( ray.direction, rand2( 2 ) ) * state.throughputColor; + gl_FragColor.a = backgroundAlpha; + + } else { + + #if FEATURE_MIS + + // get the PDF of the hit envmap point + vec3 envColor; + float envPdf = sampleEquirect( envRotation3x3 * ray.direction, envColor ); + envPdf /= lightsDenom; + + // and weight the contribution + float misWeight = misHeuristic( scatterRec.pdf, envPdf ); + gl_FragColor.rgb += environmentIntensity * envColor * state.throughputColor * misWeight; + + #else + + gl_FragColor.rgb += + environmentIntensity * + sampleEquirectColor( envMapInfo.map, envRotation3x3 * ray.direction ) * + state.throughputColor; + + #endif + + } + break; + + } + + uint materialIndex = uTexelFetch1D( materialIndexAttribute, surfaceHit.faceIndices.x ).r; + Material material = readMaterialInfo( materials, materialIndex ); + + #if FEATURE_FOG + + if ( hitType == FOG_HIT ) { + + material = state.fogMaterial; + state.accumulatedRoughness += 0.2; + + } else if ( material.fogVolume ) { + + state.fogMaterial = material; + state.fogMaterial.fogVolume = surfaceHit.side == 1.0; + + ray.origin = stepRayOrigin( ray.origin, ray.direction, - surfaceHit.faceNormal, surfaceHit.dist ); + + i -= sign( state.transmissiveTraversals ); + state.transmissiveTraversals -= sign( state.transmissiveTraversals ); + continue; + + } + + #endif + + // early out if this is a matte material + if ( material.matte && state.firstRay ) { + + gl_FragColor = vec4( 0.0 ); + break; + + } + + // if we've determined that this is a shadow ray and we've hit an item with no shadow casting + // then skip it + if ( ! material.castShadow && state.isShadowRay ) { + + ray.origin = stepRayOrigin( ray.origin, ray.direction, - surfaceHit.faceNormal, surfaceHit.dist ); + continue; + + } + + SurfaceRecord surf; + if ( + getSurfaceRecord( + material, surfaceHit, attributesArray, state.accumulatedRoughness, + surf + ) == SKIP_SURFACE + ) { + + // only allow a limited number of transparency discards otherwise we could + // crash the context with too long a loop. + i -= sign( state.transmissiveTraversals ); + state.transmissiveTraversals -= sign( state.transmissiveTraversals ); + + ray.origin = stepRayOrigin( ray.origin, ray.direction, - surfaceHit.faceNormal, surfaceHit.dist ); + continue; + + } + + scatterRec = bsdfSample( - ray.direction, surf ); + state.isShadowRay = scatterRec.specularPdf < rand( 4 ); + + bool isBelowSurface = ! surf.volumeParticle && dot( scatterRec.direction, surf.faceNormal ) < 0.0; + vec3 hitPoint = stepRayOrigin( ray.origin, ray.direction, isBelowSurface ? - surf.faceNormal : surf.faceNormal, surfaceHit.dist ); + + // next event estimation + #if FEATURE_MIS + + gl_FragColor.rgb += directLightContribution( - ray.direction, surf, state, hitPoint ); + + #endif + + // accumulate a roughness value to offset diffuse, specular, diffuse rays that have high contribution + // to a single pixel resulting in fireflies + // TODO: handle transmissive surfaces + if ( ! surf.volumeParticle && ! isBelowSurface ) { + + // determine if this is a rough normal or not by checking how far off straight up it is + vec3 halfVector = normalize( - ray.direction + scatterRec.direction ); + state.accumulatedRoughness += max( + sin( acosApprox( dot( halfVector, surf.normal ) ) ), + sin( acosApprox( dot( halfVector, surf.clearcoatNormal ) ) ) + ); + + state.transmissiveRay = false; + + } + + // accumulate emissive color + gl_FragColor.rgb += ( surf.emission * state.throughputColor ); + + // skip the sample if our PDF or ray is impossible + if ( scatterRec.pdf <= 0.0 || ! isDirectionValid( scatterRec.direction, surf.normal, surf.faceNormal ) ) { + + break; + + } + + // if we're bouncing around the inside a transmissive material then decrement + // perform this separate from a bounce + bool isTransmissiveRay = ! surf.volumeParticle && dot( scatterRec.direction, surf.faceNormal * surfaceHit.side ) < 0.0; + if ( ( isTransmissiveRay || isBelowSurface ) && state.transmissiveTraversals > 0 ) { + + state.transmissiveTraversals --; + i --; + + } + + // + + // handle throughput color transformation + // attenuate the throughput color by the medium color + if ( ! surf.frontFace ) { + + state.throughputColor *= transmissionAttenuation( surfaceHit.dist, surf.attenuationColor, surf.attenuationDistance ); + + } + + #if FEATURE_RUSSIAN_ROULETTE + + // russian roulette path termination + // https://www.arnoldrenderer.com/research/physically_based_shader_design_in_arnold.pdf + uint minBounces = 3u; + float depthProb = float( state.depth < minBounces ); + + float rrProb = luminance( state.throughputColor * scatterRec.color / scatterRec.pdf ); + rrProb /= luminance( state.throughputColor ); + rrProb = sqrt( rrProb ); + rrProb = max( rrProb, depthProb ); + rrProb = min( rrProb, 1.0 ); + if ( rand( 8 ) > rrProb ) { + + break; + + } + + // perform sample clamping here to avoid bright pixels + state.throughputColor *= min( 1.0 / rrProb, 20.0 ); + + #endif + + // adjust the throughput and discard and exit if we find discard the sample if there are any NaNs + state.throughputColor *= scatterRec.color / scatterRec.pdf; + if ( any( isnan( state.throughputColor ) ) || any( isinf( state.throughputColor ) ) ) { + + break; + + } + + // + + // prepare for next ray + ray.direction = scatterRec.direction; + ray.origin = hitPoint; + + } + + gl_FragColor.a *= opacity; + + #if DEBUG_MODE == 1 + + // output the number of rays checked in the path and number of + // transmissive rays encountered. + gl_FragColor.rgb = vec3( + float( state.depth ), + transmissiveBounces - state.transmissiveTraversals, + 0.0 + ); + gl_FragColor.a = 1.0; + + #endif + + } + + `}),this.setValues(t)}};function*jA(){let{_renderer:r,_fsQuad:t,_blendQuad:e,_primaryTarget:n,_blendTargets:i,_sobolTarget:s,_subframe:o,alpha:a,material:c}=this,l=new Kt,f=new Kt,h=e.material,[u,d]=i;for(;;){a?(h.opacity=this._opacityFactor/(this.samples+1),c.blending=ke,c.opacity=1):(c.opacity=this._opacityFactor/(this.samples+1),c.blending=Yn);let[g,x,p,m]=o,v=n.width,_=n.height;c.resolution.set(v*p,_*m),c.sobolTexture=s.texture,c.stratifiedTexture.init(20,c.bounces+c.transmissiveBounces+5),c.stratifiedTexture.next(),c.seed++;let y=this.tiles.x||1,b=this.tiles.y||1,T=y*b,w=Math.ceil(v*p),E=Math.ceil(_*m),M=Math.floor(g*v),S=Math.floor(x*_),I=Math.ceil(w/y),P=Math.ceil(E/b);for(let L=0;L{let e=this.compileMaterial(this._fsQuad._mesh);e.then(()=>{this._compilePromise===e&&(this._compilePromise=null)}),this._compilePromise=e},this.material.addEventListener("recompilation",this._compileFunction)}compileMaterial(){return this._renderer.compileAsync(this._fsQuad._mesh)}setCamera(t){let{material:e}=this;e.cameraWorldMatrix.copy(t.matrixWorld),e.invProjectionMatrix.copy(t.projectionMatrixInverse),e.physicalCamera.updateFrom(t);let n=0;t.projectionMatrix.elements[15]>0&&(n=1),t.isEquirectCamera&&(n=2),e.setDefine("CAMERA_TYPE",n),this.camera=t}setSize(t,e){t=Math.ceil(t),e=Math.ceil(e),!(this._primaryTarget.width===t&&this._primaryTarget.height===e)&&(this._primaryTarget.setSize(t,e),this._blendTargets[0].setSize(t,e),this._blendTargets[1].setSize(t,e),this.reset())}getSize(t){t.x=this._primaryTarget.width,t.y=this._primaryTarget.height}dispose(){this._primaryTarget.dispose(),this._blendTargets[0].dispose(),this._blendTargets[1].dispose(),this._sobolTarget.dispose(),this._fsQuad.dispose(),this._blendQuad.dispose(),this._task=null}reset(){let{_renderer:t,_primaryTarget:e,_blendTargets:n}=this,i=t.getRenderTarget(),s=t.getClearAlpha();t.getClearColor(Lv),t.setRenderTarget(e),t.setClearColor(0,0),t.clearColor(),t.setRenderTarget(n[0]),t.setClearColor(0,0),t.clearColor(),t.setRenderTarget(n[1]),t.setClearColor(0,0),t.clearColor(),t.setClearColor(Lv,s),t.setRenderTarget(i),this.samples=0,this._task=null,this.material.stratifiedTexture.stableNoise=this.stableNoise,this.stableNoise&&(this.material.seed=0,this.material.stratifiedTexture.reset())}update(){this.material.onBeforeRender(),!this.isCompiling&&(this._task||(this._task=jA.call(this)),this._task.next())}};var Yr=new q,Nv=new q,Ih=new aa,Ph=new ft,Dh=class extends oe{constructor(t=512,e=512){super(new Float32Array(t*e*4),t,e,Gt,$t,Mi,Ke,we,re,re),this.generationCallback=null}update(){this.dispose(),this.needsUpdate=!0;let{data:t,width:e,height:n}=this.image;for(let i=0;i{Uv.setFromSpherical(e);let o=Uv.y*.5+.5;s.lerpColors(this.bottomColor,this.topColor,o**this.exponent)}}copy(t){return super.copy(t),this.topColor.copy(t.topColor),this.bottomColor.copy(t.bottomColor),this}};var Fh=class extends Ue{get map(){return this.uniforms.map.value}set map(t){this.uniforms.map.value=t}get opacity(){return this.uniforms.opacity.value}set opacity(t){this.uniforms&&(this.uniforms.opacity.value=t)}constructor(t){super({uniforms:{map:{value:null},opacity:{value:1}},vertexShader:` + varying vec2 vUv; + void main() { + + vUv = uv; + gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); + + } + `,fragmentShader:` + uniform sampler2D map; + uniform float opacity; + varying vec2 vUv; + + vec4 clampedTexelFatch( sampler2D map, ivec2 px, int lod ) { + + vec4 res = texelFetch( map, ivec2( px.x, px.y ), 0 ); + + #if defined( TONE_MAPPING ) + + res.xyz = toneMapping( res.xyz ); + + #endif + + return linearToOutputTexel( res ); + + } + + void main() { + + vec2 size = vec2( textureSize( map, 0 ) ); + vec2 pxUv = vUv * size; + vec2 pxCurr = floor( pxUv ); + vec2 pxFrac = fract( pxUv ) - 0.5; + vec2 pxOffset; + pxOffset.x = pxFrac.x > 0.0 ? 1.0 : - 1.0; + pxOffset.y = pxFrac.y > 0.0 ? 1.0 : - 1.0; + + vec2 pxNext = clamp( pxOffset + pxCurr, vec2( 0.0 ), size - 1.0 ); + vec2 alpha = abs( pxFrac ); + + vec4 p1 = mix( + clampedTexelFatch( map, ivec2( pxCurr.x, pxCurr.y ), 0 ), + clampedTexelFatch( map, ivec2( pxNext.x, pxCurr.y ), 0 ), + alpha.x + ); + + vec4 p2 = mix( + clampedTexelFatch( map, ivec2( pxCurr.x, pxNext.y ), 0 ), + clampedTexelFatch( map, ivec2( pxNext.x, pxNext.y ), 0 ), + alpha.x + ); + + gl_FragColor = mix( p1, p2, alpha.y ); + gl_FragColor.a *= opacity; + #include + + } + `}),this.setValues(t)}};var Kp=class extends Ue{constructor(){super({uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:` + varying vec2 vUv; + void main() { + + vUv = uv; + gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); + + }`,fragmentShader:` + #define ENVMAP_TYPE_CUBE_UV + + uniform samplerCube envMap; + uniform float flipEnvMap; + varying vec2 vUv; + + #include + #include + + ${Rh} + + void main() { + + vec3 rayDirection = equirectUvToDirection( vUv ); + rayDirection.x *= flipEnvMap; + gl_FragColor = textureCube( envMap, rayDirection ); + + }`}),this.depthWrite=!1,this.depthTest=!1}},Ua=class{constructor(t){this._renderer=t,this._quad=new Fn(new Kp)}generate(t,e=null,n=null){if(!t.isCubeTexture)throw new Error("CubeToEquirectMaterial: Source can only be cube textures.");let i=t.images[0],s=this._renderer,o=this._quad;e===null&&(e=4*i.height),n===null&&(n=2*i.height);let a=new ze(e,n,{type:$t,colorSpace:i.colorSpace}),c=i.height,l=Math.log2(c)-2,f=1/c,h=1/(3*Math.max(Math.pow(2,l),112));o.material.defines.CUBEUV_MAX_MIP=`${l}.0`,o.material.defines.CUBEUV_TEXEL_WIDTH=h,o.material.defines.CUBEUV_TEXEL_HEIGHT=f,o.material.uniforms.envMap.value=t,o.material.uniforms.flipEnvMap.value=t.isRenderTargetTexture?1:-1,o.material.needsUpdate=!0;let u=s.getRenderTarget(),d=s.autoClear;s.autoClear=!0,s.setRenderTarget(a),o.render(s),s.setRenderTarget(u),s.autoClear=d;let g=new Uint16Array(e*n*4),x=new Float32Array(e*n*4);s.readRenderTargetPixels(a,0,0,e,n,x),a.dispose();for(let m=0,v=x.length;m{this._renderer.render(e,n)},this.renderToCanvasCallback=(e,n,i)=>{let s=n.autoClear;n.autoClear=!1,i.render(n),n.autoClear=s},this.setScene(new ws,new Re)}setBVHWorker(t){this._generator.setBVHWorker(t)}setScene(t,e,n={}){t.updateMatrixWorld(!0),e.updateMatrixWorld();let i=this._generator;if(i.setObjects(t),this._buildAsync)return i.generateAsync(n.onProgress).then(s=>this._updateFromResults(t,e,s));{let s=i.generate();return this._updateFromResults(t,e,s)}}setSceneAsync(...t){this._buildAsync=!0;let e=this.setScene(...t);return this._buildAsync=!1,e}setCamera(t){this.camera=t,this.updateCamera()}updateCamera(){let t=this.camera;t.updateMatrixWorld(),this._pathTracer.setCamera(t),this._lowResPathTracer.setCamera(t),this.reset()}updateMaterials(){let t=this._pathTracer.material,e=this._renderer,n=this._materials,i=this.textureSize,s=iv(n);t.textures.setTextures(e,s,i.x,i.y),t.materials.updateFrom(n,s),this.reset()}updateLights(){let t=this.scene,e=this._renderer,n=this._pathTracer.material,i=rv(t),s=nv(i);n.lights.updateFrom(i,s),n.iesProfiles.setTextures(e,s),this.reset()}updateEnvironment(){let t=this.scene,e=this._pathTracer.material;if(this._internalBackground&&(this._internalBackground.dispose(),this._internalBackground=null),e.backgroundBlur=t.backgroundBlurriness,e.backgroundIntensity=t.backgroundIntensity??1,e.backgroundRotation.makeRotationFromEuler(t.backgroundRotation).invert(),t.background===null)e.backgroundMap=null,e.backgroundAlpha=0;else if(t.background.isColor){this._colorBackground=this._colorBackground||new Na(16);let n=this._colorBackground;n.topColor.equals(t.background)||(n.topColor.set(t.background),n.bottomColor.set(t.background),n.update()),e.backgroundMap=n,e.backgroundAlpha=1}else if(t.background.isCubeTexture){if(t.background!==this._previousBackground){let n=new Ua(this._renderer).generate(t.background);this._internalBackground=n,e.backgroundMap=n,e.backgroundAlpha=1}}else e.backgroundMap=t.background,e.backgroundAlpha=1;if(e.environmentIntensity=t.environment!==null?t.environmentIntensity??1:0,e.environmentRotation.makeRotationFromEuler(t.environmentRotation).invert(),this._previousEnvironment!==t.environment&&t.environment!==null)if(t.environment.isCubeTexture){let n=new Ua(this._renderer).generate(t.environment);e.envMapInfo.updateFrom(n)}else e.envMapInfo.updateFrom(t.environment);this._previousEnvironment=t.environment,this._previousBackground=t.background,this.reset()}_updateFromResults(t,e,n){let{materials:i,geometry:s,bvh:o,bvhChanged:a,needsMaterialIndexUpdate:c}=n;this._materials=i;let f=this._pathTracer.material;return a&&(f.bvh.updateFrom(o),f.attributesArray.updateFrom(s.attributes.normal,s.attributes.tangent,s.attributes.uv,s.attributes.color)),c&&f.materialIndexAttribute.updateFrom(s.attributes.materialIndex),this._previousScene=t,this.scene=t,this.camera=e,this.updateCamera(),this.updateMaterials(),this.updateEnvironment(),this.updateLights(),n}renderSample(){let t=this._lowResPathTracer,e=this._pathTracer,n=this._renderer,i=this._clock,s=this._quad;this._updateScale(),this._queueReset&&(e.reset(),t.reset(),this._queueReset=!1,s.material.opacity=0,i.start());let o=i.getDelta()*1e3,a=i.getElapsedTime()*1e3;if(!this.pausePathTracing&&this.enablePathTracing&&this.renderDelay<=a&&!this.isCompiling&&e.update(),e.alpha=e.material.backgroundAlpha!==1||!t1(n),t.alpha=e.alpha,this.renderToCanvas){let c=this._renderer,l=this.minSamples;if(a>=this.renderDelay&&this.samples>=this.minSamples&&(this.fadeDuration!==0?s.material.opacity=Math.min(s.material.opacity+o/this.fadeDuration,1):s.material.opacity=1),!this.enablePathTracing||this.samples0&&(s.material.opacity<1&&(s.material.blending=this.dynamicLowRes?la:Yn),s.material.map=e.target.texture,this.renderToCanvasCallback(e.target,c,s),s.material.blending=ke)}}reset(){this._queueReset=!0,this._pathTracer.samples=0}dispose(){this._quad.dispose(),this._quad.material.dispose(),this._pathTracer.dispose()}_updateScale(){if(this.synchronizeRenderSize){this._renderer.getDrawingBufferSize(oo);let t=Math.floor(this.renderScale*oo.x),e=Math.floor(this.renderScale*oo.y);if(this._pathTracer.getSize(oo),oo.x!==t||oo.y!==e){let n=this.lowResScale;this._pathTracer.setSize(t,e),this._lowResPathTracer.setSize(Math.floor(t*n),Math.floor(e*n))}}}};var jp=class extends Ds{constructor(...t){super(...t),this.iesMap=null,this.radius=0}copy(t,e){return super.copy(t,e),this.iesMap=t.iesMap,this.radius=t.radius,this}};var tm=class extends Fs{constructor(...t){super(...t),this.isCircular=!1}copy(t,e){return super.copy(t,e),this.isCircular=t.isCircular,this}};var em=class extends li{constructor(t){super({blending:ke,transparent:!1,depthWrite:!1,depthTest:!1,defines:{USE_SLIDER:0},uniforms:{sigma:{value:5},threshold:{value:.03},kSigma:{value:1},map:{value:null},opacity:{value:1}},vertexShader:` + + varying vec2 vUv; + + void main() { + + vUv = uv; + gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); + + } + + `,fragmentShader:` + + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Copyright (c) 2018-2019 Michele Morrone + // All rights reserved. + // + // https://michelemorrone.eu - https://BrutPitt.com + // + // me@michelemorrone.eu - brutpitt@gmail.com + // twitter: @BrutPitt - github: BrutPitt + // + // https://github.com/BrutPitt/glslSmartDeNoise/ + // + // This software is distributed under the terms of the BSD 2-Clause license + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + uniform sampler2D map; + + uniform float sigma; + uniform float threshold; + uniform float kSigma; + uniform float opacity; + + varying vec2 vUv; + + #define INV_SQRT_OF_2PI 0.39894228040143267793994605993439 + #define INV_PI 0.31830988618379067153776752674503 + + // Parameters: + // sampler2D tex - sampler image / texture + // vec2 uv - actual fragment coord + // float sigma > 0 - sigma Standard Deviation + // float kSigma >= 0 - sigma coefficient + // kSigma * sigma --> radius of the circular kernel + // float threshold - edge sharpening threshold + vec4 smartDeNoise( sampler2D tex, vec2 uv, float sigma, float kSigma, float threshold ) { + + float radius = round( kSigma * sigma ); + float radQ = radius * radius; + + float invSigmaQx2 = 0.5 / ( sigma * sigma ); + float invSigmaQx2PI = INV_PI * invSigmaQx2; + + float invThresholdSqx2 = 0.5 / ( threshold * threshold ); + float invThresholdSqrt2PI = INV_SQRT_OF_2PI / threshold; + + vec4 centrPx = texture2D( tex, uv ); + centrPx.rgb *= centrPx.a; + + float zBuff = 0.0; + vec4 aBuff = vec4( 0.0 ); + vec2 size = vec2( textureSize( tex, 0 ) ); + + vec2 d; + for ( d.x = - radius; d.x <= radius; d.x ++ ) { + + float pt = sqrt( radQ - d.x * d.x ); + + for ( d.y = - pt; d.y <= pt; d.y ++ ) { + + float blurFactor = exp( - dot( d, d ) * invSigmaQx2 ) * invSigmaQx2PI; + + vec4 walkPx = texture2D( tex, uv + d / size ); + walkPx.rgb *= walkPx.a; + + vec4 dC = walkPx - centrPx; + float deltaFactor = exp( - dot( dC.rgba, dC.rgba ) * invThresholdSqx2 ) * invThresholdSqrt2PI * blurFactor; + + zBuff += deltaFactor; + aBuff += deltaFactor * walkPx; + + } + + } + + return aBuff / zBuff; + + } + + void main() { + + gl_FragColor = smartDeNoise( map, vec2( vUv.x, vUv.y ), sigma, kSigma, threshold ); + #include + #include + #include + + gl_FragColor.a *= opacity; + + } + + `}),this.setValues(t)}};export{Vg as ACESFilmicToneMapping,Ni as AddEquation,Bg as AddOperation,Wd as AdditiveAnimationBlendMode,la as AdditiveBlending,Gg as AgXToneMapping,Hd as AlphaFormat,r0 as AlwaysCompare,kl as AlwaysDepth,Sf as AlwaysStencilFunc,Cl as AmbientLight,Ol as AnimationAction,Ir as AnimationClip,Gf as AnimationLoader,od as AnimationMixer,sd as AnimationObjectGroup,Vf as AnimationUtils,Qc as ArcCurve,Nl as ArrayCamera,Cd as ArrowHelper,bf as AttachedBindMode,Ul as Audio,id as AudioAnalyser,oa as AudioContext,ed as AudioListener,jf as AudioLoader,Id as AxesHelper,He as BackSide,Zg as BasicDepthPacking,$v as BasicShadowMap,Hc as BatchedMesh,Uo as Bone,yi as BooleanKeyframeTrack,xd as Box2,se as Box3,Ed as Box3Helper,Sr as BoxGeometry,Ad as BoxHelper,Ot as BufferAttribute,Ft as BufferGeometry,Ll as BufferGeometryLoader,Bs as ByteType,ni as Cache,Ms as Camera,wd as CameraHelper,Uf as CanvasTexture,$c as CapsuleGeometry,jc as CatmullRomCurve3,kg as CineonToneMapping,Zc as CircleGeometry,we as ClampToEdgeWrapping,Ls as Clock,ft as Color,na as ColorKeyframeTrack,ie as ColorManagement,Lf as CompressedArrayTexture,Nf as CompressedCubeTexture,Es as CompressedTexture,Wf as CompressedTextureLoader,Vo as ConeGeometry,Lg as ConstantAlphaFactor,Dg as ConstantColorFactor,Dd as Controls,Dc as CubeCamera,Si as CubeReflectionMapping,Vi as CubeRefractionMapping,Mr as CubeTexture,Xf as CubeTextureLoader,Ns as CubeUVReflectionMapping,Ho as CubicBezierCurve,tl as CubicBezierCurve3,Ml as CubicInterpolant,Ld as CullFaceBack,gg as CullFaceFront,Yv as CullFaceFrontBack,mg as CullFaceNone,Pn as Curve,il as CurvePath,vg as CustomBlending,Hg as CustomToneMapping,ko as CylinderGeometry,md as Cylindrical,bs as Data3DTexture,Ui as DataArrayTexture,oe as DataTexture,qf as DataTextureLoader,fn as DataUtils,a_ as DecrementStencilOp,l_ as DecrementWrapStencilOp,g0 as DefaultLoadingManager,em as DenoiseMaterial,xs as DepthFormat,zs as DepthStencilFormat,Oo as DepthTexture,Xg as DetachedBindMode,Rl as DirectionalLight,Td as DirectionalLightHelper,Tl as DiscreteInterpolant,Jc as DodecahedronGeometry,Sn as DoubleSide,Eg as DstAlphaFactor,Cg as DstColorFactor,T_ as DynamicCopyUsage,v_ as DynamicDrawUsage,b_ as DynamicReadUsage,Kc as EdgesGeometry,Rs as EllipseCurve,t0 as EqualCompare,Hl as EqualDepth,d_ as EqualStencilFunc,Mi as EquirectangularReflectionMapping,ha as EquirectangularRefractionMapping,In as Euler,On as EventDispatcher,zo as ExternalTexture,rl as ExtrudeGeometry,$n as FileLoader,Cf as Float16BufferAttribute,bt as Float32BufferAttribute,$t as FloatType,Nc as Fog,Lc as FogExp2,Ff as FramebufferTexture,yn as FrontSide,Oi as Frustum,Vc as FrustumArray,hd as GLBufferAttribute,A_ as GLSL1,qd as GLSL3,Na as GradientEquirectTexture,e0 as GreaterCompare,Wl as GreaterDepth,i0 as GreaterEqualCompare,Gl as GreaterEqualDepth,x_ as GreaterEqualStencilFunc,m_ as GreaterStencilFunc,Sd as GridHelper,Li as Group,Ge as HalfFloatType,Al as HemisphereLight,bd as HemisphereLightHelper,sl as IcosahedronGeometry,Qf as ImageBitmapLoader,Pr as ImageLoader,Pc as ImageUtils,o_ as IncrementStencilOp,c_ as IncrementWrapStencilOp,Bi as InstancedBufferAttribute,Fl as InstancedBufferGeometry,ud as InstancedInterleavedBuffer,kc as InstancedMesh,Ef as Int16BufferAttribute,Rf as Int32BufferAttribute,Tf as Int8BufferAttribute,Gi as IntType,As as InterleavedBuffer,Tr as InterleavedBufferAttribute,Ar as Interpolant,Eo as InterpolateDiscrete,Ic as InterpolateLinear,Ec as InterpolateSmooth,C_ as InterpolationSamplingMode,R_ as InterpolationSamplingType,u_ as InvertStencilOp,pr as KeepStencilOp,bn as KeyframeTrack,Bc as LOD,ol as LatheGeometry,Ss as Layers,jg as LessCompare,Vl as LessDepth,Xd as LessEqualCompare,_r as LessEqualDepth,p_ as LessEqualStencilFunc,f_ as LessStencilFunc,si as Light,Pl as LightProbe,ri as Line,dn as Line3,Qe as LineBasicMaterial,Go as LineCurve,el as LineCurve3,Sl as LineDashedMaterial,Xc as LineLoop,kn as LineSegments,re as LinearFilter,ea as LinearInterpolant,zd as LinearMipMapLinearFilter,Kv as LinearMipMapNearestFilter,ai as LinearMipmapLinearFilter,fa as LinearMipmapNearestFilter,yr as LinearSRGBColorSpace,Og as LinearToneMapping,Co as LinearTransfer,sn as Loader,sa as LoaderUtils,ia as LoadingManager,qg as LoopOnce,$g as LoopPingPong,Yg as LoopRepeat,Xv as MOUSE,Je as Material,Dl as MaterialLoader,q_ as MathUtils,gd as Matrix2,Xt as Matrix3,gt as Matrix4,Sg as MaxEquation,Me as Mesh,zn as MeshBasicMaterial,jo as MeshDepthMaterial,ta as MeshDistanceMaterial,yl as MeshLambertMaterial,bl as MeshMatcapMaterial,_l as MeshNormalMaterial,xl as MeshPhongMaterial,gl as MeshPhysicalMaterial,Qo as MeshStandardMaterial,vl as MeshToonMaterial,bg as MinEquation,Ao as MirroredRepeatWrapping,Ug as MixOperation,Bd as MultiplyBlending,ua as MultiplyOperation,Vt as NearestFilter,Jv as NearestMipMapLinearFilter,Zv as NearestMipMapNearestFilter,Us as NearestMipmapLinearFilter,Od as NearestMipmapNearestFilter,Wg as NeutralToneMapping,Qg as NeverCompare,zl as NeverDepth,h_ as NeverStencilFunc,ke as NoBlending,Ti as NoColorSpace,Zn as NoToneMapping,Mu as NormalAnimationBlendMode,Yn as NormalBlending,n0 as NotEqualCompare,Xl as NotEqualDepth,g_ as NotEqualStencilFunc,Er as NumberKeyframeTrack,ue as Object3D,Kf as ObjectLoader,Kg as ObjectSpaceNormalMap,Jo as OctahedronGeometry,Tg as OneFactor,Ng as OneMinusConstantAlphaFactor,Fg as OneMinusConstantColorFactor,Rg as OneMinusDstAlphaFactor,Ig as OneMinusDstColorFactor,Cc as OneMinusSrcAlphaFactor,Ag as OneMinusSrcColorFactor,ki as OrthographicCamera,Nd as PCFShadowMap,xg as PCFSoftShadowMap,Ru as PMREMGenerator,Cs as Path,Re as PerspectiveCamera,Pa as PhysicalCamera,jp as PhysicalSpotLight,_n as Plane,Ps as PlaneGeometry,Rd as PlaneHelper,El as PointLight,yd as PointLightHelper,qc as Points,Bo as PointsMaterial,Md as PolarGridHelper,zi as PolyhedronGeometry,nd as PositionalAudio,pe as PropertyBinding,Bl as PropertyMixer,Wo as QuadraticBezierCurve,Xo as QuadraticBezierCurve3,Ze as Quaternion,Rr as QuaternionKeyframeTrack,wl as QuaternionLinearInterpolant,bu as RED_GREEN_RGTC2_Format,_u as RED_RGTC1_Format,ca as REVISION,Jg as RGBADepthPacking,Gt as RGBAFormat,Xi as RGBAIntegerFormat,du as RGBA_ASTC_10x10_Format,uu as RGBA_ASTC_10x5_Format,hu as RGBA_ASTC_10x6_Format,fu as RGBA_ASTC_10x8_Format,pu as RGBA_ASTC_12x10_Format,mu as RGBA_ASTC_12x12_Format,nu as RGBA_ASTC_4x4_Format,iu as RGBA_ASTC_5x4_Format,ru as RGBA_ASTC_5x5_Format,su as RGBA_ASTC_6x5_Format,ou as RGBA_ASTC_6x6_Format,au as RGBA_ASTC_8x5_Format,cu as RGBA_ASTC_8x6_Format,lu as RGBA_ASTC_8x8_Format,gu as RGBA_BPTC_Format,eu as RGBA_ETC2_EAC_Format,Ql as RGBA_PVRTC_2BPPV1_Format,Kl as RGBA_PVRTC_4BPPV1_Format,ma as RGBA_S3TC_DXT1_Format,ga as RGBA_S3TC_DXT3_Format,xa as RGBA_S3TC_DXT5_Format,n_ as RGBDepthPacking,Gd as RGBFormat,Qv as RGBIntegerFormat,xu as RGB_BPTC_SIGNED_Format,vu as RGB_BPTC_UNSIGNED_Format,jl as RGB_ETC1_Format,tu as RGB_ETC2_Format,Jl as RGB_PVRTC_2BPPV1_Format,Zl as RGB_PVRTC_4BPPV1_Format,pa as RGB_S3TC_DXT1_Format,i_ as RGDepthPacking,Fr as RGFormat,Wi as RGIntegerFormat,ml as RawShaderMaterial,ii as Ray,fd as Raycaster,Fs as RectAreaLight,Jn as RedFormat,Dr as RedIntegerFormat,zg as ReinhardToneMapping,Po as RenderTarget,ad as RenderTarget3D,Ke as RepeatWrapping,s_ as ReplaceStencilOp,yg as ReverseSubtractEquation,al as RingGeometry,Su as SIGNED_RED_GREEN_RGTC2_Format,yu as SIGNED_RED_RGTC1_Format,vn as SRGBColorSpace,me as SRGBTransfer,ws as Scene,jt as ShaderChunk,ci as ShaderLib,Ue as ShaderMaterial,pl as ShadowMaterial,_i as Shape,cl as ShapeGeometry,Pd as ShapePath,qn as ShapeUtils,tm as ShapedAreaLight,da as ShortType,zc as Skeleton,_d as SkeletonHelper,Oc as SkinnedMesh,Bn as Source,Ve as Sphere,Ko as SphereGeometry,aa as Spherical,Il as SphericalHarmonics3,qo as SplineCurve,Ds as SpotLight,vd as SpotLightHelper,Uc as Sprite,No as SpriteMaterial,Rc as SrcAlphaFactor,Pg as SrcAlphaSaturateFactor,wg as SrcColorFactor,M_ as StaticCopyUsage,Io as StaticDrawUsage,y_ as StaticReadUsage,td as StereoCamera,w_ as StreamCopyUsage,__ as StreamDrawUsage,S_ as StreamReadUsage,bi as StringKeyframeTrack,_g as SubtractEquation,Ud as SubtractiveBlending,qv as TOUCH,qi as TangentSpaceNormalMap,ll as TetrahedronGeometry,Oe as Texture,Yf as TextureLoader,Fd as TextureUtils,pd as Timer,E_ as TimestampQuery,ul as TorusGeometry,hl as TorusKnotGeometry,$e as Triangle,e_ as TriangleFanDrawMode,t_ as TriangleStripDrawMode,jv as TrianglesDrawMode,fl as TubeGeometry,ql as UVMapping,Fo as Uint16BufferAttribute,Lo as Uint32BufferAttribute,wf as Uint8BufferAttribute,Af as Uint8ClampedBufferAttribute,cd as Uniform,ld as UniformsGroup,mt as UniformsLib,c0 as UniformsUtils,on as UnsignedByteType,Vd as UnsignedInt101111Type,Os as UnsignedInt248Type,kd as UnsignedInt5999Type,an as UnsignedIntType,Yl as UnsignedShort4444Type,$l as UnsignedShort5551Type,Hi as UnsignedShortType,oi as VSMShadowMap,q as Vector2,R as Vector3,Kt as Vector4,Cr as VectorKeyframeTrack,Df as VideoFrameTexture,Yc as VideoTexture,Mf as WebGL3DRenderTarget,Do as WebGLArrayRenderTarget,Rn as WebGLCoordinateSystem,Fc as WebGLCubeRenderTarget,Qp as WebGLPathTracer,ze as WebGLRenderTarget,V0 as WebGLRenderer,Xw as WebGLUtils,vs as WebGPUCoordinateSystem,Ts as WebXRController,dl as WireframeGeometry,Ro as WrapAroundEnding,mr as ZeroCurvatureEnding,Mg as ZeroFactor,gr as ZeroSlopeEnding,r_ as ZeroStencilOp,s0 as createCanvasElement}; +/*! Bundled license information: + +three/build/three.core.js: +three/build/three.module.js: + (** + * @license + * Copyright 2010-2025 Three.js Authors + * SPDX-License-Identifier: MIT + *) +*/ diff --git a/registry/examples/path-traced-3d/assets/vendor/three.LICENSE.txt b/registry/examples/path-traced-3d/assets/vendor/three.LICENSE.txt new file mode 100644 index 0000000000..cf78143040 --- /dev/null +++ b/registry/examples/path-traced-3d/assets/vendor/three.LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License + +Copyright © 2010-2025 three.js authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/registry/examples/path-traced-3d/index.html b/registry/examples/path-traced-3d/index.html new file mode 100644 index 0000000000..262e992c1c --- /dev/null +++ b/registry/examples/path-traced-3d/index.html @@ -0,0 +1,57 @@ + + + + + + Path-traced 3D - HyperFrames + + + +
+ +
+ + + diff --git a/registry/examples/path-traced-3d/registry-item.json b/registry/examples/path-traced-3d/registry-item.json new file mode 100644 index 0000000000..09c8220663 --- /dev/null +++ b/registry/examples/path-traced-3d/registry-item.json @@ -0,0 +1,55 @@ +{ + "$schema": "https://hyperframes.heygen.com/schema/registry-item.json", + "name": "path-traced-3d", + "type": "hyperframes:example", + "title": "Path-Traced 3D", + "description": "Three.js scene with a fast raster preview and an opt-in path-traced export", + "tags": ["3d", "three-js", "path-tracing", "webgl"], + "dimensions": { + "width": 1920, + "height": 1080 + }, + "duration": 6, + "files": [ + { + "path": "assets/render.js", + "target": "assets/render.js", + "type": "hyperframes:asset" + }, + { + "path": "assets/scene.js", + "target": "assets/scene.js", + "type": "hyperframes:asset" + }, + { + "path": "assets/vendor/README.md", + "target": "assets/vendor/README.md", + "type": "hyperframes:asset" + }, + { + "path": "assets/vendor/three-gpu-pathtracer.LICENSE.txt", + "target": "assets/vendor/three-gpu-pathtracer.LICENSE.txt", + "type": "hyperframes:asset" + }, + { + "path": "assets/vendor/three-mesh-bvh.LICENSE.txt", + "target": "assets/vendor/three-mesh-bvh.LICENSE.txt", + "type": "hyperframes:asset" + }, + { + "path": "assets/vendor/three-path-tracer.min.js", + "target": "assets/vendor/three-path-tracer.min.js", + "type": "hyperframes:asset" + }, + { + "path": "assets/vendor/three.LICENSE.txt", + "target": "assets/vendor/three.LICENSE.txt", + "type": "hyperframes:asset" + }, + { + "path": "index.html", + "target": "index.html", + "type": "hyperframes:composition" + } + ] +} diff --git a/registry/examples/path-traced-3d/source/README.md b/registry/examples/path-traced-3d/source/README.md new file mode 100644 index 0000000000..e533fca8a8 --- /dev/null +++ b/registry/examples/path-traced-3d/source/README.md @@ -0,0 +1,42 @@ +# Source for the path-traced-3d example + +These files stay in the repository; `hyperframes init --example path-traced-3d` installs only the +files listed in `../registry-item.json`. + +## Rebuild the vendored bundle + +`build.mjs` bundles `vendor-entry.js` with the versions pinned in `package.json` and +`package-lock.json` into `../assets/vendor/three-path-tracer.min.js`, and copies the three +licence files beside it. + +```sh +npm ci +npm run build +``` + +Update the versions and the SHA-256 in `../assets/vendor/README.md` when they change. + +## Check what reaches the pixels + +`verify-render.mjs` copies the example to a temporary folder at 320x180, then uses the +HyperFrames CLI and ffmpeg to check, in raster and in path mode (2 samples per pixel): + +- `hyperframes check` passes in path mode, so setup (including the first, slowest tracing run) + resolves its `buildReady` promise; +- stills taken at 4 s, 0 s, then 4 s again in one page are byte-identical at 4 s, differ from + 0 s, and are not blank; +- a new page draws the same 4 s still (no grain that changes per page load); +- path mode draws different pixels from raster mode; +- every frame of an exported MP4 (raster: 1 s at 30 fps; path: 0.8 s at 10 fps on two workers) + is not blank, the clip moves, and no step between neighbouring frames is more than 3x the + typical step. + +```sh +node verify-render.mjs +# or, from a HyperFrames checkout, with the CLI built from source: +HYPERFRAMES_CLI=packages/cli/bin/hyperframes.mjs node registry/examples/path-traced-3d/source/verify-render.mjs +``` + +Every command gets a 170 s readiness wait, because on a software GPU the tracer's first shader +run takes about a minute. It prints a JSON report with the wall time of every step. Set `KEEP_VERIFY_OUTPUT=1` to keep the +renders. `path-traced-3d.test.mjs` is the fast check that runs with the repository's script tests. diff --git a/registry/examples/path-traced-3d/source/build.mjs b/registry/examples/path-traced-3d/source/build.mjs new file mode 100644 index 0000000000..df6a219675 --- /dev/null +++ b/registry/examples/path-traced-3d/source/build.mjs @@ -0,0 +1,23 @@ +// Rebuilds ../assets/vendor/three-path-tracer.min.js and its licence files from the versions +// pinned in package.json and package-lock.json. Run `npm ci && npm run build` in this folder. +import { build } from "esbuild"; +import { copyFile } from "node:fs/promises"; + +const out = new URL("../assets/vendor/", import.meta.url); + +await build({ + entryPoints: [new URL("vendor-entry.js", import.meta.url).pathname], + bundle: true, + format: "esm", + minify: true, + target: "es2020", + outfile: new URL("three-path-tracer.min.js", out).pathname, +}); + +for (const pkg of ["three", "three-gpu-pathtracer", "three-mesh-bvh"]) { + await copyFile( + new URL(`node_modules/${pkg}/LICENSE`, import.meta.url), + new URL(`${pkg}.LICENSE.txt`, out), + ); +} +console.log("built assets/vendor/three-path-tracer.min.js"); diff --git a/registry/examples/path-traced-3d/source/package-lock.json b/registry/examples/path-traced-3d/source/package-lock.json new file mode 100644 index 0000000000..a0205d3899 --- /dev/null +++ b/registry/examples/path-traced-3d/source/package-lock.json @@ -0,0 +1,537 @@ +{ + "name": "path-traced-3d-vendor", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "path-traced-3d-vendor", + "devDependencies": { + "esbuild": "0.25.12", + "three": "0.180.0", + "three-gpu-pathtracer": "0.0.24", + "three-mesh-bvh": "0.9.5" + } + }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.12.tgz", + "integrity": "sha512-Hhmwd6CInZ3dwpuGTF8fJG6yoWmsToE+vYgD4nytZVxcu1ulHpUQRAB1UJ8+N1Am3Mz4+xOByoQoSZf4D+CpkA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.25.12.tgz", + "integrity": "sha512-VJ+sKvNA/GE7Ccacc9Cha7bpS8nyzVv0jdVgwNDaR4gDMC/2TTRc33Ip8qrNYUcpkOHUT5OZ0bUcNNVZQ9RLlg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.25.12.tgz", + "integrity": "sha512-6AAmLG7zwD1Z159jCKPvAxZd4y/VTO0VkprYy+3N2FtJ8+BQWFXU+OxARIwA46c5tdD9SsKGZ/1ocqBS/gAKHg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.25.12.tgz", + "integrity": "sha512-5jbb+2hhDHx5phYR2By8GTWEzn6I9UqR11Kwf22iKbNpYrsmRB18aX/9ivc5cabcUiAT/wM+YIZ6SG9QO6a8kg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.25.12.tgz", + "integrity": "sha512-N3zl+lxHCifgIlcMUP5016ESkeQjLj/959RxxNYIthIg+CQHInujFuXeWbWMgnTo4cp5XVHqFPmpyu9J65C1Yg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.25.12.tgz", + "integrity": "sha512-HQ9ka4Kx21qHXwtlTUVbKJOAnmG1ipXhdWTmNXiPzPfWKpXqASVcWdnf2bnL73wgjNrFXAa3yYvBSd9pzfEIpA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.25.12.tgz", + "integrity": "sha512-gA0Bx759+7Jve03K1S0vkOu5Lg/85dou3EseOGUes8flVOGxbhDDh/iZaoek11Y8mtyKPGF3vP8XhnkDEAmzeg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.25.12.tgz", + "integrity": "sha512-TGbO26Yw2xsHzxtbVFGEXBFH0FRAP7gtcPE7P5yP7wGy7cXK2oO7RyOhL5NLiqTlBh47XhmIUXuGciXEqYFfBQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.25.12.tgz", + "integrity": "sha512-lPDGyC1JPDou8kGcywY0YILzWlhhnRjdof3UlcoqYmS9El818LLfJJc3PXXgZHrHCAKs/Z2SeZtDJr5MrkxtOw==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.25.12.tgz", + "integrity": "sha512-8bwX7a8FghIgrupcxb4aUmYDLp8pX06rGh5HqDT7bB+8Rdells6mHvrFHHW2JAOPZUbnjUpKTLg6ECyzvas2AQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.25.12.tgz", + "integrity": "sha512-0y9KrdVnbMM2/vG8KfU0byhUN+EFCny9+8g202gYqSSVMonbsCfLjUO+rCci7pM0WBEtz+oK/PIwHkzxkyharA==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.25.12.tgz", + "integrity": "sha512-h///Lr5a9rib/v1GGqXVGzjL4TMvVTv+s1DPoxQdz7l/AYv6LDSxdIwzxkrPW438oUXiDtwM10o9PmwS/6Z0Ng==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.25.12.tgz", + "integrity": "sha512-iyRrM1Pzy9GFMDLsXn1iHUm18nhKnNMWscjmp4+hpafcZjrr2WbT//d20xaGljXDBYHqRcl8HnxbX6uaA/eGVw==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.25.12.tgz", + "integrity": "sha512-9meM/lRXxMi5PSUqEXRCtVjEZBGwB7P/D4yT8UG/mwIdze2aV4Vo6U5gD3+RsoHXKkHCfSxZKzmDssVlRj1QQA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.25.12.tgz", + "integrity": "sha512-Zr7KR4hgKUpWAwb1f3o5ygT04MzqVrGEGXGLnj15YQDJErYu/BGg+wmFlIDOdJp0PmB0lLvxFIOXZgFRrdjR0w==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.25.12.tgz", + "integrity": "sha512-MsKncOcgTNvdtiISc/jZs/Zf8d0cl/t3gYWX8J9ubBnVOwlk65UIEEvgBORTiljloIWnBzLs4qhzPkJcitIzIg==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.25.12.tgz", + "integrity": "sha512-uqZMTLr/zR/ed4jIGnwSLkaHmPjOjJvnm6TVVitAa08SLS9Z0VM8wIRx7gWbJB5/J54YuIMInDquWyYvQLZkgw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.25.12.tgz", + "integrity": "sha512-xXwcTq4GhRM7J9A8Gv5boanHhRa/Q9KLVmcyXHCTaM4wKfIpWkdXiMog/KsnxzJ0A1+nD+zoecuzqPmCRyBGjg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.25.12.tgz", + "integrity": "sha512-Ld5pTlzPy3YwGec4OuHh1aCVCRvOXdH8DgRjfDy/oumVovmuSzWfnSJg+VtakB9Cm0gxNO9BzWkj6mtO1FMXkQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.25.12.tgz", + "integrity": "sha512-fF96T6KsBo/pkQI950FARU9apGNTSlZGsv1jZBAlcLL1MLjLNIWPBkj5NlSz8aAzYKg+eNqknrUJ24QBybeR5A==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.25.12.tgz", + "integrity": "sha512-MZyXUkZHjQxUvzK7rN8DJ3SRmrVrke8ZyRusHlP+kuwqTcfWLyqMOE3sScPPyeIXN/mDJIfGXvcMqCgYKekoQw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.25.12.tgz", + "integrity": "sha512-rm0YWsqUSRrjncSXGA7Zv78Nbnw4XL6/dzr20cyrQf7ZmRcsovpcRBdhD43Nuk3y7XIoW2OxMVvwuRvk9XdASg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.25.12.tgz", + "integrity": "sha512-3wGSCDyuTHQUzt0nV7bocDy72r2lI33QL3gkDNGkod22EsYl04sMf0qLb8luNKTOmgF/eDEDP5BFNwoBKH441w==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.25.12.tgz", + "integrity": "sha512-rMmLrur64A7+DKlnSuwqUdRKyd3UE7oPJZmnljqEptesKM8wx9J8gx5u0+9Pq0fQQW8vqeKebwNXdfOyP+8Bsg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.25.12.tgz", + "integrity": "sha512-HkqnmmBoCbCwxUKKNPBixiWDGCpQGVsrQfJoVGYLPT41XWF8lHuE5N6WhVia2n4o5QK5M4tYr21827fNhi4byQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.25.12.tgz", + "integrity": "sha512-alJC0uCZpTFrSL0CCDjcgleBXPnCrEAhTBILpeAp7M/OFgoqtAetfBzX0xM00MUsVVPpVjlPuMbREqnZCXaTnA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/esbuild": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.12.tgz", + "integrity": "sha512-bbPBYYrtZbkt6Os6FiTLCTFxvq4tt3JKall1vRwshA3fdVztsLAatFaZobhkBC8/BrPetoa0oksYoKXoG4ryJg==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.25.12", + "@esbuild/android-arm": "0.25.12", + "@esbuild/android-arm64": "0.25.12", + "@esbuild/android-x64": "0.25.12", + "@esbuild/darwin-arm64": "0.25.12", + "@esbuild/darwin-x64": "0.25.12", + "@esbuild/freebsd-arm64": "0.25.12", + "@esbuild/freebsd-x64": "0.25.12", + "@esbuild/linux-arm": "0.25.12", + "@esbuild/linux-arm64": "0.25.12", + "@esbuild/linux-ia32": "0.25.12", + "@esbuild/linux-loong64": "0.25.12", + "@esbuild/linux-mips64el": "0.25.12", + "@esbuild/linux-ppc64": "0.25.12", + "@esbuild/linux-riscv64": "0.25.12", + "@esbuild/linux-s390x": "0.25.12", + "@esbuild/linux-x64": "0.25.12", + "@esbuild/netbsd-arm64": "0.25.12", + "@esbuild/netbsd-x64": "0.25.12", + "@esbuild/openbsd-arm64": "0.25.12", + "@esbuild/openbsd-x64": "0.25.12", + "@esbuild/openharmony-arm64": "0.25.12", + "@esbuild/sunos-x64": "0.25.12", + "@esbuild/win32-arm64": "0.25.12", + "@esbuild/win32-ia32": "0.25.12", + "@esbuild/win32-x64": "0.25.12" + } + }, + "node_modules/three": { + "version": "0.180.0", + "resolved": "https://registry.npmjs.org/three/-/three-0.180.0.tgz", + "integrity": "sha512-o+qycAMZrh+TsE01GqWUxUIKR1AL0S8pq7zDkYOQw8GqfX8b8VoCKYUoHbhiX5j+7hr8XsuHDVU6+gkQJQKg9w==", + "dev": true, + "license": "MIT" + }, + "node_modules/three-gpu-pathtracer": { + "version": "0.0.24", + "resolved": "https://registry.npmjs.org/three-gpu-pathtracer/-/three-gpu-pathtracer-0.0.24.tgz", + "integrity": "sha512-fHQ7g7ywvSwRAQywhsfech2/kspQKinfFNOcNDTJS2Q34CzcF1kpESlOVvJH8kX/bGlCnxMI+Qo16kWGAy7zCA==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "three": ">=0.180.0", + "three-mesh-bvh": ">=0.7.4", + "xatlas-web": "^0.1.0" + } + }, + "node_modules/three-mesh-bvh": { + "version": "0.9.5", + "resolved": "https://registry.npmjs.org/three-mesh-bvh/-/three-mesh-bvh-0.9.5.tgz", + "integrity": "sha512-MYpwzUWDxPAKGhSBFin9E/7K4AAHyIm4IfMZQ/3+Z/jq/swa2dAhXx0yUNDd9mjlhLuzXkMBTGDZioL2GSlIfQ==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "three": ">= 0.159.0" + } + }, + "node_modules/xatlas-web": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/xatlas-web/-/xatlas-web-0.1.0.tgz", + "integrity": "sha512-PprVfuXbaIskxLTLBUQRaWfgSy9xUQqAMIRooOw0P6NYqwgh6T0voeer6+Z5M7AFt5SGXUybuww/uDGs1yw8vQ==", + "dev": true, + "license": "MIT", + "peer": true + } + } +} diff --git a/registry/examples/path-traced-3d/source/package.json b/registry/examples/path-traced-3d/source/package.json new file mode 100644 index 0000000000..848e353f22 --- /dev/null +++ b/registry/examples/path-traced-3d/source/package.json @@ -0,0 +1,14 @@ +{ + "name": "path-traced-3d-vendor", + "private": true, + "type": "module", + "scripts": { + "build": "node build.mjs" + }, + "devDependencies": { + "esbuild": "0.25.12", + "three": "0.180.0", + "three-gpu-pathtracer": "0.0.24", + "three-mesh-bvh": "0.9.5" + } +} diff --git a/registry/examples/path-traced-3d/source/path-traced-3d.test.mjs b/registry/examples/path-traced-3d/source/path-traced-3d.test.mjs new file mode 100644 index 0000000000..a075e0e3b0 --- /dev/null +++ b/registry/examples/path-traced-3d/source/path-traced-3d.test.mjs @@ -0,0 +1,81 @@ +import assert from "node:assert/strict"; +import { createHash } from "node:crypto"; +import { readdirSync, readFileSync } from "node:fs"; +import { join, relative } from "node:path"; +import test from "node:test"; +import { fileURLToPath } from "node:url"; + +const example = fileURLToPath(new URL("..", import.meta.url)); +const read = (path) => readFileSync(join(example, path), "utf8"); + +test("the manifest installs exactly the page and its assets", () => { + const item = JSON.parse(read("registry-item.json")); + const onDisk = readdirSync(join(example, "assets"), { recursive: true, withFileTypes: true }) + .filter((entry) => entry.isFile()) + .map((entry) => relative(example, join(entry.parentPath, entry.name))) + .concat("index.html") + .sort(); + assert.deepEqual(item.files.map((file) => file.path).sort(), onDisk); + for (const file of item.files) assert.equal(file.target, file.path); +}); + +test("the page loads nothing from the network and defaults to the raster preview", () => { + const html = read("index.html"); + assert.doesNotMatch(html, /]+src="https?:/); + const variables = JSON.parse(html.match(/data-composition-variables='([^']+)'/)[1]); + assert.equal(variables.find((v) => v.id === "renderer").default, "raster"); + for (const file of ["assets/render.js", "assets/scene.js"]) { + for (const match of read(file).matchAll(/from\s+"([^"]+)"/g)) { + assert.match(match[1], /^\.\//, `${file} imports ${match[1]}`); + } + } +}); + +test("the vendored bundle matches the hash its note records", () => { + const bundle = readFileSync(join(example, "assets/vendor/three-path-tracer.min.js")); + const hash = createHash("sha256").update(bundle).digest("hex"); + assert.ok(read("assets/vendor/README.md").includes(hash)); + const pins = JSON.parse(read("source/package.json")).devDependencies; + assert.equal(pins.three, "0.180.0"); + assert.equal(pins["three-gpu-pathtracer"], "0.0.24"); + assert.equal(pins["three-mesh-bvh"], "0.9.5"); +}); + +test("rendering never waits on frames or the clock", () => { + const source = read("assets/render.js").replace(/^\s*\/\/.*$/gm, ""); + for (const banned of [ + "requestAnimationFrame", + "setAnimationLoop", + "performance.now", + "Date.now", + "scheduler.yield", + "compileAsync =", + "setTimeout", + "setInterval", + ]) { + assert.ok(!source.includes(banned), `render.js uses ${banned}`); + } + assert.match(source, /tracer\.renderDelay = 0;/); + assert.match(source, /tracer\.stableNoise = true;/); + assert.match(source, /window\.__hf\.buildReady\[READY_KEY\] = ready;/); + assert.match(source, /event\.detail\.waitUntil\(queue\);/); +}); + +test("a pose depends only on its time, whatever was posed before", async () => { + const THREE = await import(new URL("../assets/vendor/three-path-tracer.min.js", import.meta.url)); + const { createScene } = await import(new URL("../assets/scene.js", import.meta.url)); + const { scene, camera, poseAt } = createScene(THREE, { aspect: 16 / 9 }); + const snapshot = () => [ + ...camera.matrixWorld.elements, + ...scene.children.flatMap((object) => object.matrixWorld.elements), + ]; + + poseAt(4); + const atFour = snapshot(); + poseAt(0); + const atZero = snapshot(); + poseAt(2.5); + poseAt(4); + assert.deepEqual(snapshot(), atFour); + assert.notDeepEqual(atZero, atFour); +}); diff --git a/registry/examples/path-traced-3d/source/vendor-entry.js b/registry/examples/path-traced-3d/source/vendor-entry.js new file mode 100644 index 0000000000..9e39c9a785 --- /dev/null +++ b/registry/examples/path-traced-3d/source/vendor-entry.js @@ -0,0 +1,10 @@ +// Everything the starter imports, as one local ES module: all of three plus the tracer classes. +export * from "three"; +export { + DenoiseMaterial, + GradientEquirectTexture, + PhysicalCamera, + PhysicalSpotLight, + ShapedAreaLight, + WebGLPathTracer, +} from "three-gpu-pathtracer"; diff --git a/registry/examples/path-traced-3d/source/verify-render.mjs b/registry/examples/path-traced-3d/source/verify-render.mjs new file mode 100644 index 0000000000..d576a1038f --- /dev/null +++ b/registry/examples/path-traced-3d/source/verify-render.mjs @@ -0,0 +1,211 @@ +#!/usr/bin/env node +// Renders the starter at 320x180 in both modes and checks the pixels that come out: +// - out-of-order seeks (4 s, 0 s, 4 s) give byte-identical PNGs for the same time; +// - a second page load draws the same 4 s still as the first (no per-load noise); +// - exported MP4 frames are neither blank nor frozen, and no step between frames jumps +// (path mode renders with two workers, so their chunks must join seamlessly). +// Needs ffmpeg on PATH. See README.md. +// +// node verify-render.mjs # uses `npx hyperframes` +// HYPERFRAMES_CLI=path/to/hyperframes.mjs node verify-render.mjs +import { spawnSync } from "node:child_process"; +import { createHash } from "node:crypto"; +import { cpSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { fileURLToPath } from "node:url"; + +const EXAMPLE = fileURLToPath(new URL("..", import.meta.url)); +const WIDTH = 320; +const HEIGHT = 180; +const PATH_SAMPLES = 2; +// Setup includes the tracer's first shader run, which takes about a minute on a software GPU. +const READY_MS = "170000"; +const env = { ...process.env, HYPERFRAMES_NO_TELEMETRY: "1", DO_NOT_TRACK: "1" }; +const cli = process.env.HYPERFRAMES_CLI + ? [process.execPath, process.env.HYPERFRAMES_CLI] + : ["npx", "--yes", "hyperframes"]; +const scratch = mkdtempSync(join(tmpdir(), "path-traced-3d-verify-")); +const report = { size: `${WIDTH}x${HEIGHT}`, pathSamples: PATH_SAMPLES, steps: [] }; + +function fail(message) { + throw new Error(message); +} + +function replaceOnce(text, from, to) { + if (!text.includes(from)) fail(`index.html no longer contains ${from}`); + return text.replace(from, to); +} + +// A copy of the starter at a small size, with the renderer chosen through the variable defaults +// (snapshot has no --variables flag, so the defaults are what both commands read). +function makeProject(name, { renderer, duration }) { + const dir = join(scratch, name); + cpSync(join(EXAMPLE, "index.html"), join(dir, "index.html")); + cpSync(join(EXAMPLE, "assets"), join(dir, "assets"), { recursive: true }); + let html = readFileSync(join(dir, "index.html"), "utf8"); + html = html.replaceAll("1920", String(WIDTH)).replaceAll("1080", String(HEIGHT)); + html = html.replaceAll('data-duration="6"', `data-duration="${duration}"`); + html = replaceOnce(html, '"default":"raster"', `"default":"${renderer}"`); + html = replaceOnce(html, '"default":64', `"default":${PATH_SAMPLES}`); + writeFileSync(join(dir, "index.html"), html); + return dir; +} + +function run(label, args) { + const started = performance.now(); + const result = spawnSync(cli[0], [...cli.slice(1), ...args], { env, encoding: "utf8" }); + const seconds = Number(((performance.now() - started) / 1000).toFixed(1)); + report.steps.push({ step: label, wallSeconds: seconds, exit: result.status }); + if (result.status !== 0) { + fail(`${label} exited ${result.status}\n${result.stdout}\n${result.stderr}`); + } + return result.stdout; +} + +function decode(file) { + const result = spawnSync( + "ffmpeg", + ["-v", "error", "-i", file, "-f", "rawvideo", "-pix_fmt", "rgb24", "-"], + { maxBuffer: 1 << 30 }, + ); + if (result.status !== 0) fail(`ffmpeg could not decode ${file}: ${result.stderr}`); + const frameBytes = WIDTH * HEIGHT * 3; + const frames = []; + for (let at = 0; at + frameBytes <= result.stdout.length; at += frameBytes) { + frames.push(result.stdout.subarray(at, at + frameBytes)); + } + return frames; +} + +function spread(pixels) { + let sum = 0; + let squares = 0; + for (const value of pixels) { + sum += value; + squares += value * value; + } + const mean = sum / pixels.length; + return Math.sqrt(squares / pixels.length - mean * mean); +} + +function meanDifference(a, b) { + let total = 0; + for (let i = 0; i < a.length; i++) total += Math.abs(a[i] - b[i]); + return total / a.length; +} + +const sha = (buffer) => createHash("sha256").update(buffer).digest("hex").slice(0, 16); + +function checkSeekOrder(renderer) { + const dir = makeProject(`${renderer}-seek`, { renderer, duration: 6 }); + const out = join(dir, "shots"); + run(`${renderer} snapshot 4s, 0s, 4s`, [ + "snapshot", + dir, + "--at", + "4,0,4", + "--no-end", + "--timeout", + READY_MS, + "-o", + out, + ]); + const files = readdirSync(out) + .filter((file) => /^frame-\d+-at-.*\.png$/.test(file)) + .sort(); + if (files.length !== 3) fail(`${renderer}: expected 3 stills, found ${files.join(", ")}`); + const hashes = files.map((file) => sha(readFileSync(join(out, file)))); + const frames = files.map((file) => decode(join(out, file))[0]); + report[`${renderer}SeekHashes`] = Object.fromEntries(files.map((file, i) => [file, hashes[i]])); + if (hashes[0] !== hashes[2]) fail(`${renderer}: 4 s differs after seeking back from 0 s`); + if (hashes[0] === hashes[1]) fail(`${renderer}: 0 s and 4 s are identical, nothing moved`); + for (const [i, frame] of frames.entries()) { + if (spread(frame) < 4) fail(`${renderer}: ${files[i]} is blank`); + } + return { atZero: frames[1], atFourHash: hashes[0] }; +} + +function checkReload(renderer, firstHash) { + const dir = makeProject(`${renderer}-reload`, { renderer, duration: 6 }); + const out = join(dir, "shots"); + run(`${renderer} snapshot 4s in a new page`, [ + "snapshot", + dir, + "--at", + "4", + "--no-end", + "--timeout", + READY_MS, + "-o", + out, + ]); + const file = readdirSync(out).find((name) => /^frame-\d+-at-.*\.png$/.test(name)); + const hash = sha(readFileSync(join(out, file))); + report[`${renderer}ReloadHash`] = hash; + if (hash !== firstHash) + fail(`${renderer}: a new page drew 4 s differently (${hash} vs ${firstHash})`); +} + +function checkExport(renderer, { duration, fps, workers }) { + const dir = makeProject(`${renderer}-export`, { renderer, duration }); + const output = join(dir, "out.mp4"); + run(`${renderer} render ${duration} s at ${fps} fps`, [ + "render", + dir, + "--fps", + String(fps), + "--workers", + String(workers), + "--player-ready-timeout", + READY_MS, + "-o", + output, + ]); + const frames = decode(output); + const expected = Math.round(duration * fps); + const spreads = frames.map((frame) => Number(spread(frame).toFixed(1))); + const firstToLast = Number(meanDifference(frames[0], frames.at(-1)).toFixed(2)); + // A jump shows up as one step between neighbouring frames far larger than the typical one: + // a cold first frame, or grain that changes where one worker's chunk meets the next. + const steps = frames.slice(1).map((frame, i) => meanDifference(frames[i], frame)); + const median = [...steps].sort((a, b) => a - b)[steps.length >> 1]; + const stepRatios = steps.map((step) => Number((step / median).toFixed(2))); + report[`${renderer}Export`] = { + workers, + frames: frames.length, + spreads, + firstToLast, + stepRatios, + }; + if (frames.length !== expected) + fail(`${renderer}: ${frames.length} frames, expected ${expected}`); + if (spreads.some((value) => value < 4)) fail(`${renderer}: an exported frame is blank`); + if (firstToLast < 0.5) fail(`${renderer}: first and last exported frames look the same`); + if (stepRatios.some((ratio) => ratio > 3)) fail(`${renderer}: a frame-to-frame step jumps`); +} + +try { + run("check", [ + "check", + makeProject("check", { renderer: "path", duration: 6 }), + "--timeout", + READY_MS, + ]); + const raster = checkSeekOrder("raster"); + const path = checkSeekOrder("path"); + checkReload("path", path.atFourHash); + report.rasterVsPathAtZero = Number(meanDifference(raster.atZero, path.atZero).toFixed(2)); + if (report.rasterVsPathAtZero < 0.5) fail("path mode drew the same pixels as raster mode"); + checkExport("raster", { duration: 1, fps: 30, workers: 1 }); + checkExport("path", { duration: 0.8, fps: 10, workers: 2 }); + console.log(JSON.stringify(report, null, 2)); + console.log("PASS"); +} catch (error) { + console.error(JSON.stringify(report, null, 2)); + console.error(`FAIL: ${error.message}`); + process.exitCode = 1; +} finally { + if (!process.env.KEEP_VERIFY_OUTPUT) rmSync(scratch, { recursive: true, force: true }); + else console.log(`kept ${scratch}`); +} diff --git a/skills-manifest.json b/skills-manifest.json index f2e269a911..5d6ab2ad5d 100644 --- a/skills-manifest.json +++ b/skills-manifest.json @@ -6,8 +6,8 @@ "files": 2 }, "hyperframes": { - "hash": "c8d63424db2726d3", - "files": 77 + "hash": "7794480f96489b7d", + "files": 78 }, "hyperframes-cli": { "hash": "571fffd79a7d42f9", diff --git a/skills/hyperframes/references/path-tracing.md b/skills/hyperframes/references/path-tracing.md new file mode 100644 index 0000000000..ddbac7e8e7 --- /dev/null +++ b/skills/hyperframes/references/path-tracing.md @@ -0,0 +1,36 @@ +# Path-traced 3D + +Path tracing gives real soft shadows, light bouncing between objects and reflections of the scene, at many times the cost of raster (75 times the export time in the measurement below). Start from the `path-traced-3d` example (`npx hyperframes init --example path-traced-3d`): a Three.js scene with a fast raster preview and an opt-in path-traced export, with three, three-gpu-pathtracer (WebGL) and three-mesh-bvh vendored as one pinned local file, so a 2D project never loads the tracer. Edit `assets/scene.js`; `assets/render.js` holds the contract below. + +## Raster or path + +| Variable | Use | Cost | +| ------------------------------ | ------------------------------------------------------------------------------------- | -------------------------------------------------------------- | +| `renderer: "raster"` (default) | Previews, drafts, timing, the Studio preview | Milliseconds a frame | +| `renderer: "path"` | The final export, when bounced light, soft shadows or inter-reflections are the point | Every frame traces `samples` passes of up to `bounces` bounces | + +Preview in raster, then export once: `npx hyperframes render --variables '{"renderer":"path","samples":64}'`. Measured on an Apple M4 Max with a hardware GPU for an 8 s 720p clip: raster 10.8 s, path traced 810.5 s at 32 samples per pixel and 6 bounces. Noise falls with the square root of the samples, so halving it costs four times the samples, and every extra bounce makes each path longer; the example defaults to 64 samples and 4 bounces. + +Without a hardware GPU, Chrome draws WebGL in software: on SwiftShader the tracer's first shader run alone took about a minute at 320×180, longer than the default 45 s readiness wait. Test path mode there at a few hundred pixels wide and 1 to 2 samples, and raise the wait: `--timeout 170000` for `check` and `snapshot`, `--player-ready-timeout 180000` for `render`. A setup that times out can be reported as "Composition has zero duration". + +## The contract + +- Setup is one `window.__hf.buildReady[""]` promise: build the scene, `await renderer.compileAsync(scene, camera)`, construct the tracer, then draw one throwaway frame and read one pixel back. The first frame a renderer draws differs from later ones, and the readback makes the GPU finish that first, slowest run inside setup; `gl.finish()` can return before a software GPU has run the work. +- Draw only inside the `hf-seek` listener and register the work synchronously: `e.detail.waitUntil(promise)`. Queue each seek behind the previous one. Never start a loop (`renderer.setAnimationLoop`, a `requestAnimationFrame` loop). +- Every visible thing is a function of `e.detail.time`. Each new time calls `tracer.setScene` (objects moved) and accumulates exactly `samples` passes from zero; a repeat seek to the time already on the canvas does no work. Drive sampling by that count, never by elapsed time or the tracer's own "done" state. +- Set `tracer.renderDelay = 0`, `fadeDuration = 0`, `minSamples = 1`, `dynamicLowRes = false`, `rasterizeScene = false` and `stableNoise = true`. The tracer times its delay and fade with `THREE.Clock`, which reads a clock that does not move during a render. +- Seed `Math.random` while you build the scene and construct the tracer, then restore it. Anything created later (a model loaded during setup) must be built under the seed too. Three's object uuids come from it and set the order the tracer sorts lights, meshes and textures in, and the tracer builds its noise textures from it, so without a seed every page load (every render worker) draws different grain, which jumps where one worker's frames meet the next. Local renders leave `Math.random` native; only distributed renders seed it. +- Keep the set of lights and material features fixed over time. A change that alters the tracer's shader starts a compile inside a seek. + +## The frozen clock + +During a render `Date.now()` and `performance.now()` return the current seek time and do not move between seeks (0 until the first seek), and `requestAnimationFrame` callbacks wait until a seek, and the first seek waits for every `buildReady` promise. So setup that awaits an animation frame or waits for the clock to advance never finishes. Composition code uses no timers of its own; await the libraries' readiness promises instead: + +- Raster: `await renderer.compileAsync(scene, camera)`. +- three-gpu-pathtracer 0.0.24 shows compilation only as the `isCompiling` flag. The promise behind it is three's `compileAsync`, so the example awaits that, `tracer._pathTracer._compilePromise`, in one small helper after any `renderSample` that leaves `isCompiling` set. It only decides when drawing may start, never what is drawn. + +Never wait with `scheduler.yield()`: its continuations run ahead of timers, so a loop that yields until a compile finishes starves the `setTimeout` poll inside `compileAsync`, and the page hangs, with or without HyperFrames. Do not replace `renderer.compileAsync` with the synchronous `compile` to get around a hang; fix the wait. + +## Check it + +Snapshot a time, an earlier time, then the first again in one run: `npx hyperframes snapshot --at 4,0,4 --no-end`. The two stills at 4 s must be byte-identical. Then render a short clip and look at the frames themselves, not just the exit code. The example's `source/verify-render.mjs` in the HyperFrames repository does both in raster and path mode, renders path mode on two workers and checks that a new page load draws the same still. diff --git a/skills/hyperframes/references/runtimes.md b/skills/hyperframes/references/runtimes.md index ed72ff2137..c9efbb8063 100644 --- a/skills/hyperframes/references/runtimes.md +++ b/skills/hyperframes/references/runtimes.md @@ -23,7 +23,7 @@ HyperFrames seeks each frame on its own, so motion must be a function of time, n | anime.js v4 | Existing anime code | `autoplay: false`, push to `window.__hfAnime`, `anime.createSeededRandom` | | Three.js, WebGPU, p5, canvas | 3D and generative | Draw from `e.detail.time` in an `hf-seek` listener; set `data-duration` on the root | -Charts and map overlays: drive them from a GSAP tween's `onUpdate`, not the library's own transitions. A real place is shown on baked imagery, not drawn (`film.md` "Maps and real places"). Heavy setup (big meshes, shader compiles) registers a `window.__hf.buildReady[""]` promise. +Charts and map overlays: drive them from a GSAP tween's `onUpdate`, not the library's own transitions. A real place is shown on baked imagery, not drawn (`film.md` "Maps and real places"). Heavy setup (big meshes, shader compiles) registers a `window.__hf.buildReady[""]` promise. Setup awaits library promises such as `renderer.compileAsync(...)`, never `requestAnimationFrame`, the clock, its own timers or `scheduler.yield()` (`path-tracing.md`). ## dotLottie browser setup diff --git a/skills/hyperframes/references/types/3d.md b/skills/hyperframes/references/types/3d.md index a0a2965e48..ff46ca30d9 100644 --- a/skills/hyperframes/references/types/3d.md +++ b/skills/hyperframes/references/types/3d.md @@ -1,6 +1,6 @@ # 3D, simulations and generative pieces -Use 3D when the film earns it: an object or a set as the payoff, a product, a simulation that explains. Loading Three.js, WebGPU, p5 or canvas and the seek protocol are in `../runtimes.md`. +Use 3D when the film earns it: an object or a set as the payoff, a product, a simulation that explains. Loading Three.js, WebGPU, p5 or canvas and the seek protocol are in `../runtimes.md`; path-traced light (soft shadows, bounced light, reflections between objects) with a fast raster preview is in `../path-tracing.md`. ## Deterministic by construction