From 42a14f024d97183989ad596e4a3579faf94ccadb Mon Sep 17 00:00:00 2001 From: maziggy Date: Sat, 31 Jan 2026 08:39:21 +0100 Subject: [PATCH] Fix AMS mapping for model-based queue jobs (Issue #192) When using "Any [Model]" queue assignment, the scheduler now computes AMS mapping after a printer is assigned, instead of requiring it upfront. This fixes H2D Pro (and other printers) failing at filament loading when queued via model-based assignment. The issue was that no AMS mapping was sent to the printer because the specific printer wasn't known at queue time. Closes #192 --- CHANGELOG.md | 4 + backend/app/services/print_scheduler.py | 307 +++++++++++++++++- .../tests/unit/test_scheduler_ams_mapping.py | 267 +++++++++++++++ .../{index-B6QcllFX.js => index-KrxdF0QX.js} | 2 +- static/index.html | 2 +- 5 files changed, 576 insertions(+), 6 deletions(-) create mode 100644 backend/tests/unit/test_scheduler_ams_mapping.py rename static/assets/{index-B6QcllFX.js => index-KrxdF0QX.js} (95%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65921562a..65f29810c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -149,6 +149,10 @@ All notable changes to Bambuddy will be documented in this file. - Tooltip shows full name on hover - **K-Profiles Backup Status** - Fixed GitHub backup settings showing incorrect printer connection count (e.g., "1/2 connected" when both printers are connected); now fetches status from API instead of relying on WebSocket cache - **GitHub Backup Timestamps** - Removed volatile timestamps from GitHub backup files so git diffs only show actual data changes +- **Model-Based Queue AMS Mapping** - Fixed "Any [Model]" queue jobs failing at filament loading on H2D Pro and other printers (Issue #192): + - Scheduler now computes AMS mapping after printer assignment for model-based jobs + - Previously, no AMS mapping was sent because the specific printer wasn't known at queue time + - Auto-matches required filaments to available AMS slots by type and color ### Maintenance - Upgraded vitest from 2.x to 3.x to resolve npm audit security vulnerabilities in dev dependencies diff --git a/backend/app/services/print_scheduler.py b/backend/app/services/print_scheduler.py index 81ab1e520..347212f44 100644 --- a/backend/app/services/print_scheduler.py +++ b/backend/app/services/print_scheduler.py @@ -1,8 +1,12 @@ """Print scheduler service - processes the print queue.""" import asyncio +import json import logging +import xml.etree.ElementTree as ET +import zipfile from datetime import datetime +from pathlib import Path from sqlalchemy import func, select from sqlalchemy.ext.asyncio import AsyncSession @@ -139,8 +143,6 @@ class PrintScheduler: required_types = None if item.required_filament_types: try: - import json - required_types = json.loads(item.required_filament_types) except json.JSONDecodeError: pass @@ -203,6 +205,17 @@ class PrintScheduler: db=db, ) + # Compute AMS mapping for the assigned printer if not already set + # This is critical for model-based jobs where mapping wasn't computed upfront + if not item.ams_mapping: + computed_mapping = await self._compute_ams_mapping_for_printer(db, printer_id, item) + if computed_mapping: + item.ams_mapping = json.dumps(computed_mapping) + logger.info( + f"Queue item {item.id}: Computed AMS mapping for printer {printer_id}: {computed_mapping}" + ) + await db.commit() + await self._start_print(db, item) busy_printers.add(printer_id) @@ -325,6 +338,294 @@ class PrintScheduler: return missing + async def _compute_ams_mapping_for_printer( + self, db: AsyncSession, printer_id: int, item: PrintQueueItem + ) -> list[int] | None: + """Compute AMS mapping for a printer based on filament requirements. + + This is called for model-based queue items after a printer is assigned, + to compute the correct AMS slot mapping for that specific printer's hardware. + + Args: + db: Database session + printer_id: The assigned printer ID + item: The queue item (contains archive_id or library_file_id) + + Returns: + AMS mapping array or None if no mapping needed/possible + """ + # Get printer status + status = printer_manager.get_status(printer_id) + if not status: + logger.warning(f"Cannot compute AMS mapping: printer {printer_id} status unavailable") + return None + + # Get filament requirements from source file + filament_reqs = await self._get_filament_requirements(db, item) + if not filament_reqs: + logger.debug(f"No filament requirements found for queue item {item.id}") + return None + + # Build loaded filaments from printer status + loaded_filaments = self._build_loaded_filaments(status) + if not loaded_filaments: + logger.debug(f"No filaments loaded on printer {printer_id}") + return None + + # Compute mapping: match required filaments to available slots + return self._match_filaments_to_slots(filament_reqs, loaded_filaments) + + async def _get_filament_requirements(self, db: AsyncSession, item: PrintQueueItem) -> list[dict] | None: + """Extract filament requirements from the source 3MF file. + + Args: + db: Database session + item: Queue item with archive_id or library_file_id + + Returns: + List of filament requirement dicts with slot_id, type, color, used_grams + """ + file_path: Path | None = None + + if item.archive_id: + result = await db.execute(select(PrintArchive).where(PrintArchive.id == item.archive_id)) + archive = result.scalar_one_or_none() + if archive: + file_path = settings.base_dir / archive.file_path + elif item.library_file_id: + result = await db.execute(select(LibraryFile).where(LibraryFile.id == item.library_file_id)) + library_file = result.scalar_one_or_none() + if library_file: + lib_path = Path(library_file.file_path) + file_path = lib_path if lib_path.is_absolute() else settings.base_dir / library_file.file_path + + if not file_path or not file_path.exists(): + return None + + filaments = [] + try: + with zipfile.ZipFile(file_path, "r") as zf: + if "Metadata/slice_info.config" not in zf.namelist(): + return None + + content = zf.read("Metadata/slice_info.config").decode() + root = ET.fromstring(content) + + # Check if plate_id is specified - use that plate's filaments + plate_id = item.plate_id + if plate_id: + for plate_elem in root.findall("./plate"): + plate_index = None + for meta in plate_elem.findall("metadata"): + if meta.get("key") == "index": + plate_index = int(meta.get("value", "0")) + break + if plate_index == plate_id: + for filament_elem in plate_elem.findall("./filament"): + filament_id = filament_elem.get("id") + filament_type = filament_elem.get("type", "") + filament_color = filament_elem.get("color", "") + used_g = filament_elem.get("used_g", "0") + try: + used_grams = float(used_g) + if used_grams > 0 and filament_id: + filaments.append( + { + "slot_id": int(filament_id), + "type": filament_type, + "color": filament_color, + "used_grams": round(used_grams, 1), + } + ) + except (ValueError, TypeError): + pass + break + else: + # No plate_id - extract all filaments with used_g > 0 + for filament_elem in root.findall("./filament"): + filament_id = filament_elem.get("id") + filament_type = filament_elem.get("type", "") + filament_color = filament_elem.get("color", "") + used_g = filament_elem.get("used_g", "0") + try: + used_grams = float(used_g) + if used_grams > 0 and filament_id: + filaments.append( + { + "slot_id": int(filament_id), + "type": filament_type, + "color": filament_color, + "used_grams": round(used_grams, 1), + } + ) + except (ValueError, TypeError): + pass + + filaments.sort(key=lambda x: x["slot_id"]) + except Exception as e: + logger.warning(f"Failed to parse filament requirements: {e}") + return None + + return filaments if filaments else None + + def _build_loaded_filaments(self, status) -> list[dict]: + """Build list of loaded filaments from printer status. + + Args: + status: PrinterState from printer_manager + + Returns: + List of loaded filament dicts with type, color, ams_id, tray_id, global_tray_id + """ + filaments = [] + + # Parse AMS units from raw_data + ams_data = status.raw_data.get("ams", []) + for ams_unit in ams_data: + ams_id = ams_unit.get("id", 0) + trays = ams_unit.get("tray", []) + is_ht = len(trays) == 1 # AMS-HT has single tray + + for tray in trays: + tray_type = tray.get("tray_type") + if tray_type: + tray_id = tray.get("id", 0) + tray_color = tray.get("tray_color", "") + # Normalize color: remove alpha, add hash + color = self._normalize_color(tray_color) + # Calculate global tray ID + global_tray_id = ams_id * 4 + tray_id + + filaments.append( + { + "type": tray_type, + "color": color, + "ams_id": ams_id, + "tray_id": tray_id, + "is_ht": is_ht, + "is_external": False, + "global_tray_id": global_tray_id, + } + ) + + # Check external spool (vt_tray) + vt_tray = status.raw_data.get("vt_tray") + if vt_tray and vt_tray.get("tray_type"): + color = self._normalize_color(vt_tray.get("tray_color", "")) + filaments.append( + { + "type": vt_tray["tray_type"], + "color": color, + "ams_id": -1, + "tray_id": 0, + "is_ht": False, + "is_external": True, + "global_tray_id": 254, + } + ) + + return filaments + + def _normalize_color(self, color: str | None) -> str: + """Normalize color to #RRGGBB format.""" + if not color: + return "#808080" + hex_color = color.replace("#", "")[:6] + return f"#{hex_color}" + + def _normalize_color_for_compare(self, color: str | None) -> str: + """Normalize color for comparison (lowercase, no hash).""" + if not color: + return "" + return color.replace("#", "").lower()[:6] + + def _colors_are_similar(self, color1: str | None, color2: str | None, threshold: int = 40) -> bool: + """Check if two colors are visually similar within a threshold.""" + hex1 = self._normalize_color_for_compare(color1) + hex2 = self._normalize_color_for_compare(color2) + if not hex1 or not hex2 or len(hex1) < 6 or len(hex2) < 6: + return False + + try: + r1 = int(hex1[0:2], 16) + g1 = int(hex1[2:4], 16) + b1 = int(hex1[4:6], 16) + r2 = int(hex2[0:2], 16) + g2 = int(hex2[2:4], 16) + b2 = int(hex2[4:6], 16) + return abs(r1 - r2) <= threshold and abs(g1 - g2) <= threshold and abs(b1 - b2) <= threshold + except ValueError: + return False + + def _match_filaments_to_slots(self, required: list[dict], loaded: list[dict]) -> list[int] | None: + """Match required filaments to loaded filaments and build AMS mapping. + + Priority: exact color match > similar color match > type-only match + + Args: + required: List of required filaments with slot_id, type, color + loaded: List of loaded filaments with type, color, global_tray_id + + Returns: + AMS mapping array (position = slot_id - 1, value = global_tray_id or -1) + """ + if not required: + return None + + # Track used trays to avoid duplicate assignment + used_tray_ids: set[int] = set() + comparisons = [] + + for req in required: + req_type = (req.get("type") or "").upper() + req_color = req.get("color", "") + + # Find best match: exact color > similar color > type-only + exact_match = None + similar_match = None + type_only_match = None + + for f in loaded: + if f["global_tray_id"] in used_tray_ids: + continue + f_type = (f.get("type") or "").upper() + if f_type != req_type: + continue + + # Type matches - check color + f_color = f.get("color", "") + if self._normalize_color_for_compare(f_color) == self._normalize_color_for_compare(req_color): + exact_match = f + break # Best possible match + elif self._colors_are_similar(f_color, req_color): + if not similar_match: + similar_match = f + elif not type_only_match: + type_only_match = f + + match = exact_match or similar_match or type_only_match + if match: + used_tray_ids.add(match["global_tray_id"]) + comparisons.append({"slot_id": req.get("slot_id", 0), "global_tray_id": match["global_tray_id"]}) + else: + comparisons.append({"slot_id": req.get("slot_id", 0), "global_tray_id": -1}) + + # Build mapping array + if not comparisons: + return None + + max_slot_id = max(c["slot_id"] for c in comparisons) + if max_slot_id <= 0: + return None + + mapping = [-1] * max_slot_id + for c in comparisons: + slot_id = c["slot_id"] + if slot_id and slot_id > 0: + mapping[slot_id - 1] = c["global_tray_id"] + + return mapping + def _is_printer_idle(self, printer_id: int) -> bool: """Check if a printer is connected and idle.""" if not printer_manager.is_connected(printer_id): @@ -621,8 +922,6 @@ class PrintScheduler: ams_mapping = None if item.ams_mapping: try: - import json - ams_mapping = json.loads(item.ams_mapping) except json.JSONDecodeError: logger.warning(f"Queue item {item.id}: Invalid AMS mapping JSON, ignoring") diff --git a/backend/tests/unit/test_scheduler_ams_mapping.py b/backend/tests/unit/test_scheduler_ams_mapping.py new file mode 100644 index 000000000..82db6cfec --- /dev/null +++ b/backend/tests/unit/test_scheduler_ams_mapping.py @@ -0,0 +1,267 @@ +"""Tests for the AMS mapping computation in the print scheduler.""" + +import pytest + +from backend.app.services.print_scheduler import PrintScheduler + + +class TestSchedulerAmsMappingHelpers: + """Test the AMS mapping helper methods in PrintScheduler.""" + + @pytest.fixture + def scheduler(self): + return PrintScheduler() + + def test_normalize_color_with_hash(self, scheduler): + """Color with hash should return #RRGGBB format.""" + result = scheduler._normalize_color("#FF5500") + assert result == "#FF5500" + + def test_normalize_color_without_hash(self, scheduler): + """Color without hash should add hash prefix.""" + result = scheduler._normalize_color("FF5500") + assert result == "#FF5500" + + def test_normalize_color_with_alpha(self, scheduler): + """Color with alpha channel should strip it.""" + result = scheduler._normalize_color("FF5500AA") + assert result == "#FF5500" + + def test_normalize_color_none(self, scheduler): + """None color should return default gray.""" + result = scheduler._normalize_color(None) + assert result == "#808080" + + def test_normalize_color_empty(self, scheduler): + """Empty color should return default gray.""" + result = scheduler._normalize_color("") + assert result == "#808080" + + def test_normalize_color_for_compare(self, scheduler): + """Color for compare should be lowercase without hash.""" + result = scheduler._normalize_color_for_compare("#FF5500") + assert result == "ff5500" + + def test_normalize_color_for_compare_with_alpha(self, scheduler): + """Alpha channel should be stripped for comparison.""" + result = scheduler._normalize_color_for_compare("#FF5500AA") + assert result == "ff5500" + + def test_colors_are_similar_exact_match(self, scheduler): + """Exact same colors should be similar.""" + assert scheduler._colors_are_similar("#FF5500", "#FF5500") is True + + def test_colors_are_similar_within_threshold(self, scheduler): + """Colors within threshold should be similar.""" + # Red difference of 10, well within default threshold of 40 + assert scheduler._colors_are_similar("#FF5500", "#F55500") is True + + def test_colors_are_similar_outside_threshold(self, scheduler): + """Colors outside threshold should not be similar.""" + # Red: FF (255) vs 00 (0) = 255 difference + assert scheduler._colors_are_similar("#FF0000", "#00FF00") is False + + def test_colors_are_similar_none_colors(self, scheduler): + """None colors should not be similar.""" + assert scheduler._colors_are_similar(None, "#FF5500") is False + assert scheduler._colors_are_similar("#FF5500", None) is False + + +class TestBuildLoadedFilaments: + """Test the _build_loaded_filaments method.""" + + @pytest.fixture + def scheduler(self): + return PrintScheduler() + + def test_build_loaded_filaments_empty_status(self, scheduler): + """Empty status should return empty list.""" + + class MockStatus: + raw_data = {} + + result = scheduler._build_loaded_filaments(MockStatus()) + assert result == [] + + def test_build_loaded_filaments_with_ams(self, scheduler): + """Should extract filaments from AMS units.""" + + class MockStatus: + raw_data = { + "ams": [ + { + "id": 0, + "tray": [ + {"id": 0, "tray_type": "PLA", "tray_color": "FF0000"}, + {"id": 1, "tray_type": "PETG", "tray_color": "00FF00"}, + ], + } + ] + } + + result = scheduler._build_loaded_filaments(MockStatus()) + assert len(result) == 2 + + # First filament + assert result[0]["type"] == "PLA" + assert result[0]["color"] == "#FF0000" + assert result[0]["ams_id"] == 0 + assert result[0]["tray_id"] == 0 + assert result[0]["global_tray_id"] == 0 # 0 * 4 + 0 + + # Second filament + assert result[1]["type"] == "PETG" + assert result[1]["global_tray_id"] == 1 # 0 * 4 + 1 + + def test_build_loaded_filaments_with_ht_ams(self, scheduler): + """AMS-HT (single tray) should be marked as is_ht.""" + + class MockStatus: + raw_data = { + "ams": [ + { + "id": 128, + "tray": [{"id": 0, "tray_type": "PLA-CF", "tray_color": "000000"}], + } + ] + } + + result = scheduler._build_loaded_filaments(MockStatus()) + assert len(result) == 1 + assert result[0]["is_ht"] is True + assert result[0]["global_tray_id"] == 512 # 128 * 4 + 0 + + def test_build_loaded_filaments_with_external(self, scheduler): + """Should include external spool.""" + + class MockStatus: + raw_data = {"vt_tray": {"tray_type": "TPU", "tray_color": "0000FF"}} + + result = scheduler._build_loaded_filaments(MockStatus()) + assert len(result) == 1 + assert result[0]["type"] == "TPU" + assert result[0]["is_external"] is True + assert result[0]["global_tray_id"] == 254 + + def test_build_loaded_filaments_skips_empty_trays(self, scheduler): + """Trays without tray_type should be skipped.""" + + class MockStatus: + raw_data = { + "ams": [ + { + "id": 0, + "tray": [ + {"id": 0, "tray_type": "PLA", "tray_color": "FF0000"}, + {"id": 1, "tray_type": "", "tray_color": ""}, # Empty + {"id": 2}, # No tray_type key + ], + } + ] + } + + result = scheduler._build_loaded_filaments(MockStatus()) + assert len(result) == 1 + assert result[0]["type"] == "PLA" + + +class TestMatchFilamentsToSlots: + """Test the _match_filaments_to_slots method.""" + + @pytest.fixture + def scheduler(self): + return PrintScheduler() + + def test_match_empty_required(self, scheduler): + """Empty required list should return None.""" + result = scheduler._match_filaments_to_slots([], []) + assert result is None + + def test_match_exact_color(self, scheduler): + """Should prefer exact color match.""" + required = [{"slot_id": 1, "type": "PLA", "color": "#FF0000"}] + loaded = [ + {"type": "PLA", "color": "#00FF00", "global_tray_id": 0}, # Wrong color + {"type": "PLA", "color": "#FF0000", "global_tray_id": 1}, # Exact match + ] + + result = scheduler._match_filaments_to_slots(required, loaded) + assert result == [1] # Should pick tray 1 (exact color match) + + def test_match_similar_color(self, scheduler): + """Should match similar colors when no exact match.""" + required = [{"slot_id": 1, "type": "PLA", "color": "#FF5500"}] + loaded = [ + {"type": "PLA", "color": "#FF5510", "global_tray_id": 0}, # Similar + ] + + result = scheduler._match_filaments_to_slots(required, loaded) + assert result == [0] + + def test_match_type_only(self, scheduler): + """Should match by type when colors don't match.""" + required = [{"slot_id": 1, "type": "PLA", "color": "#FF0000"}] + loaded = [ + {"type": "PLA", "color": "#0000FF", "global_tray_id": 5}, # Type match, color way off + ] + + result = scheduler._match_filaments_to_slots(required, loaded) + assert result == [5] + + def test_match_no_match_returns_minus_one(self, scheduler): + """Unmatched filaments should have -1 in mapping.""" + required = [{"slot_id": 1, "type": "PLA", "color": "#FF0000"}] + loaded = [ + {"type": "PETG", "color": "#FF0000", "global_tray_id": 0}, # Wrong type + ] + + result = scheduler._match_filaments_to_slots(required, loaded) + assert result == [-1] + + def test_match_multiple_filaments(self, scheduler): + """Should match multiple filaments correctly.""" + required = [ + {"slot_id": 1, "type": "PLA", "color": "#FF0000"}, + {"slot_id": 2, "type": "PETG", "color": "#00FF00"}, + ] + loaded = [ + {"type": "PLA", "color": "#FF0000", "global_tray_id": 0}, + {"type": "PETG", "color": "#00FF00", "global_tray_id": 1}, + ] + + result = scheduler._match_filaments_to_slots(required, loaded) + assert result == [0, 1] + + def test_match_avoids_duplicate_assignment(self, scheduler): + """Same tray should not be assigned to multiple slots.""" + required = [ + {"slot_id": 1, "type": "PLA", "color": "#FF0000"}, + {"slot_id": 2, "type": "PLA", "color": "#FF0000"}, # Same requirements + ] + loaded = [ + {"type": "PLA", "color": "#FF0000", "global_tray_id": 0}, # Only one PLA + ] + + result = scheduler._match_filaments_to_slots(required, loaded) + # First slot gets the match, second slot gets -1 + assert result == [0, -1] + + def test_match_h2d_pro_ams_ids(self, scheduler): + """Should work with H2D Pro's high AMS IDs (128+).""" + required = [{"slot_id": 1, "type": "PLA", "color": "#FF0000"}] + loaded = [ + {"type": "PLA", "color": "#FF0000", "global_tray_id": 512}, # AMS 128, slot 0 + ] + + result = scheduler._match_filaments_to_slots(required, loaded) + assert result == [512] + + def test_match_external_spool(self, scheduler): + """Should match external spool with ID 254.""" + required = [{"slot_id": 1, "type": "TPU", "color": "#0000FF"}] + loaded = [ + {"type": "TPU", "color": "#0000FF", "global_tray_id": 254, "is_external": True}, + ] + + result = scheduler._match_filaments_to_slots(required, loaded) + assert result == [254] diff --git a/static/assets/index-B6QcllFX.js b/static/assets/index-KrxdF0QX.js similarity index 95% rename from static/assets/index-B6QcllFX.js rename to static/assets/index-KrxdF0QX.js index 4aab726a4..b571257f8 100644 --- a/static/assets/index-B6QcllFX.js +++ b/static/assets/index-KrxdF0QX.js @@ -88,7 +88,7 @@ Please change the parent to aa.mutate([je.id]),disabled:aa.isPending||(H?.layer_num??0)<=1,className:`px-4 py-2 text-xs font-medium rounded-lg transition-colors ${(H?.layer_num??0)<=1?"bg-gray-100 dark:bg-bambu-dark text-gray-400 dark:text-bambu-gray/50 cursor-not-allowed":"bg-red-100 dark:bg-red-500/20 text-red-600 dark:text-red-400 hover:bg-red-200 dark:hover:bg-red-500/30 border border-red-300 dark:border-red-500/30"}`,title:(H?.layer_num??0)<=1?"Wait for layer 2+":"Skip this object",children:"Skip"})]},je.id))})]})]}):s.jsx("div",{className:"flex items-center justify-center py-12",children:s.jsx(ut,{className:"w-5 h-5 animate-spin text-bambu-gray"})})]})]}),W&&s.jsx(Vfe,{printerName:t.name,errors:H?.hms_errors||[],onClose:()=>Y(!1)}),de&&s.jsx(Fke,{isOpen:!!de,onClose:()=>me(null),printerId:t.id,printerName:t.name,amsId:de.amsId,amsLabel:de.amsLabel,initialMode:de.mode,thresholds:a}),ue&&s.jsx(Uke,{isOpen:!!ue,onClose:()=>Ee(null),trayUuid:ue.trayUuid,trayInfo:ue.trayInfo}),pe&&s.jsx(Wke,{isOpen:!!pe,onClose:()=>Me(null),printerId:t.id,slotInfo:pe,onSuccess:()=>{m.invalidateQueries({queryKey:["slotPresets",t.id]}),m.invalidateQueries({queryKey:["printerStatus",t.id]})}}),T&&s.jsx(lje,{printer:t,onClose:()=>C(!1)}),ye&&re&&s.jsx(oje,{printer:t,firmwareInfo:re,onClose:()=>le(!1)}),Qt&&s.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>Gt(null)})]})}function sje({onClose:t,onAdd:e,existingSerials:n}){const[r,i]=w.useState({name:"",serial_number:"",ip_address:"",access_code:"",model:"",auto_archive:!0}),[a,o]=w.useState(!1),[l,c]=w.useState([]),[u,d]=w.useState(""),[f,m]=w.useState(!1),[g,x]=w.useState(!1),[y,b]=w.useState("192.168.1.0/24"),[v,N]=w.useState({scanned:0,total:0});w.useEffect(()=>{_l.getInfo().then(A=>{x(A.is_docker)}).catch(()=>{})},[]);const S=l.filter(A=>!n.includes(A.serial)),E=async()=>{d(""),c([]),o(!0),m(!1),N({scanned:0,total:0});try{if(g){await _l.startSubnetScan(y);const A=setInterval(async()=>{try{const D=await _l.getScanStatus();N({scanned:D.scanned,total:D.total});const k=await _l.getDiscoveredPrinters();c(k),D.running||(clearInterval(A),o(!1),m(!0))}catch(D){console.error("Failed to get scan status:",D)}},500)}else{await _l.startDiscovery(10);const A=setInterval(async()=>{try{const D=await _l.getDiscoveredPrinters();c(D)}catch(D){console.error("Failed to get discovered printers:",D)}},1e3);setTimeout(async()=>{clearInterval(A);try{await _l.stopDiscovery()}catch{}o(!1),m(!0);try{const D=await _l.getDiscoveredPrinters();c(D)}catch(D){console.error("Failed to get final discovered printers:",D)}},1e4)}}catch(A){console.error("Failed to start discovery:",A),d(A instanceof Error?A.message:"Failed to start discovery"),o(!1),m(!0)}},T=A=>A?{O1D:"H2D",O1C:"H2C",O1S:"H2S","BL-P001":"X1C","BL-P002":"X1","BL-P003":"X1E",C11:"P1S",C12:"P1P",C13:"P2S",N2S:"A1",N1:"A1 Mini",X1C:"X1C",X1:"X1",X1E:"X1E",P1S:"P1S",P1P:"P1P",P2S:"P2S",A1:"A1","A1 Mini":"A1 Mini",H2D:"H2D",H2C:"H2C",H2S:"H2S"}[A]||A:"",C=A=>{const D=A.serial.startsWith("unknown-")?"":A.serial;i({...r,name:A.name||"",serial_number:D,ip_address:A.ip_address,model:T(A.model)}),c([])};return w.useEffect(()=>()=>{_l.stopDiscovery().catch(()=>{}),_l.stopSubnetScan().catch(()=>{})},[]),w.useEffect(()=>{const A=D=>{D.key==="Escape"&&t()};return window.addEventListener("keydown",A),()=>window.removeEventListener("keydown",A)},[t]),s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",onClick:t,children:s.jsx(St,{className:"w-full max-w-md",onClick:A=>A.stopPropagation(),children:s.jsxs(Et,{children:[s.jsx("h2",{className:"text-xl font-semibold mb-4",children:"Add Printer"}),s.jsxs("div",{className:"mb-4 pb-4 border-b border-bambu-dark-tertiary",children:[g&&s.jsxs("div",{className:"mb-3",children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Subnet to scan"}),s.jsx("input",{type:"text",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm",value:y,onChange:A=>b(A.target.value),placeholder:"192.168.1.0/24",disabled:a}),s.jsxs("p",{className:"mt-1 text-xs text-bambu-gray",children:["Docker detected. Enter your printer's subnet in CIDR notation. Requires ",s.jsx("code",{className:"text-bambu-green",children:"network_mode: host"})," in docker-compose.yml."]})]}),s.jsx(Se,{type:"button",variant:"secondary",onClick:E,disabled:a,className:"w-full",children:a?s.jsxs(s.Fragment,{children:[s.jsx(ut,{className:"w-4 h-4 animate-spin"}),g&&v.total>0?`Scanning... ${v.scanned}/${v.total}`:"Scanning..."]}):s.jsxs(s.Fragment,{children:[s.jsx(_a,{className:"w-4 h-4"}),g?"Scan Subnet for Printers":"Discover Printers on Network"]})}),u&&s.jsx("div",{className:"mt-2 text-sm text-red-400",children:u}),S.length>0&&s.jsx("div",{className:"mt-3 space-y-2 max-h-40 overflow-y-auto",children:S.map(A=>s.jsxs("div",{className:"flex items-center justify-between p-2 bg-bambu-dark rounded-lg hover:bg-bambu-dark-secondary cursor-pointer transition-colors",onClick:()=>C(A),children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("p",{className:"font-medium text-white text-sm truncate",children:A.name||A.serial}),s.jsxs("p",{className:"text-xs text-bambu-gray truncate",children:[T(A.model)||"Unknown"," • ",A.ip_address,A.serial.startsWith("unknown-")&&s.jsx("span",{className:"text-yellow-500",children:" • Serial required"})]})]}),s.jsx(Ur,{className:"w-4 h-4 text-bambu-gray -rotate-90 flex-shrink-0 ml-2"})]},A.serial))}),a&&s.jsx("p",{className:"mt-2 text-sm text-bambu-gray text-center",children:g?"Scanning subnet for Bambu printers...":"Scanning network..."}),f&&!a&&l.length===0&&s.jsxs("p",{className:"mt-2 text-sm text-bambu-gray text-center",children:["No printers found",g?" in the specified subnet":" on the network","."]}),f&&!a&&l.length>0&&S.length===0&&s.jsx("p",{className:"mt-2 text-sm text-bambu-gray text-center",children:"All discovered printers are already configured."})]}),s.jsxs("form",{onSubmit:A=>{A.preventDefault(),e(r)},className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name"}),s.jsx("input",{type:"text",required:!0,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:r.name,onChange:A=>i({...r,name:A.target.value}),placeholder:"My Printer"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"IP Address"}),s.jsx("input",{type:"text",required:!0,pattern:"\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:r.ip_address,onChange:A=>i({...r,ip_address:A.target.value}),placeholder:"192.168.1.100"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Serial Number"}),s.jsx("input",{type:"text",required:!0,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:r.serial_number,onChange:A=>i({...r,serial_number:A.target.value}),placeholder:"01P00A000000000"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Access Code"}),s.jsx("input",{type:"password",required:!0,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:r.access_code,onChange:A=>i({...r,access_code:A.target.value}),placeholder:"From printer settings"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Model (optional)"}),s.jsxs("select",{className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:r.model||"",onChange:A=>i({...r,model:A.target.value}),children:[s.jsx("option",{value:"",children:"Select model..."}),s.jsxs("optgroup",{label:"H2 Series",children:[s.jsx("option",{value:"H2C",children:"H2C"}),s.jsx("option",{value:"H2D",children:"H2D"}),s.jsx("option",{value:"H2S",children:"H2S"})]}),s.jsxs("optgroup",{label:"X1 Series",children:[s.jsx("option",{value:"X1E",children:"X1E"}),s.jsx("option",{value:"X1C",children:"X1 Carbon"}),s.jsx("option",{value:"X1",children:"X1"})]}),s.jsxs("optgroup",{label:"P Series",children:[s.jsx("option",{value:"P2S",children:"P2S"}),s.jsx("option",{value:"P1S",children:"P1S"}),s.jsx("option",{value:"P1P",children:"P1P"})]}),s.jsxs("optgroup",{label:"A1 Series",children:[s.jsx("option",{value:"A1",children:"A1"}),s.jsx("option",{value:"A1 Mini",children:"A1 Mini"})]})]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"checkbox",id:"auto_archive",checked:r.auto_archive,onChange:A=>i({...r,auto_archive:A.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),s.jsx("label",{htmlFor:"auto_archive",className:"text-sm text-bambu-gray",children:"Auto-archive completed prints"})]}),s.jsxs("div",{className:"flex gap-3 pt-4",children:[s.jsx(Se,{type:"button",variant:"secondary",onClick:t,className:"flex-1",children:"Cancel"}),s.jsx(Se,{type:"submit",className:"flex-1",children:"Add Printer"})]})]})]})})})}function oje({printer:t,firmwareInfo:e,onClose:n}){const r=sn(),{showToast:i}=Gn(),[a,o]=w.useState(null),[l,c]=w.useState(!1),[u,d]=w.useState(null),{data:f,isLoading:m}=ct({queryKey:["firmwarePrepare",t.id],queryFn:()=>B1.prepareUpload(t.id),staleTime:3e4}),g=ht({mutationFn:()=>B1.startUpload(t.id),onSuccess:()=>{c(!0);const y=setInterval(async()=>{try{const b=await B1.getUploadStatus(t.id);o(b),(b.status==="complete"||b.status==="error")&&(clearInterval(y),d(null),c(!1),b.status==="complete"&&(i("Firmware uploaded! Trigger update from printer screen.","success"),r.invalidateQueries({queryKey:["firmwareUpdate",t.id]})))}catch{}},2e3);d(y)},onError:y=>{i(`Failed to start upload: ${y.message}`,"error"),c(!1)}});w.useEffect(()=>()=>{u&&clearInterval(u)},[u]);const x=()=>{o(null),g.mutate()};return s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:s.jsx(St,{className:"w-full max-w-md mx-4",children:s.jsxs(Et,{children:[s.jsxs("div",{className:"flex items-start gap-3 mb-4",children:[s.jsx("div",{className:"p-2 rounded-full bg-orange-500/20",children:s.jsx(Hr,{className:"w-5 h-5 text-orange-400"})}),s.jsxs("div",{className:"flex-1",children:[s.jsx("h3",{className:"text-lg font-semibold text-white",children:"Firmware Update"}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:t.name})]})]}),s.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3 mb-4",children:[s.jsxs("div",{className:"flex justify-between items-center text-sm",children:[s.jsx("span",{className:"text-bambu-gray",children:"Current:"}),s.jsx("span",{className:"text-white font-mono",children:e.current_version||"Unknown"})]}),s.jsxs("div",{className:"flex justify-between items-center text-sm mt-1",children:[s.jsx("span",{className:"text-bambu-gray",children:"Latest:"}),s.jsx("span",{className:"text-orange-400 font-mono",children:e.latest_version})]}),e.release_notes&&s.jsxs("details",{className:"mt-3 text-sm",children:[s.jsx("summary",{className:"text-orange-400 cursor-pointer hover:underline",children:"Release Notes"}),s.jsx("div",{className:"mt-2 text-bambu-gray text-xs max-h-40 overflow-y-auto whitespace-pre-wrap",children:e.release_notes})]})]}),m?s.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-sm mb-4",children:[s.jsx(ut,{className:"w-4 h-4 animate-spin"}),"Checking prerequisites..."]}):f&&!l&&!a?s.jsx("div",{className:"mb-4",children:f.can_proceed?s.jsxs("div",{className:"flex items-center gap-2 text-bambu-green text-sm",children:[s.jsx(Bs,{className:"w-4 h-4"}),"SD card ready. Click below to upload firmware."]}):s.jsx("div",{className:"space-y-1",children:f.errors.map((y,b)=>s.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm",children:[s.jsx(Mi,{className:"w-4 h-4 flex-shrink-0"}),y]},b))})}):null,(l||a)&&a&&s.jsxs("div",{className:"mb-4",children:[s.jsxs("div",{className:"flex items-center justify-between text-sm mb-1",children:[s.jsx("span",{className:"text-bambu-gray capitalize",children:a.status}),s.jsxs("span",{className:"text-white",children:[a.progress,"%"]})]}),s.jsx("div",{className:"w-full bg-bambu-dark-tertiary rounded-full h-2",children:s.jsx("div",{className:`h-2 rounded-full transition-all ${a.status==="error"?"bg-status-error":a.status==="complete"?"bg-status-ok":"bg-orange-500"} ${a.status==="uploading"?"animate-pulse":""}`,style:{width:`${a.progress}%`}})}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a.message}),a.error&&s.jsx("p",{className:"text-xs text-red-400 mt-1",children:a.error})]}),a?.status==="complete"&&s.jsxs("div",{className:"bg-bambu-green/10 border border-bambu-green/30 rounded-lg p-3 mb-4",children:[s.jsx("p",{className:"text-sm text-bambu-green font-medium mb-2",children:"Firmware uploaded to SD card!"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"To apply the update on your printer:"}),s.jsxs("ol",{className:"text-xs text-bambu-gray mt-1 list-decimal list-inside space-y-1",children:[s.jsxs("li",{children:["On the printer's touchscreen, go to ",s.jsx("strong",{className:"text-white",children:"Settings"})]}),s.jsxs("li",{children:["Navigate to ",s.jsx("strong",{className:"text-white",children:"Firmware"})]}),s.jsxs("li",{children:["Select ",s.jsx("strong",{className:"text-white",children:"Update from SD card"})]}),s.jsx("li",{children:"The update will take 10-20 minutes"})]})]}),s.jsxs("div",{className:"flex gap-2 justify-end",children:[s.jsx(Se,{variant:"secondary",onClick:n,children:a?.status==="complete"?"Done":"Cancel"}),f?.can_proceed&&!l&&a?.status!=="complete"&&s.jsx(Se,{onClick:x,disabled:g.isPending,children:g.isPending?s.jsxs(s.Fragment,{children:[s.jsx(ut,{className:"w-4 h-4 animate-spin mr-2"}),"Starting..."]}):s.jsxs(s.Fragment,{children:[s.jsx(Hr,{className:"w-4 h-4 mr-2"}),"Upload Firmware"]})})]})]})})})}function lje({printer:t,onClose:e}){const n=sn(),[r,i]=w.useState({name:t.name,ip_address:t.ip_address,access_code:"",model:t.model||"",location:t.location||"",auto_archive:t.auto_archive}),a=ht({mutationFn:l=>fe.updatePrinter(t.id,l),onSuccess:()=>{n.invalidateQueries({queryKey:["printers"]}),n.invalidateQueries({queryKey:["printerStatus",t.id]}),e()}});w.useEffect(()=>{const l=c=>{c.key==="Escape"&&e()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[e]);const o=l=>{l.preventDefault();const c={name:r.name,ip_address:r.ip_address,model:r.model||void 0,location:r.location||void 0,auto_archive:r.auto_archive};r.access_code&&(c.access_code=r.access_code),a.mutate(c)};return s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",onClick:e,children:s.jsx(St,{className:"w-full max-w-md",onClick:l=>l.stopPropagation(),children:s.jsxs(Et,{children:[s.jsx("h2",{className:"text-xl font-semibold mb-4",children:"Edit Printer"}),s.jsxs("form",{onSubmit:o,className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name"}),s.jsx("input",{type:"text",required:!0,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:r.name,onChange:l=>i({...r,name:l.target.value}),placeholder:"My Printer"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"IP Address"}),s.jsx("input",{type:"text",required:!0,pattern:"\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:r.ip_address,onChange:l=>i({...r,ip_address:l.target.value}),placeholder:"192.168.1.100"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Serial Number"}),s.jsx("input",{type:"text",disabled:!0,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray cursor-not-allowed",value:t.serial_number}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Serial number cannot be changed"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Access Code"}),s.jsx("input",{type:"password",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:r.access_code,onChange:l=>i({...r,access_code:l.target.value}),placeholder:"Leave empty to keep current"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Model"}),s.jsxs("select",{className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:r.model,onChange:l=>i({...r,model:l.target.value}),children:[s.jsx("option",{value:"",children:"Select model..."}),s.jsxs("optgroup",{label:"H2 Series",children:[s.jsx("option",{value:"H2C",children:"H2C"}),s.jsx("option",{value:"H2D",children:"H2D"}),s.jsx("option",{value:"H2S",children:"H2S"})]}),s.jsxs("optgroup",{label:"X1 Series",children:[s.jsx("option",{value:"X1E",children:"X1E"}),s.jsx("option",{value:"X1C",children:"X1 Carbon"}),s.jsx("option",{value:"X1",children:"X1"})]}),s.jsxs("optgroup",{label:"P Series",children:[s.jsx("option",{value:"P2S",children:"P2S"}),s.jsx("option",{value:"P1S",children:"P1S"}),s.jsx("option",{value:"P1P",children:"P1P"})]}),s.jsxs("optgroup",{label:"A1 Series",children:[s.jsx("option",{value:"A1",children:"A1"}),s.jsx("option",{value:"A1 Mini",children:"A1 Mini"})]})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Location / Group"}),s.jsx("input",{type:"text",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:r.location,onChange:l=>i({...r,location:l.target.value}),placeholder:"e.g., Workshop, Office, Basement"}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Used to group printers on the dashboard"})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"checkbox",id:"edit_auto_archive",checked:r.auto_archive,onChange:l=>i({...r,auto_archive:l.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),s.jsx("label",{htmlFor:"edit_auto_archive",className:"text-sm text-bambu-gray",children:"Auto-archive completed prints"})]}),s.jsxs("div",{className:"flex gap-3 pt-4",children:[s.jsx(Se,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),s.jsx(Se,{type:"submit",className:"flex-1",disabled:a.isPending,children:a.isPending?"Saving...":"Save Changes"})]})]})]})})})}function cje(t){const{data:e}=ct({queryKey:["printerStatus",t],queryFn:()=>fe.getPrinterStatus(t),refetchInterval:3e4});return!e?.connected}function uje({printer:t,plug:e,onPowerOn:n,isPowering:r}){const i=cje(t.id),{data:a}=ct({queryKey:["smartPlugStatus",e.id],queryFn:()=>fe.getSmartPlugStatus(e.id),refetchInterval:1e4});return i?s.jsxs("div",{className:"flex items-center justify-between px-3 py-2 hover:bg-gray-100 dark:hover:bg-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("span",{className:"text-sm text-gray-900 dark:text-white truncate",children:t.name}),a&&s.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${a.state==="ON"?"bg-bambu-green/20 text-bambu-green":"bg-red-500/20 text-red-400"}`,children:a.state||"?"})]}),s.jsxs("button",{onClick:()=>n(e.id),disabled:r||a?.state==="ON",className:`px-2 py-1 text-xs rounded transition-colors flex items-center gap-1 ${a?.state==="ON"?"bg-bambu-green/20 text-bambu-green cursor-default":"bg-bambu-green/20 text-bambu-green hover:bg-bambu-green hover:text-white"}`,children:[s.jsx(gu,{className:"w-3 h-3"}),r?"...":"On"]})]}):null}function dje(){const[t,e]=w.useState(!1),[n,r]=w.useState(()=>localStorage.getItem("hideDisconnectedPrinters")==="true"),[i,a]=w.useState(!1),[o,l]=w.useState(null),[c,u]=w.useState(()=>localStorage.getItem("printerSortBy")||"name"),[d,f]=w.useState(()=>localStorage.getItem("printerSortAsc")!=="false"),[m,g]=w.useState(()=>{const G=localStorage.getItem("printerCardSize");return G?parseInt(G,10):2}),x=m===1?"compact":"expanded",y=sn(),[b,v]=w.useState(()=>{const G=localStorage.getItem("openEmbeddedCameras");if(G)try{const oe=JSON.parse(G);return new Map(oe.map(se=>[se.id,se]))}catch{return new Map}return new Map});w.useEffect(()=>{const G=Array.from(b.values());G.length>0?localStorage.setItem("openEmbeddedCameras",JSON.stringify(G)):localStorage.removeItem("openEmbeddedCameras")},[b]);const{data:N,isLoading:S}=ct({queryKey:["printers"],queryFn:fe.getPrinters}),{data:E}=ct({queryKey:["settings"],queryFn:fe.getSettings});w.useEffect(()=>{E?.camera_view_mode==="window"&&b.size>0&&v(new Map)},[E?.camera_view_mode,b.size]);const{data:T}=ct({queryKey:["smart-plugs"],queryFn:fe.getSmartPlugs}),{data:C}=ct({queryKey:["maintenanceOverview"],queryFn:fe.getMaintenanceOverview,staleTime:60*1e3}),{data:A}=ct({queryKey:["spoolman-status"],queryFn:fe.getSpoolmanStatus,staleTime:60*1e3}),D=A?.enabled&&A?.connected,{data:k}=ct({queryKey:["unlinked-spools"],queryFn:fe.getUnlinkedSpools,enabled:!!D,staleTime:30*1e3}),R=k&&k.length>0,F=C?.reduce((G,oe)=>(G[oe.printer_id]={due_count:oe.due_count,warning_count:oe.warning_count,total_print_hours:oe.total_print_hours},G),{})||{},O=T?.reduce((G,oe)=>(oe.printer_id&&(G[oe.printer_id]=oe),G),{})||{},X=ht({mutationFn:fe.createPrinter,onSuccess:()=>{y.invalidateQueries({queryKey:["printers"]}),y.invalidateQueries({queryKey:["maintenanceOverview"]}),e(!1)}}),j=ht({mutationFn:G=>fe.controlSmartPlug(G,"on"),onSuccess:()=>{y.invalidateQueries({queryKey:["smart-plugs"]}),l(null)},onError:()=>{l(null)}}),W=()=>{const G=!n;r(G),localStorage.setItem("hideDisconnectedPrinters",String(G))},Y=G=>{u(G),localStorage.setItem("printerSortBy",G)},q=()=>{const G=!d;f(G),localStorage.setItem("printerSortAsc",String(G))},Z=()=>{switch(m){case 1:return"grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5";case 2:return"grid-cols-1 md:grid-cols-2 xl:grid-cols-3";case 3:return"grid-cols-1 lg:grid-cols-2";case 4:return"grid-cols-1";default:return"grid-cols-1 md:grid-cols-2 xl:grid-cols-3"}},ee=["S","M","L","XL"],ne=w.useMemo(()=>{if(!N)return[];const G=[...N];switch(c){case"name":G.sort((oe,se)=>oe.name.localeCompare(se.name));break;case"model":G.sort((oe,se)=>(oe.model||"").localeCompare(se.model||""));break;case"location":G.sort((oe,se)=>{const de=oe.location||"",me=se.location||"";return!de&&me?1:de&&!me?-1:de.localeCompare(me)||oe.name.localeCompare(se.name)});break;case"status":G.sort((oe,se)=>{const de=y.getQueryData(["printerStatus",oe.id]),me=y.getQueryData(["printerStatus",se.id]),ue=Ee=>Ee?.connected?Ee.state==="RUNNING"?0:1:2;return ue(de)-ue(me)});break}return d||G.reverse(),G},[N,c,d,y]),z=w.useMemo(()=>{if(c!=="location")return null;const G={};return ne.forEach(oe=>{const se=oe.location||"Ungrouped";G[se]||(G[se]=[]),G[se].push(oe)}),G},[c,ne]);return s.jsxs("div",{className:"p-4 md:p-8",children:[s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-2xl font-bold text-white",children:"Printers"}),s.jsx(aje,{printers:N})]}),s.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 flex-wrap",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs("select",{value:c,onChange:G=>Y(G.target.value),className:"text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg px-2 py-1.5 text-white focus:border-bambu-green focus:outline-none",children:[s.jsx("option",{value:"name",children:"Name"}),s.jsx("option",{value:"status",children:"Status"}),s.jsx("option",{value:"model",children:"Model"}),s.jsx("option",{value:"location",children:"Location"})]}),s.jsx("button",{onClick:q,className:"p-1.5 rounded-lg hover:bg-bambu-dark-tertiary transition-colors",title:d?"Sort descending":"Sort ascending",children:d?s.jsx(rg,{className:"w-4 h-4 text-bambu-gray"}):s.jsx(h0,{className:"w-4 h-4 text-bambu-gray"})})]}),s.jsx("div",{className:"flex items-center bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:ee.map((G,oe)=>{const se=oe+1,de=m===se;return s.jsx("button",{onClick:()=>{g(se),localStorage.setItem("printerCardSize",String(se))},className:`px-2 py-1.5 text-xs font-medium transition-colors ${oe===0?"rounded-l-lg":""} ${oe===ee.length-1?"rounded-r-lg":""} ${de?"bg-bambu-green text-white":"text-bambu-gray hover:bg-bambu-dark-tertiary hover:text-white"}`,title:`${G==="S"?"Small":G==="M"?"Medium":G==="L"?"Large":"Extra large"} cards`,children:G},G)})}),s.jsx("div",{className:"w-px h-6 bg-bambu-dark-tertiary"}),s.jsxs("label",{className:"flex items-center gap-2 text-sm text-bambu-gray cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:n,onChange:W,className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),"Hide offline"]}),n&&Object.keys(O).length>0&&s.jsxs("div",{className:"relative",children:[s.jsxs("button",{onClick:()=>a(!i),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm bg-white dark:bg-bambu-dark-secondary border border-gray-200 dark:border-bambu-dark-tertiary rounded-lg text-gray-600 dark:text-bambu-gray hover:text-gray-900 dark:hover:text-white hover:border-bambu-green transition-colors",children:[s.jsx(gu,{className:"w-4 h-4"}),"Power On",s.jsx(Ur,{className:`w-3 h-3 transition-transform ${i?"rotate-180":""}`})]}),i&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>a(!1)}),s.jsxs("div",{className:"absolute right-0 mt-2 w-56 bg-white dark:bg-bambu-dark-secondary border border-gray-200 dark:border-bambu-dark-tertiary rounded-lg shadow-lg z-20 py-1",children:[s.jsx("div",{className:"px-3 py-2 text-xs text-gray-500 dark:text-bambu-gray border-b border-gray-200 dark:border-bambu-dark-tertiary",children:"Offline printers with smart plugs"}),N?.filter(G=>O[G.id]).map(G=>s.jsx(uje,{printer:G,plug:O[G.id],onPowerOn:oe=>{l(oe),j.mutate(oe)},isPowering:o===O[G.id]?.id},G.id)),N?.filter(G=>O[G.id]).length===0&&s.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:"No printers with smart plugs"})]})]})]}),s.jsxs(Se,{onClick:()=>e(!0),children:[s.jsx(Jn,{className:"w-4 h-4"}),"Add Printer"]})]})]}),S?s.jsx("div",{className:"text-center py-12 text-bambu-gray",children:"Loading printers..."}):N?.length===0?s.jsx(St,{children:s.jsxs(Et,{className:"text-center py-12",children:[s.jsx("p",{className:"text-bambu-gray mb-4",children:"No printers configured yet"}),s.jsxs(Se,{onClick:()=>e(!0),children:[s.jsx(Jn,{className:"w-4 h-4"}),"Add Your First Printer"]})]})}):z?s.jsx("div",{className:"space-y-6",children:Object.entries(z).map(([G,oe])=>s.jsxs("div",{children:[s.jsxs("h2",{className:"text-lg font-semibold text-white mb-3 flex items-center gap-2",children:[s.jsx("span",{className:"w-2 h-2 rounded-full bg-bambu-green"}),G,s.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",oe.length,")"]})]}),s.jsx("div",{className:`grid gap-4 ${m>=3?"gap-6":""} ${Z()}`,children:oe.map(se=>s.jsx(uH,{printer:se,hideIfDisconnected:n,maintenanceInfo:F[se.id],viewMode:x,cardSize:m,amsThresholds:E?{humidityGood:Number(E.ams_humidity_good)||40,humidityFair:Number(E.ams_humidity_fair)||60,tempGood:Number(E.ams_temp_good)||28,tempFair:Number(E.ams_temp_fair)||35}:void 0,spoolmanEnabled:D,hasUnlinkedSpools:R,timeFormat:E?.time_format||"system",cameraViewMode:E?.camera_view_mode||"window",onOpenEmbeddedCamera:(de,me)=>v(ue=>new Map(ue).set(de,{id:de,name:me})),checkPrinterFirmware:E?.check_printer_firmware!==!1},se.id))})]},G))}):s.jsx("div",{className:`grid gap-4 ${m>=3?"gap-6":""} ${Z()}`,children:ne.map(G=>s.jsx(uH,{printer:G,hideIfDisconnected:n,maintenanceInfo:F[G.id],viewMode:x,cardSize:m,spoolmanEnabled:D,hasUnlinkedSpools:R,amsThresholds:E?{humidityGood:Number(E.ams_humidity_good)||40,humidityFair:Number(E.ams_humidity_fair)||60,tempGood:Number(E.ams_temp_good)||28,tempFair:Number(E.ams_temp_fair)||35}:void 0,timeFormat:E?.time_format||"system",cameraViewMode:E?.camera_view_mode||"window",onOpenEmbeddedCamera:(oe,se)=>v(de=>new Map(de).set(oe,{id:oe,name:se})),checkPrinterFirmware:E?.check_printer_firmware!==!1},G.id))}),t&&s.jsx(sje,{onClose:()=>e(!1),onAdd:G=>X.mutate(G),existingSerials:N?.map(G=>G.serial_number)||[]}),Array.from(b.values()).map((G,oe)=>s.jsx(Ufe,{printerId:G.id,printerName:G.name,viewerIndex:oe,onClose:()=>v(se=>{const de=new Map(se);return de.delete(G.id),de})},G.id))]})}function hje(){const t=navigator.userAgent.toLowerCase(),e=navigator.platform?.toLowerCase()||"";return t.includes("win")||e.includes("win")?"windows":t.includes("mac")||e.includes("mac")?"macos":t.includes("linux")||e.includes("linux")?"linux":"unknown"}function fje(){switch(hje()){case"windows":return"bambustudio://";case"macos":case"linux":default:return"bambustudioopen://"}}function Bc(t){const e=fje();window.location.href=`${e}${encodeURIComponent(t)}`}const vO="181",Kp={ROTATE:0,DOLLY:1,PAN:2},Up={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},mje=0,dH=1,pje=2,IZ=1,gje=2,Dc=3,Xd=0,ys=1,kl=2,eu=0,Xp=1,hH=2,fH=3,mH=4,xje=5,Gh=100,bje=101,yje=102,vje=103,_je=104,wje=200,Sje=201,Nje=202,Mje=203,iP=204,aP=205,Eje=206,Tje=207,Aje=208,Cje=209,kje=210,jje=211,Pje=212,Rje=213,Dje=214,sP=0,oP=1,lP=2,gg=3,cP=4,uP=5,dP=6,hP=7,_O=0,Oje=1,Lje=2,Rd=0,Ije=1,Fje=2,Uje=3,zje=4,Bje=5,$je=6,Hje=7,FZ=300,xg=301,bg=302,fP=303,mP=304,zN=306,pP=1e3,Wc=1001,gP=1002,qs=1003,Vje=1004,w_=1005,To=1006,NC=1007,rf=1008,Wl=1009,UZ=1010,zZ=1011,R0=1012,wO=1013,Uf=1014,qc=1015,Zg=1016,SO=1017,NO=1018,D0=1020,BZ=35902,$Z=35899,HZ=1021,VZ=1022,rl=1023,O0=1026,L0=1027,GZ=1028,MO=1029,EO=1030,TO=1031,AO=1033,X1=33776,Y1=33777,Q1=33778,Z1=33779,xP=35840,bP=35841,yP=35842,vP=35843,_P=36196,wP=37492,SP=37496,NP=37808,MP=37809,EP=37810,TP=37811,AP=37812,CP=37813,kP=37814,jP=37815,PP=37816,RP=37817,DP=37818,OP=37819,LP=37820,IP=37821,FP=36492,UP=36494,zP=36495,BP=36283,$P=36284,HP=36285,VP=36286,Gje=3200,Wje=3201,WZ=0,qje=1,xd="",bo="srgb",yg="srgb-linear",vS="linear",ur="srgb",Hm=7680,pH=519,Kje=512,Xje=513,Yje=514,qZ=515,Qje=516,Zje=517,Jje=518,e3e=519,gH=35044,xH="300 es",Dl=2e3,_S=2001;function KZ(t){for(let e=t.length-1;e>=0;--e)if(t[e]>=65535)return!0;return!1}function wS(t){return document.createElementNS("http://www.w3.org/1999/xhtml",t)}function t3e(){const t=wS("canvas");return t.style.display="block",t}const bH={};function yH(...t){const e="THREE."+t.shift();console.log(e,...t)}function mn(...t){const e="THREE."+t.shift();console.warn(e,...t)}function di(...t){const e="THREE."+t.shift();console.error(e,...t)}function I0(...t){const e=t.join(" ");e in bH||(bH[e]=!0,mn(...t))}function n3e(t,e,n){return new Promise(function(r,i){function a(){switch(t.clientWaitSync(e,t.SYNC_FLUSH_COMMANDS_BIT,0)){case t.WAIT_FAILED:i();break;case t.TIMEOUT_EXPIRED:setTimeout(a,n);break;default:r()}}setTimeout(a,n)})}let tm=class{addEventListener(e,n){this._listeners===void 0&&(this._listeners={});const r=this._listeners;r[e]===void 0&&(r[e]=[]),r[e].indexOf(n)===-1&&r[e].push(n)}hasEventListener(e,n){const r=this._listeners;return r===void 0?!1:r[e]!==void 0&&r[e].indexOf(n)!==-1}removeEventListener(e,n){const r=this._listeners;if(r===void 0)return;const i=r[e];if(i!==void 0){const a=i.indexOf(n);a!==-1&&i.splice(a,1)}}dispatchEvent(e){const n=this._listeners;if(n===void 0)return;const r=n[e.type];if(r!==void 0){e.target=this;const i=r.slice(0);for(let a=0,o=i.length;a>8&255]+Ma[t>>16&255]+Ma[t>>24&255]+"-"+Ma[e&255]+Ma[e>>8&255]+"-"+Ma[e>>16&15|64]+Ma[e>>24&255]+"-"+Ma[n&63|128]+Ma[n>>8&255]+"-"+Ma[n>>16&255]+Ma[n>>24&255]+Ma[r&255]+Ma[r>>8&255]+Ma[r>>16&255]+Ma[r>>24&255]).toLowerCase()}function Rn(t,e,n){return Math.max(e,Math.min(n,t))}function r3e(t,e){return(t%e+e)%e}function MC(t,e,n){return(1-n)*t+n*e}function sb(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return t/4294967295;case Uint16Array:return t/65535;case Uint8Array:return t/255;case Int32Array:return Math.max(t/2147483647,-1);case Int16Array:return Math.max(t/32767,-1);case Int8Array:return Math.max(t/127,-1);default:throw new Error("Invalid component type.")}}function ds(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return Math.round(t*4294967295);case Uint16Array:return Math.round(t*65535);case Uint8Array:return Math.round(t*255);case Int32Array:return Math.round(t*2147483647);case Int16Array:return Math.round(t*32767);case Int8Array:return Math.round(t*127);default:throw new Error("Invalid component type.")}}const i3e={DEG2RAD:J1};let Tn=class XZ{constructor(e=0,n=0){XZ.prototype.isVector2=!0,this.x=e,this.y=n}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,n){return this.x=e,this.y=n,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,n){switch(e){case 0:this.x=n;break;case 1:this.y=n;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,n){return this.x=e.x+n.x,this.y=e.y+n.y,this}addScaledVector(e,n){return this.x+=e.x*n,this.y+=e.y*n,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,n){return this.x=e.x-n.x,this.y=e.y-n.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){const n=this.x,r=this.y,i=e.elements;return this.x=i[0]*n+i[3]*r+i[6],this.y=i[1]*n+i[4]*r+i[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,n){return this.x=Rn(this.x,e.x,n.x),this.y=Rn(this.y,e.y,n.y),this}clampScalar(e,n){return this.x=Rn(this.x,e,n),this.y=Rn(this.y,e,n),this}clampLength(e,n){const r=this.length();return this.divideScalar(r||1).multiplyScalar(Rn(r,e,n))}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(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.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(e){const n=Math.sqrt(this.lengthSq()*e.lengthSq());if(n===0)return Math.PI/2;const r=this.dot(e)/n;return Math.acos(Rn(r,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const n=this.x-e.x,r=this.y-e.y;return n*n+r*r}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,n){return this.x+=(e.x-this.x)*n,this.y+=(e.y-this.y)*n,this}lerpVectors(e,n,r){return this.x=e.x+(n.x-e.x)*r,this.y=e.y+(n.y-e.y)*r,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,n=0){return this.x=e[n],this.y=e[n+1],this}toArray(e=[],n=0){return e[n]=this.x,e[n+1]=this.y,e}fromBufferAttribute(e,n){return this.x=e.getX(n),this.y=e.getY(n),this}rotateAround(e,n){const r=Math.cos(n),i=Math.sin(n),a=this.x-e.x,o=this.y-e.y;return this.x=a*r-o*i+e.x,this.y=a*i+o*r+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}},zf=class{constructor(e=0,n=0,r=0,i=1){this.isQuaternion=!0,this._x=e,this._y=n,this._z=r,this._w=i}static slerpFlat(e,n,r,i,a,o,l){let c=r[i+0],u=r[i+1],d=r[i+2],f=r[i+3],m=a[o+0],g=a[o+1],x=a[o+2],y=a[o+3];if(l<=0){e[n+0]=c,e[n+1]=u,e[n+2]=d,e[n+3]=f;return}if(l>=1){e[n+0]=m,e[n+1]=g,e[n+2]=x,e[n+3]=y;return}if(f!==y||c!==m||u!==g||d!==x){let b=c*m+u*g+d*x+f*y;b<0&&(m=-m,g=-g,x=-x,y=-y,b=-b);let v=1-l;if(b<.9995){const N=Math.acos(b),S=Math.sin(N);v=Math.sin(v*N)/S,l=Math.sin(l*N)/S,c=c*v+m*l,u=u*v+g*l,d=d*v+x*l,f=f*v+y*l}else{c=c*v+m*l,u=u*v+g*l,d=d*v+x*l,f=f*v+y*l;const N=1/Math.sqrt(c*c+u*u+d*d+f*f);c*=N,u*=N,d*=N,f*=N}}e[n]=c,e[n+1]=u,e[n+2]=d,e[n+3]=f}static multiplyQuaternionsFlat(e,n,r,i,a,o){const l=r[i],c=r[i+1],u=r[i+2],d=r[i+3],f=a[o],m=a[o+1],g=a[o+2],x=a[o+3];return e[n]=l*x+d*f+c*g-u*m,e[n+1]=c*x+d*m+u*f-l*g,e[n+2]=u*x+d*g+l*m-c*f,e[n+3]=d*x-l*f-c*m-u*g,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,n,r,i){return this._x=e,this._y=n,this._z=r,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,n=!0){const r=e._x,i=e._y,a=e._z,o=e._order,l=Math.cos,c=Math.sin,u=l(r/2),d=l(i/2),f=l(a/2),m=c(r/2),g=c(i/2),x=c(a/2);switch(o){case"XYZ":this._x=m*d*f+u*g*x,this._y=u*g*f-m*d*x,this._z=u*d*x+m*g*f,this._w=u*d*f-m*g*x;break;case"YXZ":this._x=m*d*f+u*g*x,this._y=u*g*f-m*d*x,this._z=u*d*x-m*g*f,this._w=u*d*f+m*g*x;break;case"ZXY":this._x=m*d*f-u*g*x,this._y=u*g*f+m*d*x,this._z=u*d*x+m*g*f,this._w=u*d*f-m*g*x;break;case"ZYX":this._x=m*d*f-u*g*x,this._y=u*g*f+m*d*x,this._z=u*d*x-m*g*f,this._w=u*d*f+m*g*x;break;case"YZX":this._x=m*d*f+u*g*x,this._y=u*g*f+m*d*x,this._z=u*d*x-m*g*f,this._w=u*d*f-m*g*x;break;case"XZY":this._x=m*d*f-u*g*x,this._y=u*g*f-m*d*x,this._z=u*d*x+m*g*f,this._w=u*d*f+m*g*x;break;default:mn("Quaternion: .setFromEuler() encountered an unknown order: "+o)}return n===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,n){const r=n/2,i=Math.sin(r);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(r),this._onChangeCallback(),this}setFromRotationMatrix(e){const n=e.elements,r=n[0],i=n[4],a=n[8],o=n[1],l=n[5],c=n[9],u=n[2],d=n[6],f=n[10],m=r+l+f;if(m>0){const g=.5/Math.sqrt(m+1);this._w=.25/g,this._x=(d-c)*g,this._y=(a-u)*g,this._z=(o-i)*g}else if(r>l&&r>f){const g=2*Math.sqrt(1+r-l-f);this._w=(d-c)/g,this._x=.25*g,this._y=(i+o)/g,this._z=(a+u)/g}else if(l>f){const g=2*Math.sqrt(1+l-r-f);this._w=(a-u)/g,this._x=(i+o)/g,this._y=.25*g,this._z=(c+d)/g}else{const g=2*Math.sqrt(1+f-r-l);this._w=(o-i)/g,this._x=(a+u)/g,this._y=(c+d)/g,this._z=.25*g}return this._onChangeCallback(),this}setFromUnitVectors(e,n){let r=e.dot(n)+1;return r<1e-8?(r=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=r):(this._x=0,this._y=-e.z,this._z=e.y,this._w=r)):(this._x=e.y*n.z-e.z*n.y,this._y=e.z*n.x-e.x*n.z,this._z=e.x*n.y-e.y*n.x,this._w=r),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(Rn(this.dot(e),-1,1)))}rotateTowards(e,n){const r=this.angleTo(e);if(r===0)return this;const i=Math.min(1,n/r);return this.slerp(e,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(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._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 e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,n){const r=e._x,i=e._y,a=e._z,o=e._w,l=n._x,c=n._y,u=n._z,d=n._w;return this._x=r*d+o*l+i*u-a*c,this._y=i*d+o*c+a*l-r*u,this._z=a*d+o*u+r*c-i*l,this._w=o*d-r*l-i*c-a*u,this._onChangeCallback(),this}slerp(e,n){if(n<=0)return this;if(n>=1)return this.copy(e);let r=e._x,i=e._y,a=e._z,o=e._w,l=this.dot(e);l<0&&(r=-r,i=-i,a=-a,o=-o,l=-l);let c=1-n;if(l<.9995){const u=Math.acos(l),d=Math.sin(u);c=Math.sin(c*u)/d,n=Math.sin(n*u)/d,this._x=this._x*c+r*n,this._y=this._y*c+i*n,this._z=this._z*c+a*n,this._w=this._w*c+o*n,this._onChangeCallback()}else this._x=this._x*c+r*n,this._y=this._y*c+i*n,this._z=this._z*c+a*n,this._w=this._w*c+o*n,this.normalize();return this}slerpQuaternions(e,n,r){return this.copy(e).slerp(n,r)}random(){const e=2*Math.PI*Math.random(),n=2*Math.PI*Math.random(),r=Math.random(),i=Math.sqrt(1-r),a=Math.sqrt(r);return this.set(i*Math.sin(e),i*Math.cos(e),a*Math.sin(n),a*Math.cos(n))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,n=0){return this._x=e[n],this._y=e[n+1],this._z=e[n+2],this._w=e[n+3],this._onChangeCallback(),this}toArray(e=[],n=0){return e[n]=this._x,e[n+1]=this._y,e[n+2]=this._z,e[n+3]=this._w,e}fromBufferAttribute(e,n){return this._x=e.getX(n),this._y=e.getY(n),this._z=e.getZ(n),this._w=e.getW(n),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}},ot=class YZ{constructor(e=0,n=0,r=0){YZ.prototype.isVector3=!0,this.x=e,this.y=n,this.z=r}set(e,n,r){return r===void 0&&(r=this.z),this.x=e,this.y=n,this.z=r,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,n){switch(e){case 0:this.x=n;break;case 1:this.y=n;break;case 2:this.z=n;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,n){return this.x=e.x+n.x,this.y=e.y+n.y,this.z=e.z+n.z,this}addScaledVector(e,n){return this.x+=e.x*n,this.y+=e.y*n,this.z+=e.z*n,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,n){return this.x=e.x-n.x,this.y=e.y-n.y,this.z=e.z-n.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,n){return this.x=e.x*n.x,this.y=e.y*n.y,this.z=e.z*n.z,this}applyEuler(e){return this.applyQuaternion(vH.setFromEuler(e))}applyAxisAngle(e,n){return this.applyQuaternion(vH.setFromAxisAngle(e,n))}applyMatrix3(e){const n=this.x,r=this.y,i=this.z,a=e.elements;return this.x=a[0]*n+a[3]*r+a[6]*i,this.y=a[1]*n+a[4]*r+a[7]*i,this.z=a[2]*n+a[5]*r+a[8]*i,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const n=this.x,r=this.y,i=this.z,a=e.elements,o=1/(a[3]*n+a[7]*r+a[11]*i+a[15]);return this.x=(a[0]*n+a[4]*r+a[8]*i+a[12])*o,this.y=(a[1]*n+a[5]*r+a[9]*i+a[13])*o,this.z=(a[2]*n+a[6]*r+a[10]*i+a[14])*o,this}applyQuaternion(e){const n=this.x,r=this.y,i=this.z,a=e.x,o=e.y,l=e.z,c=e.w,u=2*(o*i-l*r),d=2*(l*n-a*i),f=2*(a*r-o*n);return this.x=n+c*u+o*f-l*d,this.y=r+c*d+l*u-a*f,this.z=i+c*f+a*d-o*u,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){const n=this.x,r=this.y,i=this.z,a=e.elements;return this.x=a[0]*n+a[4]*r+a[8]*i,this.y=a[1]*n+a[5]*r+a[9]*i,this.z=a[2]*n+a[6]*r+a[10]*i,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,n){return this.x=Rn(this.x,e.x,n.x),this.y=Rn(this.y,e.y,n.y),this.z=Rn(this.z,e.z,n.z),this}clampScalar(e,n){return this.x=Rn(this.x,e,n),this.y=Rn(this.y,e,n),this.z=Rn(this.z,e,n),this}clampLength(e,n){const r=this.length();return this.divideScalar(r||1).multiplyScalar(Rn(r,e,n))}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(e){return this.x*e.x+this.y*e.y+this.z*e.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(e){return this.normalize().multiplyScalar(e)}lerp(e,n){return this.x+=(e.x-this.x)*n,this.y+=(e.y-this.y)*n,this.z+=(e.z-this.z)*n,this}lerpVectors(e,n,r){return this.x=e.x+(n.x-e.x)*r,this.y=e.y+(n.y-e.y)*r,this.z=e.z+(n.z-e.z)*r,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,n){const r=e.x,i=e.y,a=e.z,o=n.x,l=n.y,c=n.z;return this.x=i*c-a*l,this.y=a*o-r*c,this.z=r*l-i*o,this}projectOnVector(e){const n=e.lengthSq();if(n===0)return this.set(0,0,0);const r=e.dot(this)/n;return this.copy(e).multiplyScalar(r)}projectOnPlane(e){return EC.copy(this).projectOnVector(e),this.sub(EC)}reflect(e){return this.sub(EC.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){const n=Math.sqrt(this.lengthSq()*e.lengthSq());if(n===0)return Math.PI/2;const r=this.dot(e)/n;return Math.acos(Rn(r,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const n=this.x-e.x,r=this.y-e.y,i=this.z-e.z;return n*n+r*r+i*i}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,n,r){const i=Math.sin(n)*e;return this.x=i*Math.sin(r),this.y=Math.cos(n)*e,this.z=i*Math.cos(r),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,n,r){return this.x=e*Math.sin(n),this.y=r,this.z=e*Math.cos(n),this}setFromMatrixPosition(e){const n=e.elements;return this.x=n[12],this.y=n[13],this.z=n[14],this}setFromMatrixScale(e){const n=this.setFromMatrixColumn(e,0).length(),r=this.setFromMatrixColumn(e,1).length(),i=this.setFromMatrixColumn(e,2).length();return this.x=n,this.y=r,this.z=i,this}setFromMatrixColumn(e,n){return this.fromArray(e.elements,n*4)}setFromMatrix3Column(e,n){return this.fromArray(e.elements,n*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,n=0){return this.x=e[n],this.y=e[n+1],this.z=e[n+2],this}toArray(e=[],n=0){return e[n]=this.x,e[n+1]=this.y,e[n+2]=this.z,e}fromBufferAttribute(e,n){return this.x=e.getX(n),this.y=e.getY(n),this.z=e.getZ(n),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const e=Math.random()*Math.PI*2,n=Math.random()*2-1,r=Math.sqrt(1-n*n);return this.x=r*Math.cos(e),this.y=n,this.z=r*Math.sin(e),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}};const EC=new ot,vH=new zf;let Cn=class QZ{constructor(e,n,r,i,a,o,l,c,u){QZ.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,n,r,i,a,o,l,c,u)}set(e,n,r,i,a,o,l,c,u){const d=this.elements;return d[0]=e,d[1]=i,d[2]=l,d[3]=n,d[4]=a,d[5]=c,d[6]=r,d[7]=o,d[8]=u,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){const n=this.elements,r=e.elements;return n[0]=r[0],n[1]=r[1],n[2]=r[2],n[3]=r[3],n[4]=r[4],n[5]=r[5],n[6]=r[6],n[7]=r[7],n[8]=r[8],this}extractBasis(e,n,r){return e.setFromMatrix3Column(this,0),n.setFromMatrix3Column(this,1),r.setFromMatrix3Column(this,2),this}setFromMatrix4(e){const n=e.elements;return this.set(n[0],n[4],n[8],n[1],n[5],n[9],n[2],n[6],n[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,n){const r=e.elements,i=n.elements,a=this.elements,o=r[0],l=r[3],c=r[6],u=r[1],d=r[4],f=r[7],m=r[2],g=r[5],x=r[8],y=i[0],b=i[3],v=i[6],N=i[1],S=i[4],E=i[7],T=i[2],C=i[5],A=i[8];return a[0]=o*y+l*N+c*T,a[3]=o*b+l*S+c*C,a[6]=o*v+l*E+c*A,a[1]=u*y+d*N+f*T,a[4]=u*b+d*S+f*C,a[7]=u*v+d*E+f*A,a[2]=m*y+g*N+x*T,a[5]=m*b+g*S+x*C,a[8]=m*v+g*E+x*A,this}multiplyScalar(e){const n=this.elements;return n[0]*=e,n[3]*=e,n[6]*=e,n[1]*=e,n[4]*=e,n[7]*=e,n[2]*=e,n[5]*=e,n[8]*=e,this}determinant(){const e=this.elements,n=e[0],r=e[1],i=e[2],a=e[3],o=e[4],l=e[5],c=e[6],u=e[7],d=e[8];return n*o*d-n*l*u-r*a*d+r*l*c+i*a*u-i*o*c}invert(){const e=this.elements,n=e[0],r=e[1],i=e[2],a=e[3],o=e[4],l=e[5],c=e[6],u=e[7],d=e[8],f=d*o-l*u,m=l*c-d*a,g=u*a-o*c,x=n*f+r*m+i*g;if(x===0)return this.set(0,0,0,0,0,0,0,0,0);const y=1/x;return e[0]=f*y,e[1]=(i*u-d*r)*y,e[2]=(l*r-i*o)*y,e[3]=m*y,e[4]=(d*n-i*c)*y,e[5]=(i*a-l*n)*y,e[6]=g*y,e[7]=(r*c-u*n)*y,e[8]=(o*n-r*a)*y,this}transpose(){let e;const n=this.elements;return e=n[1],n[1]=n[3],n[3]=e,e=n[2],n[2]=n[6],n[6]=e,e=n[5],n[5]=n[7],n[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){const n=this.elements;return e[0]=n[0],e[1]=n[3],e[2]=n[6],e[3]=n[1],e[4]=n[4],e[5]=n[7],e[6]=n[2],e[7]=n[5],e[8]=n[8],this}setUvTransform(e,n,r,i,a,o,l){const c=Math.cos(a),u=Math.sin(a);return this.set(r*c,r*u,-r*(c*o+u*l)+o+e,-i*u,i*c,-i*(-u*o+c*l)+l+n,0,0,1),this}scale(e,n){return this.premultiply(TC.makeScale(e,n)),this}rotate(e){return this.premultiply(TC.makeRotation(-e)),this}translate(e,n){return this.premultiply(TC.makeTranslation(e,n)),this}makeTranslation(e,n){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,n,0,0,1),this}makeRotation(e){const n=Math.cos(e),r=Math.sin(e);return this.set(n,-r,0,r,n,0,0,0,1),this}makeScale(e,n){return this.set(e,0,0,0,n,0,0,0,1),this}equals(e){const n=this.elements,r=e.elements;for(let i=0;i<9;i++)if(n[i]!==r[i])return!1;return!0}fromArray(e,n=0){for(let r=0;r<9;r++)this.elements[r]=e[r+n];return this}toArray(e=[],n=0){const r=this.elements;return e[n]=r[0],e[n+1]=r[1],e[n+2]=r[2],e[n+3]=r[3],e[n+4]=r[4],e[n+5]=r[5],e[n+6]=r[6],e[n+7]=r[7],e[n+8]=r[8],e}clone(){return new this.constructor().fromArray(this.elements)}};const TC=new Cn,_H=new Cn().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),wH=new Cn().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function a3e(){const t={enabled:!0,workingColorSpace:yg,spaces:{},convert:function(i,a,o){return this.enabled===!1||a===o||!a||!o||(this.spaces[a].transfer===ur&&(i.r=tu(i.r),i.g=tu(i.g),i.b=tu(i.b)),this.spaces[a].primaries!==this.spaces[o].primaries&&(i.applyMatrix3(this.spaces[a].toXYZ),i.applyMatrix3(this.spaces[o].fromXYZ)),this.spaces[o].transfer===ur&&(i.r=Yp(i.r),i.g=Yp(i.g),i.b=Yp(i.b))),i},workingToColorSpace:function(i,a){return this.convert(i,this.workingColorSpace,a)},colorSpaceToWorking:function(i,a){return this.convert(i,a,this.workingColorSpace)},getPrimaries:function(i){return this.spaces[i].primaries},getTransfer:function(i){return i===xd?vS:this.spaces[i].transfer},getToneMappingMode:function(i){return this.spaces[i].outputColorSpaceConfig.toneMappingMode||"standard"},getLuminanceCoefficients:function(i,a=this.workingColorSpace){return i.fromArray(this.spaces[a].luminanceCoefficients)},define:function(i){Object.assign(this.spaces,i)},_getMatrix:function(i,a,o){return i.copy(this.spaces[a].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,a){return I0("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),t.workingToColorSpace(i,a)},toWorkingColorSpace:function(i,a){return I0("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),t.colorSpaceToWorking(i,a)}},e=[.64,.33,.3,.6,.15,.06],n=[.2126,.7152,.0722],r=[.3127,.329];return t.define({[yg]:{primaries:e,whitePoint:r,transfer:vS,toXYZ:_H,fromXYZ:wH,luminanceCoefficients:n,workingColorSpaceConfig:{unpackColorSpace:bo},outputColorSpaceConfig:{drawingBufferColorSpace:bo}},[bo]:{primaries:e,whitePoint:r,transfer:ur,toXYZ:_H,fromXYZ:wH,luminanceCoefficients:n,outputColorSpaceConfig:{drawingBufferColorSpace:bo}}}),t}const Kn=a3e();function tu(t){return t<.04045?t*.0773993808:Math.pow(t*.9478672986+.0521327014,2.4)}function Yp(t){return t<.0031308?t*12.92:1.055*Math.pow(t,.41666)-.055}let Vm,s3e=class{static getDataURL(e,n="image/png"){if(/^data:/i.test(e.src)||typeof HTMLCanvasElement>"u")return e.src;let r;if(e instanceof HTMLCanvasElement)r=e;else{Vm===void 0&&(Vm=wS("canvas")),Vm.width=e.width,Vm.height=e.height;const i=Vm.getContext("2d");e instanceof ImageData?i.putImageData(e,0,0):i.drawImage(e,0,0,e.width,e.height),r=Vm}return r.toDataURL(n)}static sRGBToLinear(e){if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap){const n=wS("canvas");n.width=e.width,n.height=e.height;const r=n.getContext("2d");r.drawImage(e,0,0,e.width,e.height);const i=r.getImageData(0,0,e.width,e.height),a=i.data;for(let o=0;o1),this.pmremVersion=0}get width(){return this.source.getSize(CC).x}get height(){return this.source.getSize(CC).y}get depth(){return this.source.getSize(CC).z}get image(){return this.source.data}set image(e=null){this.source.data=e}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(e,n){this.updateRanges.push({start:e,count:n})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(e){return this.name=e.name,this.source=e.source,this.mipmaps=e.mipmaps.slice(0),this.mapping=e.mapping,this.channel=e.channel,this.wrapS=e.wrapS,this.wrapT=e.wrapT,this.magFilter=e.magFilter,this.minFilter=e.minFilter,this.anisotropy=e.anisotropy,this.format=e.format,this.internalFormat=e.internalFormat,this.type=e.type,this.offset.copy(e.offset),this.repeat.copy(e.repeat),this.center.copy(e.center),this.rotation=e.rotation,this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrix.copy(e.matrix),this.generateMipmaps=e.generateMipmaps,this.premultiplyAlpha=e.premultiplyAlpha,this.flipY=e.flipY,this.unpackAlignment=e.unpackAlignment,this.colorSpace=e.colorSpace,this.renderTarget=e.renderTarget,this.isRenderTargetTexture=e.isRenderTargetTexture,this.isArrayTexture=e.isArrayTexture,this.userData=JSON.parse(JSON.stringify(e.userData)),this.needsUpdate=!0,this}setValues(e){for(const n in e){const r=e[n];if(r===void 0){mn(`Texture.setValues(): parameter '${n}' has value of undefined.`);continue}const i=this[n];if(i===void 0){mn(`Texture.setValues(): property '${n}' does not exist.`);continue}i&&r&&i.isVector2&&r.isVector2||i&&r&&i.isVector3&&r.isVector3||i&&r&&i.isMatrix3&&r.isMatrix3?i.copy(r):this[n]=r}}toJSON(e){const n=e===void 0||typeof e=="string";if(!n&&e.textures[this.uuid]!==void 0)return e.textures[this.uuid];const r={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(e).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&&(r.userData=this.userData),n||(e.textures[this.uuid]=r),r}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(e){if(this.mapping!==FZ)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case pP:e.x=e.x-Math.floor(e.x);break;case Wc:e.x=e.x<0?0:1;break;case gP:Math.abs(Math.floor(e.x)%2)===1?e.x=Math.ceil(e.x)-e.x:e.x=e.x-Math.floor(e.x);break}if(e.y<0||e.y>1)switch(this.wrapT){case pP:e.y=e.y-Math.floor(e.y);break;case Wc:e.y=e.y<0?0:1;break;case gP:Math.abs(Math.floor(e.y)%2)===1?e.y=Math.ceil(e.y)-e.y:e.y=e.y-Math.floor(e.y);break}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){e===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(e){e===!0&&this.pmremVersion++}};pl.DEFAULT_IMAGE=null;pl.DEFAULT_MAPPING=FZ;pl.DEFAULT_ANISOTROPY=1;let wi=class ZZ{constructor(e=0,n=0,r=0,i=1){ZZ.prototype.isVector4=!0,this.x=e,this.y=n,this.z=r,this.w=i}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,n,r,i){return this.x=e,this.y=n,this.z=r,this.w=i,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,n){switch(e){case 0:this.x=n;break;case 1:this.y=n;break;case 2:this.z=n;break;case 3:this.w=n;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){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: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w!==void 0?e.w:1,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,n){return this.x=e.x+n.x,this.y=e.y+n.y,this.z=e.z+n.z,this.w=e.w+n.w,this}addScaledVector(e,n){return this.x+=e.x*n,this.y+=e.y*n,this.z+=e.z*n,this.w+=e.w*n,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,n){return this.x=e.x-n.x,this.y=e.y-n.y,this.z=e.z-n.z,this.w=e.w-n.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){const n=this.x,r=this.y,i=this.z,a=this.w,o=e.elements;return this.x=o[0]*n+o[4]*r+o[8]*i+o[12]*a,this.y=o[1]*n+o[5]*r+o[9]*i+o[13]*a,this.z=o[2]*n+o[6]*r+o[10]*i+o[14]*a,this.w=o[3]*n+o[7]*r+o[11]*i+o[15]*a,this}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this.w/=e.w,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);const n=Math.sqrt(1-e.w*e.w);return n<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/n,this.y=e.y/n,this.z=e.z/n),this}setAxisAngleFromRotationMatrix(e){let n,r,i,a;const c=e.elements,u=c[0],d=c[4],f=c[8],m=c[1],g=c[5],x=c[9],y=c[2],b=c[6],v=c[10];if(Math.abs(d-m)<.01&&Math.abs(f-y)<.01&&Math.abs(x-b)<.01){if(Math.abs(d+m)<.1&&Math.abs(f+y)<.1&&Math.abs(x+b)<.1&&Math.abs(u+g+v-3)<.1)return this.set(1,0,0,0),this;n=Math.PI;const S=(u+1)/2,E=(g+1)/2,T=(v+1)/2,C=(d+m)/4,A=(f+y)/4,D=(x+b)/4;return S>E&&S>T?S<.01?(r=0,i=.707106781,a=.707106781):(r=Math.sqrt(S),i=C/r,a=A/r):E>T?E<.01?(r=.707106781,i=0,a=.707106781):(i=Math.sqrt(E),r=C/i,a=D/i):T<.01?(r=.707106781,i=.707106781,a=0):(a=Math.sqrt(T),r=A/a,i=D/a),this.set(r,i,a,n),this}let N=Math.sqrt((b-x)*(b-x)+(f-y)*(f-y)+(m-d)*(m-d));return Math.abs(N)<.001&&(N=1),this.x=(b-x)/N,this.y=(f-y)/N,this.z=(m-d)/N,this.w=Math.acos((u+g+v-1)/2),this}setFromMatrixPosition(e){const n=e.elements;return this.x=n[12],this.y=n[13],this.z=n[14],this.w=n[15],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,n){return this.x=Rn(this.x,e.x,n.x),this.y=Rn(this.y,e.y,n.y),this.z=Rn(this.z,e.z,n.z),this.w=Rn(this.w,e.w,n.w),this}clampScalar(e,n){return this.x=Rn(this.x,e,n),this.y=Rn(this.y,e,n),this.z=Rn(this.z,e,n),this.w=Rn(this.w,e,n),this}clampLength(e,n){const r=this.length();return this.divideScalar(r||1).multiplyScalar(Rn(r,e,n))}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(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.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(e){return this.normalize().multiplyScalar(e)}lerp(e,n){return this.x+=(e.x-this.x)*n,this.y+=(e.y-this.y)*n,this.z+=(e.z-this.z)*n,this.w+=(e.w-this.w)*n,this}lerpVectors(e,n,r){return this.x=e.x+(n.x-e.x)*r,this.y=e.y+(n.y-e.y)*r,this.z=e.z+(n.z-e.z)*r,this.w=e.w+(n.w-e.w)*r,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,n=0){return this.x=e[n],this.y=e[n+1],this.z=e[n+2],this.w=e[n+3],this}toArray(e=[],n=0){return e[n]=this.x,e[n+1]=this.y,e[n+2]=this.z,e[n+3]=this.w,e}fromBufferAttribute(e,n){return this.x=e.getX(n),this.y=e.getY(n),this.z=e.getZ(n),this.w=e.getW(n),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}},c3e=class extends tm{constructor(e=1,n=1,r={}){super(),r=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:To,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1,depth:1,multiview:!1},r),this.isRenderTarget=!0,this.width=e,this.height=n,this.depth=r.depth,this.scissor=new wi(0,0,e,n),this.scissorTest=!1,this.viewport=new wi(0,0,e,n);const i={width:e,height:n,depth:r.depth},a=new pl(i);this.textures=[];const o=r.count;for(let l=0;l1);this.dispose()}this.viewport.set(0,0,e,n),this.scissor.set(0,0,e,n)}clone(){return new this.constructor().copy(this)}copy(e){this.width=e.width,this.height=e.height,this.depth=e.depth,this.scissor.copy(e.scissor),this.scissorTest=e.scissorTest,this.viewport.copy(e.viewport),this.textures.length=0;for(let n=0,r=e.textures.length;n=this.min.x&&e.x<=this.max.x&&e.y>=this.min.y&&e.y<=this.max.y&&e.z>=this.min.z&&e.z<=this.max.z}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y&&this.min.z<=e.min.z&&e.max.z<=this.max.z}getParameter(e,n){return n.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y),(e.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(e){return e.max.x>=this.min.x&&e.min.x<=this.max.x&&e.max.y>=this.min.y&&e.min.y<=this.max.y&&e.max.z>=this.min.z&&e.min.z<=this.max.z}intersectsSphere(e){return this.clampPoint(e.center,Go),Go.distanceToSquared(e.center)<=e.radius*e.radius}intersectsPlane(e){let n,r;return e.normal.x>0?(n=e.normal.x*this.min.x,r=e.normal.x*this.max.x):(n=e.normal.x*this.max.x,r=e.normal.x*this.min.x),e.normal.y>0?(n+=e.normal.y*this.min.y,r+=e.normal.y*this.max.y):(n+=e.normal.y*this.max.y,r+=e.normal.y*this.min.y),e.normal.z>0?(n+=e.normal.z*this.min.z,r+=e.normal.z*this.max.z):(n+=e.normal.z*this.max.z,r+=e.normal.z*this.min.z),n<=-e.constant&&r>=-e.constant}intersectsTriangle(e){if(this.isEmpty())return!1;this.getCenter(ob),N_.subVectors(this.max,ob),Gm.subVectors(e.a,ob),Wm.subVectors(e.b,ob),qm.subVectors(e.c,ob),Wu.subVectors(Wm,Gm),qu.subVectors(qm,Wm),Ah.subVectors(Gm,qm);let n=[0,-Wu.z,Wu.y,0,-qu.z,qu.y,0,-Ah.z,Ah.y,Wu.z,0,-Wu.x,qu.z,0,-qu.x,Ah.z,0,-Ah.x,-Wu.y,Wu.x,0,-qu.y,qu.x,0,-Ah.y,Ah.x,0];return!kC(n,Gm,Wm,qm,N_)||(n=[1,0,0,0,1,0,0,0,1],!kC(n,Gm,Wm,qm,N_))?!1:(M_.crossVectors(Wu,qu),n=[M_.x,M_.y,M_.z],kC(n,Gm,Wm,qm,N_))}clampPoint(e,n){return n.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,Go).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=this.getSize(Go).length()*.5),e}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}applyMatrix4(e){return this.isEmpty()?this:(yc[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),yc[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),yc[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),yc[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),yc[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),yc[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),yc[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),yc[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(yc),this)}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(e){return this.min.fromArray(e.min),this.max.fromArray(e.max),this}};const yc=[new ot,new ot,new ot,new ot,new ot,new ot,new ot,new ot],Go=new ot,S_=new $f,Gm=new ot,Wm=new ot,qm=new ot,Wu=new ot,qu=new ot,Ah=new ot,ob=new ot,N_=new ot,M_=new ot,Ch=new ot;function kC(t,e,n,r,i){for(let a=0,o=t.length-3;a<=o;a+=3){Ch.fromArray(t,a);const l=i.x*Math.abs(Ch.x)+i.y*Math.abs(Ch.y)+i.z*Math.abs(Ch.z),c=e.dot(Ch),u=n.dot(Ch),d=r.dot(Ch);if(Math.max(-Math.max(c,u,d),Math.min(c,u,d))>l)return!1}return!0}const d3e=new $f,lb=new ot,jC=new ot;let BN=class{constructor(e=new ot,n=-1){this.isSphere=!0,this.center=e,this.radius=n}set(e,n){return this.center.copy(e),this.radius=n,this}setFromPoints(e,n){const r=this.center;n!==void 0?r.copy(n):d3e.setFromPoints(e).getCenter(r);let i=0;for(let a=0,o=e.length;athis.radius*this.radius&&(n.sub(this.center).normalize(),n.multiplyScalar(this.radius).add(this.center)),n}getBoundingBox(e){return this.isEmpty()?(e.makeEmpty(),e):(e.set(this.center,this.center),e.expandByScalar(this.radius),e)}applyMatrix4(e){return this.center.applyMatrix4(e),this.radius=this.radius*e.getMaxScaleOnAxis(),this}translate(e){return this.center.add(e),this}expandByPoint(e){if(this.isEmpty())return this.center.copy(e),this.radius=0,this;lb.subVectors(e,this.center);const n=lb.lengthSq();if(n>this.radius*this.radius){const r=Math.sqrt(n),i=(r-this.radius)*.5;this.center.addScaledVector(lb,i/r),this.radius+=i}return this}union(e){return e.isEmpty()?this:this.isEmpty()?(this.copy(e),this):(this.center.equals(e.center)===!0?this.radius=Math.max(this.radius,e.radius):(jC.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint(lb.copy(e.center).add(jC)),this.expandByPoint(lb.copy(e.center).sub(jC))),this)}equals(e){return e.center.equals(this.center)&&e.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(e){return this.radius=e.radius,this.center.fromArray(e.center),this}};const vc=new ot,PC=new ot,E_=new ot,Ku=new ot,RC=new ot,T_=new ot,DC=new ot;let kO=class{constructor(e=new ot,n=new ot(0,0,-1)){this.origin=e,this.direction=n}set(e,n){return this.origin.copy(e),this.direction.copy(n),this}copy(e){return this.origin.copy(e.origin),this.direction.copy(e.direction),this}at(e,n){return n.copy(this.origin).addScaledVector(this.direction,e)}lookAt(e){return this.direction.copy(e).sub(this.origin).normalize(),this}recast(e){return this.origin.copy(this.at(e,vc)),this}closestPointToPoint(e,n){n.subVectors(e,this.origin);const r=n.dot(this.direction);return r<0?n.copy(this.origin):n.copy(this.origin).addScaledVector(this.direction,r)}distanceToPoint(e){return Math.sqrt(this.distanceSqToPoint(e))}distanceSqToPoint(e){const n=vc.subVectors(e,this.origin).dot(this.direction);return n<0?this.origin.distanceToSquared(e):(vc.copy(this.origin).addScaledVector(this.direction,n),vc.distanceToSquared(e))}distanceSqToSegment(e,n,r,i){PC.copy(e).add(n).multiplyScalar(.5),E_.copy(n).sub(e).normalize(),Ku.copy(this.origin).sub(PC);const a=e.distanceTo(n)*.5,o=-this.direction.dot(E_),l=Ku.dot(this.direction),c=-Ku.dot(E_),u=Ku.lengthSq(),d=Math.abs(1-o*o);let f,m,g,x;if(d>0)if(f=o*c-l,m=o*l-c,x=a*d,f>=0)if(m>=-x)if(m<=x){const y=1/d;f*=y,m*=y,g=f*(f+o*m+2*l)+m*(o*f+m+2*c)+u}else m=a,f=Math.max(0,-(o*m+l)),g=-f*f+m*(m+2*c)+u;else m=-a,f=Math.max(0,-(o*m+l)),g=-f*f+m*(m+2*c)+u;else m<=-x?(f=Math.max(0,-(-o*a+l)),m=f>0?-a:Math.min(Math.max(-a,-c),a),g=-f*f+m*(m+2*c)+u):m<=x?(f=0,m=Math.min(Math.max(-a,-c),a),g=m*(m+2*c)+u):(f=Math.max(0,-(o*a+l)),m=f>0?a:Math.min(Math.max(-a,-c),a),g=-f*f+m*(m+2*c)+u);else m=o>0?-a:a,f=Math.max(0,-(o*m+l)),g=-f*f+m*(m+2*c)+u;return r&&r.copy(this.origin).addScaledVector(this.direction,f),i&&i.copy(PC).addScaledVector(E_,m),g}intersectSphere(e,n){vc.subVectors(e.center,this.origin);const r=vc.dot(this.direction),i=vc.dot(vc)-r*r,a=e.radius*e.radius;if(i>a)return null;const o=Math.sqrt(a-i),l=r-o,c=r+o;return c<0?null:l<0?this.at(c,n):this.at(l,n)}intersectsSphere(e){return e.radius<0?!1:this.distanceSqToPoint(e.center)<=e.radius*e.radius}distanceToPlane(e){const n=e.normal.dot(this.direction);if(n===0)return e.distanceToPoint(this.origin)===0?0:null;const r=-(this.origin.dot(e.normal)+e.constant)/n;return r>=0?r:null}intersectPlane(e,n){const r=this.distanceToPlane(e);return r===null?null:this.at(r,n)}intersectsPlane(e){const n=e.distanceToPoint(this.origin);return n===0||e.normal.dot(this.direction)*n<0}intersectBox(e,n){let r,i,a,o,l,c;const u=1/this.direction.x,d=1/this.direction.y,f=1/this.direction.z,m=this.origin;return u>=0?(r=(e.min.x-m.x)*u,i=(e.max.x-m.x)*u):(r=(e.max.x-m.x)*u,i=(e.min.x-m.x)*u),d>=0?(a=(e.min.y-m.y)*d,o=(e.max.y-m.y)*d):(a=(e.max.y-m.y)*d,o=(e.min.y-m.y)*d),r>o||a>i||((a>r||isNaN(r))&&(r=a),(o=0?(l=(e.min.z-m.z)*f,c=(e.max.z-m.z)*f):(l=(e.max.z-m.z)*f,c=(e.min.z-m.z)*f),r>c||l>i)||((l>r||r!==r)&&(r=l),(c=0?r:i,n)}intersectsBox(e){return this.intersectBox(e,vc)!==null}intersectTriangle(e,n,r,i,a){RC.subVectors(n,e),T_.subVectors(r,e),DC.crossVectors(RC,T_);let o=this.direction.dot(DC),l;if(o>0){if(i)return null;l=1}else if(o<0)l=-1,o=-o;else return null;Ku.subVectors(this.origin,e);const c=l*this.direction.dot(T_.crossVectors(Ku,T_));if(c<0)return null;const u=l*this.direction.dot(RC.cross(Ku));if(u<0||c+u>o)return null;const d=-l*Ku.dot(DC);return d<0?null:this.at(d/o,a)}applyMatrix4(e){return this.origin.applyMatrix4(e),this.direction.transformDirection(e),this}equals(e){return e.origin.equals(this.origin)&&e.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}},Ti=class WP{constructor(e,n,r,i,a,o,l,c,u,d,f,m,g,x,y,b){WP.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],e!==void 0&&this.set(e,n,r,i,a,o,l,c,u,d,f,m,g,x,y,b)}set(e,n,r,i,a,o,l,c,u,d,f,m,g,x,y,b){const v=this.elements;return v[0]=e,v[4]=n,v[8]=r,v[12]=i,v[1]=a,v[5]=o,v[9]=l,v[13]=c,v[2]=u,v[6]=d,v[10]=f,v[14]=m,v[3]=g,v[7]=x,v[11]=y,v[15]=b,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 WP().fromArray(this.elements)}copy(e){const n=this.elements,r=e.elements;return n[0]=r[0],n[1]=r[1],n[2]=r[2],n[3]=r[3],n[4]=r[4],n[5]=r[5],n[6]=r[6],n[7]=r[7],n[8]=r[8],n[9]=r[9],n[10]=r[10],n[11]=r[11],n[12]=r[12],n[13]=r[13],n[14]=r[14],n[15]=r[15],this}copyPosition(e){const n=this.elements,r=e.elements;return n[12]=r[12],n[13]=r[13],n[14]=r[14],this}setFromMatrix3(e){const n=e.elements;return this.set(n[0],n[3],n[6],0,n[1],n[4],n[7],0,n[2],n[5],n[8],0,0,0,0,1),this}extractBasis(e,n,r){return e.setFromMatrixColumn(this,0),n.setFromMatrixColumn(this,1),r.setFromMatrixColumn(this,2),this}makeBasis(e,n,r){return this.set(e.x,n.x,r.x,0,e.y,n.y,r.y,0,e.z,n.z,r.z,0,0,0,0,1),this}extractRotation(e){const n=this.elements,r=e.elements,i=1/Km.setFromMatrixColumn(e,0).length(),a=1/Km.setFromMatrixColumn(e,1).length(),o=1/Km.setFromMatrixColumn(e,2).length();return n[0]=r[0]*i,n[1]=r[1]*i,n[2]=r[2]*i,n[3]=0,n[4]=r[4]*a,n[5]=r[5]*a,n[6]=r[6]*a,n[7]=0,n[8]=r[8]*o,n[9]=r[9]*o,n[10]=r[10]*o,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,this}makeRotationFromEuler(e){const n=this.elements,r=e.x,i=e.y,a=e.z,o=Math.cos(r),l=Math.sin(r),c=Math.cos(i),u=Math.sin(i),d=Math.cos(a),f=Math.sin(a);if(e.order==="XYZ"){const m=o*d,g=o*f,x=l*d,y=l*f;n[0]=c*d,n[4]=-c*f,n[8]=u,n[1]=g+x*u,n[5]=m-y*u,n[9]=-l*c,n[2]=y-m*u,n[6]=x+g*u,n[10]=o*c}else if(e.order==="YXZ"){const m=c*d,g=c*f,x=u*d,y=u*f;n[0]=m+y*l,n[4]=x*l-g,n[8]=o*u,n[1]=o*f,n[5]=o*d,n[9]=-l,n[2]=g*l-x,n[6]=y+m*l,n[10]=o*c}else if(e.order==="ZXY"){const m=c*d,g=c*f,x=u*d,y=u*f;n[0]=m-y*l,n[4]=-o*f,n[8]=x+g*l,n[1]=g+x*l,n[5]=o*d,n[9]=y-m*l,n[2]=-o*u,n[6]=l,n[10]=o*c}else if(e.order==="ZYX"){const m=o*d,g=o*f,x=l*d,y=l*f;n[0]=c*d,n[4]=x*u-g,n[8]=m*u+y,n[1]=c*f,n[5]=y*u+m,n[9]=g*u-x,n[2]=-u,n[6]=l*c,n[10]=o*c}else if(e.order==="YZX"){const m=o*c,g=o*u,x=l*c,y=l*u;n[0]=c*d,n[4]=y-m*f,n[8]=x*f+g,n[1]=f,n[5]=o*d,n[9]=-l*d,n[2]=-u*d,n[6]=g*f+x,n[10]=m-y*f}else if(e.order==="XZY"){const m=o*c,g=o*u,x=l*c,y=l*u;n[0]=c*d,n[4]=-f,n[8]=u*d,n[1]=m*f+y,n[5]=o*d,n[9]=g*f-x,n[2]=x*f-g,n[6]=l*d,n[10]=y*f+m}return n[3]=0,n[7]=0,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,this}makeRotationFromQuaternion(e){return this.compose(h3e,e,f3e)}lookAt(e,n,r){const i=this.elements;return Os.subVectors(e,n),Os.lengthSq()===0&&(Os.z=1),Os.normalize(),Xu.crossVectors(r,Os),Xu.lengthSq()===0&&(Math.abs(r.z)===1?Os.x+=1e-4:Os.z+=1e-4,Os.normalize(),Xu.crossVectors(r,Os)),Xu.normalize(),A_.crossVectors(Os,Xu),i[0]=Xu.x,i[4]=A_.x,i[8]=Os.x,i[1]=Xu.y,i[5]=A_.y,i[9]=Os.y,i[2]=Xu.z,i[6]=A_.z,i[10]=Os.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,n){const r=e.elements,i=n.elements,a=this.elements,o=r[0],l=r[4],c=r[8],u=r[12],d=r[1],f=r[5],m=r[9],g=r[13],x=r[2],y=r[6],b=r[10],v=r[14],N=r[3],S=r[7],E=r[11],T=r[15],C=i[0],A=i[4],D=i[8],k=i[12],R=i[1],F=i[5],O=i[9],X=i[13],j=i[2],W=i[6],Y=i[10],q=i[14],Z=i[3],ee=i[7],ne=i[11],z=i[15];return a[0]=o*C+l*R+c*j+u*Z,a[4]=o*A+l*F+c*W+u*ee,a[8]=o*D+l*O+c*Y+u*ne,a[12]=o*k+l*X+c*q+u*z,a[1]=d*C+f*R+m*j+g*Z,a[5]=d*A+f*F+m*W+g*ee,a[9]=d*D+f*O+m*Y+g*ne,a[13]=d*k+f*X+m*q+g*z,a[2]=x*C+y*R+b*j+v*Z,a[6]=x*A+y*F+b*W+v*ee,a[10]=x*D+y*O+b*Y+v*ne,a[14]=x*k+y*X+b*q+v*z,a[3]=N*C+S*R+E*j+T*Z,a[7]=N*A+S*F+E*W+T*ee,a[11]=N*D+S*O+E*Y+T*ne,a[15]=N*k+S*X+E*q+T*z,this}multiplyScalar(e){const n=this.elements;return n[0]*=e,n[4]*=e,n[8]*=e,n[12]*=e,n[1]*=e,n[5]*=e,n[9]*=e,n[13]*=e,n[2]*=e,n[6]*=e,n[10]*=e,n[14]*=e,n[3]*=e,n[7]*=e,n[11]*=e,n[15]*=e,this}determinant(){const e=this.elements,n=e[0],r=e[4],i=e[8],a=e[12],o=e[1],l=e[5],c=e[9],u=e[13],d=e[2],f=e[6],m=e[10],g=e[14],x=e[3],y=e[7],b=e[11],v=e[15];return x*(+a*c*f-i*u*f-a*l*m+r*u*m+i*l*g-r*c*g)+y*(+n*c*g-n*u*m+a*o*m-i*o*g+i*u*d-a*c*d)+b*(+n*u*f-n*l*g-a*o*f+r*o*g+a*l*d-r*u*d)+v*(-i*l*d-n*c*f+n*l*m+i*o*f-r*o*m+r*c*d)}transpose(){const e=this.elements;let n;return n=e[1],e[1]=e[4],e[4]=n,n=e[2],e[2]=e[8],e[8]=n,n=e[6],e[6]=e[9],e[9]=n,n=e[3],e[3]=e[12],e[12]=n,n=e[7],e[7]=e[13],e[13]=n,n=e[11],e[11]=e[14],e[14]=n,this}setPosition(e,n,r){const i=this.elements;return e.isVector3?(i[12]=e.x,i[13]=e.y,i[14]=e.z):(i[12]=e,i[13]=n,i[14]=r),this}invert(){const e=this.elements,n=e[0],r=e[1],i=e[2],a=e[3],o=e[4],l=e[5],c=e[6],u=e[7],d=e[8],f=e[9],m=e[10],g=e[11],x=e[12],y=e[13],b=e[14],v=e[15],N=f*b*u-y*m*u+y*c*g-l*b*g-f*c*v+l*m*v,S=x*m*u-d*b*u-x*c*g+o*b*g+d*c*v-o*m*v,E=d*y*u-x*f*u+x*l*g-o*y*g-d*l*v+o*f*v,T=x*f*c-d*y*c-x*l*m+o*y*m+d*l*b-o*f*b,C=n*N+r*S+i*E+a*T;if(C===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const A=1/C;return e[0]=N*A,e[1]=(y*m*a-f*b*a-y*i*g+r*b*g+f*i*v-r*m*v)*A,e[2]=(l*b*a-y*c*a+y*i*u-r*b*u-l*i*v+r*c*v)*A,e[3]=(f*c*a-l*m*a-f*i*u+r*m*u+l*i*g-r*c*g)*A,e[4]=S*A,e[5]=(d*b*a-x*m*a+x*i*g-n*b*g-d*i*v+n*m*v)*A,e[6]=(x*c*a-o*b*a-x*i*u+n*b*u+o*i*v-n*c*v)*A,e[7]=(o*m*a-d*c*a+d*i*u-n*m*u-o*i*g+n*c*g)*A,e[8]=E*A,e[9]=(x*f*a-d*y*a-x*r*g+n*y*g+d*r*v-n*f*v)*A,e[10]=(o*y*a-x*l*a+x*r*u-n*y*u-o*r*v+n*l*v)*A,e[11]=(d*l*a-o*f*a-d*r*u+n*f*u+o*r*g-n*l*g)*A,e[12]=T*A,e[13]=(d*y*i-x*f*i+x*r*m-n*y*m-d*r*b+n*f*b)*A,e[14]=(x*l*i-o*y*i-x*r*c+n*y*c+o*r*b-n*l*b)*A,e[15]=(o*f*i-d*l*i+d*r*c-n*f*c-o*r*m+n*l*m)*A,this}scale(e){const n=this.elements,r=e.x,i=e.y,a=e.z;return n[0]*=r,n[4]*=i,n[8]*=a,n[1]*=r,n[5]*=i,n[9]*=a,n[2]*=r,n[6]*=i,n[10]*=a,n[3]*=r,n[7]*=i,n[11]*=a,this}getMaxScaleOnAxis(){const e=this.elements,n=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],r=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],i=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(n,r,i))}makeTranslation(e,n,r){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,n,0,0,1,r,0,0,0,1),this}makeRotationX(e){const n=Math.cos(e),r=Math.sin(e);return this.set(1,0,0,0,0,n,-r,0,0,r,n,0,0,0,0,1),this}makeRotationY(e){const n=Math.cos(e),r=Math.sin(e);return this.set(n,0,r,0,0,1,0,0,-r,0,n,0,0,0,0,1),this}makeRotationZ(e){const n=Math.cos(e),r=Math.sin(e);return this.set(n,-r,0,0,r,n,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,n){const r=Math.cos(n),i=Math.sin(n),a=1-r,o=e.x,l=e.y,c=e.z,u=a*o,d=a*l;return this.set(u*o+r,u*l-i*c,u*c+i*l,0,u*l+i*c,d*l+r,d*c-i*o,0,u*c-i*l,d*c+i*o,a*c*c+r,0,0,0,0,1),this}makeScale(e,n,r){return this.set(e,0,0,0,0,n,0,0,0,0,r,0,0,0,0,1),this}makeShear(e,n,r,i,a,o){return this.set(1,r,a,0,e,1,o,0,n,i,1,0,0,0,0,1),this}compose(e,n,r){const i=this.elements,a=n._x,o=n._y,l=n._z,c=n._w,u=a+a,d=o+o,f=l+l,m=a*u,g=a*d,x=a*f,y=o*d,b=o*f,v=l*f,N=c*u,S=c*d,E=c*f,T=r.x,C=r.y,A=r.z;return i[0]=(1-(y+v))*T,i[1]=(g+E)*T,i[2]=(x-S)*T,i[3]=0,i[4]=(g-E)*C,i[5]=(1-(m+v))*C,i[6]=(b+N)*C,i[7]=0,i[8]=(x+S)*A,i[9]=(b-N)*A,i[10]=(1-(m+y))*A,i[11]=0,i[12]=e.x,i[13]=e.y,i[14]=e.z,i[15]=1,this}decompose(e,n,r){const i=this.elements;let a=Km.set(i[0],i[1],i[2]).length();const o=Km.set(i[4],i[5],i[6]).length(),l=Km.set(i[8],i[9],i[10]).length();this.determinant()<0&&(a=-a),e.x=i[12],e.y=i[13],e.z=i[14],Wo.copy(this);const u=1/a,d=1/o,f=1/l;return Wo.elements[0]*=u,Wo.elements[1]*=u,Wo.elements[2]*=u,Wo.elements[4]*=d,Wo.elements[5]*=d,Wo.elements[6]*=d,Wo.elements[8]*=f,Wo.elements[9]*=f,Wo.elements[10]*=f,n.setFromRotationMatrix(Wo),r.x=a,r.y=o,r.z=l,this}makePerspective(e,n,r,i,a,o,l=Dl,c=!1){const u=this.elements,d=2*a/(n-e),f=2*a/(r-i),m=(n+e)/(n-e),g=(r+i)/(r-i);let x,y;if(c)x=a/(o-a),y=o*a/(o-a);else if(l===Dl)x=-(o+a)/(o-a),y=-2*o*a/(o-a);else if(l===_S)x=-o/(o-a),y=-o*a/(o-a);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+l);return u[0]=d,u[4]=0,u[8]=m,u[12]=0,u[1]=0,u[5]=f,u[9]=g,u[13]=0,u[2]=0,u[6]=0,u[10]=x,u[14]=y,u[3]=0,u[7]=0,u[11]=-1,u[15]=0,this}makeOrthographic(e,n,r,i,a,o,l=Dl,c=!1){const u=this.elements,d=2/(n-e),f=2/(r-i),m=-(n+e)/(n-e),g=-(r+i)/(r-i);let x,y;if(c)x=1/(o-a),y=o/(o-a);else if(l===Dl)x=-2/(o-a),y=-(o+a)/(o-a);else if(l===_S)x=-1/(o-a),y=-a/(o-a);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+l);return u[0]=d,u[4]=0,u[8]=0,u[12]=m,u[1]=0,u[5]=f,u[9]=0,u[13]=g,u[2]=0,u[6]=0,u[10]=x,u[14]=y,u[3]=0,u[7]=0,u[11]=0,u[15]=1,this}equals(e){const n=this.elements,r=e.elements;for(let i=0;i<16;i++)if(n[i]!==r[i])return!1;return!0}fromArray(e,n=0){for(let r=0;r<16;r++)this.elements[r]=e[r+n];return this}toArray(e=[],n=0){const r=this.elements;return e[n]=r[0],e[n+1]=r[1],e[n+2]=r[2],e[n+3]=r[3],e[n+4]=r[4],e[n+5]=r[5],e[n+6]=r[6],e[n+7]=r[7],e[n+8]=r[8],e[n+9]=r[9],e[n+10]=r[10],e[n+11]=r[11],e[n+12]=r[12],e[n+13]=r[13],e[n+14]=r[14],e[n+15]=r[15],e}};const Km=new ot,Wo=new Ti,h3e=new ot(0,0,0),f3e=new ot(1,1,1),Xu=new ot,A_=new ot,Os=new ot,SH=new Ti,NH=new zf;let Yd=class eJ{constructor(e=0,n=0,r=0,i=eJ.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=n,this._z=r,this._order=i}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,n,r,i=this._order){return this._x=e,this._y=n,this._z=r,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,n=this._order,r=!0){const i=e.elements,a=i[0],o=i[4],l=i[8],c=i[1],u=i[5],d=i[9],f=i[2],m=i[6],g=i[10];switch(n){case"XYZ":this._y=Math.asin(Rn(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(-d,g),this._z=Math.atan2(-o,a)):(this._x=Math.atan2(m,u),this._z=0);break;case"YXZ":this._x=Math.asin(-Rn(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(l,g),this._z=Math.atan2(c,u)):(this._y=Math.atan2(-f,a),this._z=0);break;case"ZXY":this._x=Math.asin(Rn(m,-1,1)),Math.abs(m)<.9999999?(this._y=Math.atan2(-f,g),this._z=Math.atan2(-o,u)):(this._y=0,this._z=Math.atan2(c,a));break;case"ZYX":this._y=Math.asin(-Rn(f,-1,1)),Math.abs(f)<.9999999?(this._x=Math.atan2(m,g),this._z=Math.atan2(c,a)):(this._x=0,this._z=Math.atan2(-o,u));break;case"YZX":this._z=Math.asin(Rn(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(-d,u),this._y=Math.atan2(-f,a)):(this._x=0,this._y=Math.atan2(l,g));break;case"XZY":this._z=Math.asin(-Rn(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(m,u),this._y=Math.atan2(l,a)):(this._x=Math.atan2(-d,g),this._y=0);break;default:mn("Euler: .setFromRotationMatrix() encountered an unknown order: "+n)}return this._order=n,r===!0&&this._onChangeCallback(),this}setFromQuaternion(e,n,r){return SH.makeRotationFromQuaternion(e),this.setFromRotationMatrix(SH,n,r)}setFromVector3(e,n=this._order){return this.set(e.x,e.y,e.z,n)}reorder(e){return NH.setFromEuler(this),this.setFromQuaternion(NH,e)}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order}fromArray(e){return this._x=e[0],this._y=e[1],this._z=e[2],e[3]!==void 0&&(this._order=e[3]),this._onChangeCallback(),this}toArray(e=[],n=0){return e[n]=this._x,e[n+1]=this._y,e[n+2]=this._z,e[n+3]=this._order,e}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}};Yd.DEFAULT_ORDER="XYZ";let tJ=class{constructor(){this.mask=1}set(e){this.mask=(1<>>0}enable(e){this.mask|=1<1){for(let n=0;n1){for(let r=0;r0&&(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(l=>({...l,boundingBox:l.boundingBox?l.boundingBox.toJSON():void 0,boundingSphere:l.boundingSphere?l.boundingSphere.toJSON():void 0})),i.instanceInfo=this._instanceInfo.map(l=>({...l})),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(e),i.indirectTexture=this._indirectTexture.toJSON(e),this._colorsTexture!==null&&(i.colorsTexture=this._colorsTexture.toJSON(e)),this.boundingSphere!==null&&(i.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(i.boundingBox=this.boundingBox.toJSON()));function a(l,c){return l[c.uuid]===void 0&&(l[c.uuid]=c.toJSON(e)),c.uuid}if(this.isScene)this.background&&(this.background.isColor?i.background=this.background.toJSON():this.background.isTexture&&(i.background=this.background.toJSON(e).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(i.environment=this.environment.toJSON(e).uuid);else if(this.isMesh||this.isLine||this.isPoints){i.geometry=a(e.geometries,this.geometry);const l=this.geometry.parameters;if(l!==void 0&&l.shapes!==void 0){const c=l.shapes;if(Array.isArray(c))for(let u=0,d=c.length;u0){i.children=[];for(let l=0;l0){i.animations=[];for(let l=0;l0&&(r.geometries=l),c.length>0&&(r.materials=c),u.length>0&&(r.textures=u),d.length>0&&(r.images=d),f.length>0&&(r.shapes=f),m.length>0&&(r.skeletons=m),g.length>0&&(r.animations=g),x.length>0&&(r.nodes=x)}return r.object=i,r;function o(l){const c=[];for(const u in l){const d=l[u];delete d.metadata,c.push(d)}return c}}clone(e){return new this.constructor().copy(this,e)}copy(e,n=!0){if(this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),this.rotation.order=e.rotation.order,this.quaternion.copy(e.quaternion),this.scale.copy(e.scale),this.matrix.copy(e.matrix),this.matrixWorld.copy(e.matrixWorld),this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrixWorldAutoUpdate=e.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=e.matrixWorldNeedsUpdate,this.layers.mask=e.layers.mask,this.visible=e.visible,this.castShadow=e.castShadow,this.receiveShadow=e.receiveShadow,this.frustumCulled=e.frustumCulled,this.renderOrder=e.renderOrder,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),n===!0)for(let r=0;r0?i.multiplyScalar(1/Math.sqrt(a)):i.set(0,0,0)}static getBarycoord(e,n,r,i,a){qo.subVectors(i,n),wc.subVectors(r,n),LC.subVectors(e,n);const o=qo.dot(qo),l=qo.dot(wc),c=qo.dot(LC),u=wc.dot(wc),d=wc.dot(LC),f=o*u-l*l;if(f===0)return a.set(0,0,0),null;const m=1/f,g=(u*c-l*d)*m,x=(o*d-l*c)*m;return a.set(1-g-x,x,g)}static containsPoint(e,n,r,i){return this.getBarycoord(e,n,r,i,Sc)===null?!1:Sc.x>=0&&Sc.y>=0&&Sc.x+Sc.y<=1}static getInterpolation(e,n,r,i,a,o,l,c){return this.getBarycoord(e,n,r,i,Sc)===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(a,Sc.x),c.addScaledVector(o,Sc.y),c.addScaledVector(l,Sc.z),c)}static getInterpolatedAttribute(e,n,r,i,a,o){return zC.setScalar(0),BC.setScalar(0),$C.setScalar(0),zC.fromBufferAttribute(e,n),BC.fromBufferAttribute(e,r),$C.fromBufferAttribute(e,i),o.setScalar(0),o.addScaledVector(zC,a.x),o.addScaledVector(BC,a.y),o.addScaledVector($C,a.z),o}static isFrontFacing(e,n,r,i){return qo.subVectors(r,n),wc.subVectors(e,n),qo.cross(wc).dot(i)<0}set(e,n,r){return this.a.copy(e),this.b.copy(n),this.c.copy(r),this}setFromPointsAndIndices(e,n,r,i){return this.a.copy(e[n]),this.b.copy(e[r]),this.c.copy(e[i]),this}setFromAttributeAndIndices(e,n,r,i){return this.a.fromBufferAttribute(e,n),this.b.fromBufferAttribute(e,r),this.c.fromBufferAttribute(e,i),this}clone(){return new this.constructor().copy(this)}copy(e){return this.a.copy(e.a),this.b.copy(e.b),this.c.copy(e.c),this}getArea(){return qo.subVectors(this.c,this.b),wc.subVectors(this.a,this.b),qo.cross(wc).length()*.5}getMidpoint(e){return e.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(e){return kp.getNormal(this.a,this.b,this.c,e)}getPlane(e){return e.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(e,n){return kp.getBarycoord(e,this.a,this.b,this.c,n)}getInterpolation(e,n,r,i,a){return kp.getInterpolation(e,this.a,this.b,this.c,n,r,i,a)}containsPoint(e){return kp.containsPoint(e,this.a,this.b,this.c)}isFrontFacing(e){return kp.isFrontFacing(this.a,this.b,this.c,e)}intersectsBox(e){return e.intersectsTriangle(this)}closestPointToPoint(e,n){const r=this.a,i=this.b,a=this.c;let o,l;Qm.subVectors(i,r),Zm.subVectors(a,r),IC.subVectors(e,r);const c=Qm.dot(IC),u=Zm.dot(IC);if(c<=0&&u<=0)return n.copy(r);FC.subVectors(e,i);const d=Qm.dot(FC),f=Zm.dot(FC);if(d>=0&&f<=d)return n.copy(i);const m=c*f-d*u;if(m<=0&&c>=0&&d<=0)return o=c/(c-d),n.copy(r).addScaledVector(Qm,o);UC.subVectors(e,a);const g=Qm.dot(UC),x=Zm.dot(UC);if(x>=0&&g<=x)return n.copy(a);const y=g*u-c*x;if(y<=0&&u>=0&&x<=0)return l=u/(u-x),n.copy(r).addScaledVector(Zm,l);const b=d*x-g*f;if(b<=0&&f-d>=0&&g-x>=0)return kH.subVectors(a,i),l=(f-d)/(f-d+(g-x)),n.copy(i).addScaledVector(kH,l);const v=1/(b+y+m);return o=y*v,l=m*v,n.copy(r).addScaledVector(Qm,o).addScaledVector(Zm,l)}equals(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}};const nJ={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},Yu={h:0,s:0,l:0},k_={h:0,s:0,l:0};function HC(t,e,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+(e-t)*6*n:n<1/2?e:n<2/3?t+(e-t)*6*(2/3-n):t}let Dn=class{constructor(e,n,r){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(e,n,r)}set(e,n,r){if(n===void 0&&r===void 0){const i=e;i&&i.isColor?this.copy(i):typeof i=="number"?this.setHex(i):typeof i=="string"&&this.setStyle(i)}else this.setRGB(e,n,r);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,n=bo){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,Kn.colorSpaceToWorking(this,n),this}setRGB(e,n,r,i=Kn.workingColorSpace){return this.r=e,this.g=n,this.b=r,Kn.colorSpaceToWorking(this,i),this}setHSL(e,n,r,i=Kn.workingColorSpace){if(e=r3e(e,1),n=Rn(n,0,1),r=Rn(r,0,1),n===0)this.r=this.g=this.b=r;else{const a=r<=.5?r*(1+n):r+n-r*n,o=2*r-a;this.r=HC(o,a,e+1/3),this.g=HC(o,a,e),this.b=HC(o,a,e-1/3)}return Kn.colorSpaceToWorking(this,i),this}setStyle(e,n=bo){function r(a){a!==void 0&&parseFloat(a)<1&&mn("Color: Alpha component of "+e+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(e)){let a;const o=i[1],l=i[2];switch(o){case"rgb":case"rgba":if(a=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(l))return r(a[4]),this.setRGB(Math.min(255,parseInt(a[1],10))/255,Math.min(255,parseInt(a[2],10))/255,Math.min(255,parseInt(a[3],10))/255,n);if(a=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(l))return r(a[4]),this.setRGB(Math.min(100,parseInt(a[1],10))/100,Math.min(100,parseInt(a[2],10))/100,Math.min(100,parseInt(a[3],10))/100,n);break;case"hsl":case"hsla":if(a=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(l))return r(a[4]),this.setHSL(parseFloat(a[1])/360,parseFloat(a[2])/100,parseFloat(a[3])/100,n);break;default:mn("Color: Unknown color model "+e)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(e)){const a=i[1],o=a.length;if(o===3)return this.setRGB(parseInt(a.charAt(0),16)/15,parseInt(a.charAt(1),16)/15,parseInt(a.charAt(2),16)/15,n);if(o===6)return this.setHex(parseInt(a,16),n);mn("Color: Invalid hex color "+e)}else if(e&&e.length>0)return this.setColorName(e,n);return this}setColorName(e,n=bo){const r=nJ[e.toLowerCase()];return r!==void 0?this.setHex(r,n):mn("Color: Unknown color "+e),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}copySRGBToLinear(e){return this.r=tu(e.r),this.g=tu(e.g),this.b=tu(e.b),this}copyLinearToSRGB(e){return this.r=Yp(e.r),this.g=Yp(e.g),this.b=Yp(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=bo){return Kn.workingToColorSpace(Ea.copy(this),e),Math.round(Rn(Ea.r*255,0,255))*65536+Math.round(Rn(Ea.g*255,0,255))*256+Math.round(Rn(Ea.b*255,0,255))}getHexString(e=bo){return("000000"+this.getHex(e).toString(16)).slice(-6)}getHSL(e,n=Kn.workingColorSpace){Kn.workingToColorSpace(Ea.copy(this),n);const r=Ea.r,i=Ea.g,a=Ea.b,o=Math.max(r,i,a),l=Math.min(r,i,a);let c,u;const d=(l+o)/2;if(l===o)c=0,u=0;else{const f=o-l;switch(u=d<=.5?f/(o+l):f/(2-o-l),o){case r:c=(i-a)/f+(i0!=e>0&&this.version++,this._alphaTest=e}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(e){if(e!==void 0)for(const n in e){const r=e[n];if(r===void 0){mn(`Material: parameter '${n}' has value of undefined.`);continue}const i=this[n];if(i===void 0){mn(`Material: '${n}' is not a property of THREE.${this.type}.`);continue}i&&i.isColor?i.set(r):i&&i.isVector3&&r&&r.isVector3?i.copy(r):this[n]=r}}toJSON(e){const n=e===void 0||typeof e=="string";n&&(e={textures:{},images:{}});const r={metadata:{version:4.7,type:"Material",generator:"Material.toJSON"}};r.uuid=this.uuid,r.type=this.type,this.name!==""&&(r.name=this.name),this.color&&this.color.isColor&&(r.color=this.color.getHex()),this.roughness!==void 0&&(r.roughness=this.roughness),this.metalness!==void 0&&(r.metalness=this.metalness),this.sheen!==void 0&&(r.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(r.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(r.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(r.emissive=this.emissive.getHex()),this.emissiveIntensity!==void 0&&this.emissiveIntensity!==1&&(r.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(r.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(r.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(r.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(r.shininess=this.shininess),this.clearcoat!==void 0&&(r.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(r.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(r.clearcoatMap=this.clearcoatMap.toJSON(e).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(r.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(e).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(r.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(e).uuid,r.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(r.sheenColorMap=this.sheenColorMap.toJSON(e).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(r.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(e).uuid),this.dispersion!==void 0&&(r.dispersion=this.dispersion),this.iridescence!==void 0&&(r.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(r.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(r.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(r.iridescenceMap=this.iridescenceMap.toJSON(e).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(r.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(e).uuid),this.anisotropy!==void 0&&(r.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(r.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(r.anisotropyMap=this.anisotropyMap.toJSON(e).uuid),this.map&&this.map.isTexture&&(r.map=this.map.toJSON(e).uuid),this.matcap&&this.matcap.isTexture&&(r.matcap=this.matcap.toJSON(e).uuid),this.alphaMap&&this.alphaMap.isTexture&&(r.alphaMap=this.alphaMap.toJSON(e).uuid),this.lightMap&&this.lightMap.isTexture&&(r.lightMap=this.lightMap.toJSON(e).uuid,r.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(r.aoMap=this.aoMap.toJSON(e).uuid,r.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(r.bumpMap=this.bumpMap.toJSON(e).uuid,r.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(r.normalMap=this.normalMap.toJSON(e).uuid,r.normalMapType=this.normalMapType,r.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(r.displacementMap=this.displacementMap.toJSON(e).uuid,r.displacementScale=this.displacementScale,r.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(r.roughnessMap=this.roughnessMap.toJSON(e).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(r.metalnessMap=this.metalnessMap.toJSON(e).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(r.emissiveMap=this.emissiveMap.toJSON(e).uuid),this.specularMap&&this.specularMap.isTexture&&(r.specularMap=this.specularMap.toJSON(e).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(r.specularIntensityMap=this.specularIntensityMap.toJSON(e).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(r.specularColorMap=this.specularColorMap.toJSON(e).uuid),this.envMap&&this.envMap.isTexture&&(r.envMap=this.envMap.toJSON(e).uuid,this.combine!==void 0&&(r.combine=this.combine)),this.envMapRotation!==void 0&&(r.envMapRotation=this.envMapRotation.toArray()),this.envMapIntensity!==void 0&&(r.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(r.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(r.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(r.gradientMap=this.gradientMap.toJSON(e).uuid),this.transmission!==void 0&&(r.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(r.transmissionMap=this.transmissionMap.toJSON(e).uuid),this.thickness!==void 0&&(r.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(r.thicknessMap=this.thicknessMap.toJSON(e).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(r.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(r.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(r.size=this.size),this.shadowSide!==null&&(r.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(r.sizeAttenuation=this.sizeAttenuation),this.blending!==Xp&&(r.blending=this.blending),this.side!==Xd&&(r.side=this.side),this.vertexColors===!0&&(r.vertexColors=!0),this.opacity<1&&(r.opacity=this.opacity),this.transparent===!0&&(r.transparent=!0),this.blendSrc!==iP&&(r.blendSrc=this.blendSrc),this.blendDst!==aP&&(r.blendDst=this.blendDst),this.blendEquation!==Gh&&(r.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(r.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(r.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(r.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(r.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(r.blendAlpha=this.blendAlpha),this.depthFunc!==gg&&(r.depthFunc=this.depthFunc),this.depthTest===!1&&(r.depthTest=this.depthTest),this.depthWrite===!1&&(r.depthWrite=this.depthWrite),this.colorWrite===!1&&(r.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(r.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==pH&&(r.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(r.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(r.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==Hm&&(r.stencilFail=this.stencilFail),this.stencilZFail!==Hm&&(r.stencilZFail=this.stencilZFail),this.stencilZPass!==Hm&&(r.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(r.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(r.rotation=this.rotation),this.polygonOffset===!0&&(r.polygonOffset=!0),this.polygonOffsetFactor!==0&&(r.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(r.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(r.linewidth=this.linewidth),this.dashSize!==void 0&&(r.dashSize=this.dashSize),this.gapSize!==void 0&&(r.gapSize=this.gapSize),this.scale!==void 0&&(r.scale=this.scale),this.dithering===!0&&(r.dithering=!0),this.alphaTest>0&&(r.alphaTest=this.alphaTest),this.alphaHash===!0&&(r.alphaHash=!0),this.alphaToCoverage===!0&&(r.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(r.premultipliedAlpha=!0),this.forceSinglePass===!0&&(r.forceSinglePass=!0),this.wireframe===!0&&(r.wireframe=!0),this.wireframeLinewidth>1&&(r.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!=="round"&&(r.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!=="round"&&(r.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(r.flatShading=!0),this.visible===!1&&(r.visible=!1),this.toneMapped===!1&&(r.toneMapped=!1),this.fog===!1&&(r.fog=!1),Object.keys(this.userData).length>0&&(r.userData=this.userData);function i(a){const o=[];for(const l in a){const c=a[l];delete c.metadata,o.push(c)}return o}if(n){const a=i(e.textures),o=i(e.images);a.length>0&&(r.textures=a),o.length>0&&(r.images=o)}return r}clone(){return new this.constructor().copy(this)}copy(e){this.name=e.name,this.blending=e.blending,this.side=e.side,this.vertexColors=e.vertexColors,this.opacity=e.opacity,this.transparent=e.transparent,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.blendColor.copy(e.blendColor),this.blendAlpha=e.blendAlpha,this.depthFunc=e.depthFunc,this.depthTest=e.depthTest,this.depthWrite=e.depthWrite,this.stencilWriteMask=e.stencilWriteMask,this.stencilFunc=e.stencilFunc,this.stencilRef=e.stencilRef,this.stencilFuncMask=e.stencilFuncMask,this.stencilFail=e.stencilFail,this.stencilZFail=e.stencilZFail,this.stencilZPass=e.stencilZPass,this.stencilWrite=e.stencilWrite;const n=e.clippingPlanes;let r=null;if(n!==null){const i=n.length;r=new Array(i);for(let a=0;a!==i;++a)r[a]=n[a].clone()}return this.clippingPlanes=r,this.clipIntersection=e.clipIntersection,this.clipShadows=e.clipShadows,this.shadowSide=e.shadowSide,this.colorWrite=e.colorWrite,this.precision=e.precision,this.polygonOffset=e.polygonOffset,this.polygonOffsetFactor=e.polygonOffsetFactor,this.polygonOffsetUnits=e.polygonOffsetUnits,this.dithering=e.dithering,this.alphaTest=e.alphaTest,this.alphaHash=e.alphaHash,this.alphaToCoverage=e.alphaToCoverage,this.premultipliedAlpha=e.premultipliedAlpha,this.forceSinglePass=e.forceSinglePass,this.visible=e.visible,this.toneMapped=e.toneMapped,this.userData=JSON.parse(JSON.stringify(e.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){e===!0&&this.version++}},jO=class extends Jg{constructor(e){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new Dn(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 Yd,this.combine=_O,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}};const bi=new ot,j_=new Tn;let y3e=0,Ao=class{constructor(e,n,r=!1){if(Array.isArray(e))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:y3e++}),this.name="",this.array=e,this.itemSize=n,this.count=e!==void 0?e.length/n:0,this.normalized=r,this.usage=gH,this.updateRanges=[],this.gpuType=qc,this.version=0}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,n){this.updateRanges.push({start:e,count:n})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.name=e.name,this.array=new e.array.constructor(e.array),this.itemSize=e.itemSize,this.count=e.count,this.normalized=e.normalized,this.usage=e.usage,this.gpuType=e.gpuType,this}copyAt(e,n,r){e*=this.itemSize,r*=n.itemSize;for(let i=0,a=this.itemSize;in.count&&mn("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),n.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new $f);const e=this.attributes.position,n=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){di("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new ot(-1/0,-1/0,-1/0),new ot(1/0,1/0,1/0));return}if(e!==void 0){if(this.boundingBox.setFromBufferAttribute(e),n)for(let r=0,i=n.length;r0&&(e.userData=this.userData),this.parameters!==void 0){const c=this.parameters;for(const u in c)c[u]!==void 0&&(e[u]=c[u]);return e}e.data={attributes:{}};const n=this.index;n!==null&&(e.data.index={type:n.array.constructor.name,array:Array.prototype.slice.call(n.array)});const r=this.attributes;for(const c in r){const u=r[c];e.data.attributes[c]=u.toJSON(e.data)}const i={};let a=!1;for(const c in this.morphAttributes){const u=this.morphAttributes[c],d=[];for(let f=0,m=u.length;f0&&(i[c]=d,a=!0)}a&&(e.data.morphAttributes=i,e.data.morphTargetsRelative=this.morphTargetsRelative);const o=this.groups;o.length>0&&(e.data.groups=JSON.parse(JSON.stringify(o)));const l=this.boundingSphere;return l!==null&&(e.data.boundingSphere=l.toJSON()),e}clone(){return new this.constructor().copy(this)}copy(e){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const n={};this.name=e.name;const r=e.index;r!==null&&this.setIndex(r.clone());const i=e.attributes;for(const u in i){const d=i[u];this.setAttribute(u,d.clone(n))}const a=e.morphAttributes;for(const u in a){const d=[],f=a[u];for(let m=0,g=f.length;m0){const i=n[r[0]];if(i!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let a=0,o=i.length;a(e.far-e.near)**2))&&(jH.copy(a).invert(),kh.copy(e.ray).applyMatrix4(jH),!(r.boundingBox!==null&&kh.intersectsBox(r.boundingBox)===!1)&&this._computeIntersections(e,n,kh)))}_computeIntersections(e,n,r){let i;const a=this.geometry,o=this.material,l=a.index,c=a.attributes.position,u=a.attributes.uv,d=a.attributes.uv1,f=a.attributes.normal,m=a.groups,g=a.drawRange;if(l!==null)if(Array.isArray(o))for(let x=0,y=m.length;xn.far?null:{distance:u,point:I_.clone(),object:t}}function F_(t,e,n,r,i,a,o,l,c,u){t.getVertexPosition(l,R_),t.getVertexPosition(c,D_),t.getVertexPosition(u,O_);const d=_3e(t,e,n,r,R_,D_,O_,RH);if(d){const f=new ot;ub.getBarycoord(RH,R_,D_,O_,f),i&&(d.uv=ub.getInterpolatedAttribute(i,l,c,u,f,new Tn)),a&&(d.uv1=ub.getInterpolatedAttribute(a,l,c,u,f,new Tn)),o&&(d.normal=ub.getInterpolatedAttribute(o,l,c,u,f,new ot),d.normal.dot(r.direction)>0&&d.normal.multiplyScalar(-1));const m={a:l,b:c,c:u,normal:new ot,materialIndex:0};ub.getNormal(R_,D_,O_,m.normal),d.face=m,d.barycoord=f}return d}let PO=class sJ extends tc{constructor(e=1,n=1,r=1,i=1,a=1,o=1){super(),this.type="BoxGeometry",this.parameters={width:e,height:n,depth:r,widthSegments:i,heightSegments:a,depthSegments:o};const l=this;i=Math.floor(i),a=Math.floor(a),o=Math.floor(o);const c=[],u=[],d=[],f=[];let m=0,g=0;x("z","y","x",-1,-1,r,n,e,o,a,0),x("z","y","x",1,-1,r,n,-e,o,a,1),x("x","z","y",1,1,e,r,n,i,o,2),x("x","z","y",1,-1,e,r,-n,i,o,3),x("x","y","z",1,-1,e,n,r,i,a,4),x("x","y","z",-1,-1,e,n,-r,i,a,5),this.setIndex(c),this.setAttribute("position",new ol(u,3)),this.setAttribute("normal",new ol(d,3)),this.setAttribute("uv",new ol(f,2));function x(y,b,v,N,S,E,T,C,A,D,k){const R=E/A,F=T/D,O=E/2,X=T/2,j=C/2,W=A+1,Y=D+1;let q=0,Z=0;const ee=new ot;for(let ne=0;ne0?1:-1,d.push(ee.x,ee.y,ee.z),f.push(G/A),f.push(1-ne/D),q+=1}}for(let ne=0;neaa.mutate([je.id]),disabled:aa.isPending||(H?.layer_num??0)<=1,className:`px-4 py-2 text-xs font-medium rounded-lg transition-colors ${(H?.layer_num??0)<=1?"bg-gray-100 dark:bg-bambu-dark text-gray-400 dark:text-bambu-gray/50 cursor-not-allowed":"bg-red-100 dark:bg-red-500/20 text-red-600 dark:text-red-400 hover:bg-red-200 dark:hover:bg-red-500/30 border border-red-300 dark:border-red-500/30"}`,title:(H?.layer_num??0)<=1?"Wait for layer 2+":"Skip this object",children:"Skip"})]},je.id))})]})]}):s.jsx("div",{className:"flex items-center justify-center py-12",children:s.jsx(ut,{className:"w-5 h-5 animate-spin text-bambu-gray"})})]})]}),W&&s.jsx(Vfe,{printerName:t.name,errors:H?.hms_errors||[],onClose:()=>Y(!1)}),de&&s.jsx(Fke,{isOpen:!!de,onClose:()=>me(null),printerId:t.id,printerName:t.name,amsId:de.amsId,amsLabel:de.amsLabel,initialMode:de.mode,thresholds:a}),ue&&s.jsx(Uke,{isOpen:!!ue,onClose:()=>Ee(null),trayUuid:ue.trayUuid,trayInfo:ue.trayInfo}),pe&&s.jsx(Wke,{isOpen:!!pe,onClose:()=>Me(null),printerId:t.id,slotInfo:pe,onSuccess:()=>{m.invalidateQueries({queryKey:["slotPresets",t.id]}),m.invalidateQueries({queryKey:["printerStatus",t.id]})}}),T&&s.jsx(lje,{printer:t,onClose:()=>C(!1)}),ye&&re&&s.jsx(oje,{printer:t,firmwareInfo:re,onClose:()=>le(!1)}),Qt&&s.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>Gt(null)})]})}function sje({onClose:t,onAdd:e,existingSerials:n}){const[r,i]=w.useState({name:"",serial_number:"",ip_address:"",access_code:"",model:"",auto_archive:!0}),[a,o]=w.useState(!1),[l,c]=w.useState([]),[u,d]=w.useState(""),[f,m]=w.useState(!1),[g,x]=w.useState(!1),[y,b]=w.useState("192.168.1.0/24"),[v,N]=w.useState({scanned:0,total:0});w.useEffect(()=>{_l.getInfo().then(A=>{x(A.is_docker)}).catch(()=>{})},[]);const S=l.filter(A=>!n.includes(A.serial)),E=async()=>{d(""),c([]),o(!0),m(!1),N({scanned:0,total:0});try{if(g){await _l.startSubnetScan(y);const A=setInterval(async()=>{try{const D=await _l.getScanStatus();N({scanned:D.scanned,total:D.total});const k=await _l.getDiscoveredPrinters();c(k),D.running||(clearInterval(A),o(!1),m(!0))}catch(D){console.error("Failed to get scan status:",D)}},500)}else{await _l.startDiscovery(10);const A=setInterval(async()=>{try{const D=await _l.getDiscoveredPrinters();c(D)}catch(D){console.error("Failed to get discovered printers:",D)}},1e3);setTimeout(async()=>{clearInterval(A);try{await _l.stopDiscovery()}catch{}o(!1),m(!0);try{const D=await _l.getDiscoveredPrinters();c(D)}catch(D){console.error("Failed to get final discovered printers:",D)}},1e4)}}catch(A){console.error("Failed to start discovery:",A),d(A instanceof Error?A.message:"Failed to start discovery"),o(!1),m(!0)}},T=A=>A?{O1D:"H2D",O1E:"H2D Pro",O2D:"H2D Pro",O1C:"H2C",O1S:"H2S","BL-P001":"X1C","BL-P002":"X1","BL-P003":"X1E",C11:"P1S",C12:"P1P",C13:"P2S",N2S:"A1",N1:"A1 Mini",X1C:"X1C",X1:"X1",X1E:"X1E",P1S:"P1S",P1P:"P1P",P2S:"P2S",A1:"A1","A1 Mini":"A1 Mini",H2D:"H2D","H2D Pro":"H2D Pro",H2C:"H2C",H2S:"H2S"}[A]||A:"",C=A=>{const D=A.serial.startsWith("unknown-")?"":A.serial;i({...r,name:A.name||"",serial_number:D,ip_address:A.ip_address,model:T(A.model)}),c([])};return w.useEffect(()=>()=>{_l.stopDiscovery().catch(()=>{}),_l.stopSubnetScan().catch(()=>{})},[]),w.useEffect(()=>{const A=D=>{D.key==="Escape"&&t()};return window.addEventListener("keydown",A),()=>window.removeEventListener("keydown",A)},[t]),s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",onClick:t,children:s.jsx(St,{className:"w-full max-w-md",onClick:A=>A.stopPropagation(),children:s.jsxs(Et,{children:[s.jsx("h2",{className:"text-xl font-semibold mb-4",children:"Add Printer"}),s.jsxs("div",{className:"mb-4 pb-4 border-b border-bambu-dark-tertiary",children:[g&&s.jsxs("div",{className:"mb-3",children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Subnet to scan"}),s.jsx("input",{type:"text",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm",value:y,onChange:A=>b(A.target.value),placeholder:"192.168.1.0/24",disabled:a}),s.jsxs("p",{className:"mt-1 text-xs text-bambu-gray",children:["Docker detected. Enter your printer's subnet in CIDR notation. Requires ",s.jsx("code",{className:"text-bambu-green",children:"network_mode: host"})," in docker-compose.yml."]})]}),s.jsx(Se,{type:"button",variant:"secondary",onClick:E,disabled:a,className:"w-full",children:a?s.jsxs(s.Fragment,{children:[s.jsx(ut,{className:"w-4 h-4 animate-spin"}),g&&v.total>0?`Scanning... ${v.scanned}/${v.total}`:"Scanning..."]}):s.jsxs(s.Fragment,{children:[s.jsx(_a,{className:"w-4 h-4"}),g?"Scan Subnet for Printers":"Discover Printers on Network"]})}),u&&s.jsx("div",{className:"mt-2 text-sm text-red-400",children:u}),S.length>0&&s.jsx("div",{className:"mt-3 space-y-2 max-h-40 overflow-y-auto",children:S.map(A=>s.jsxs("div",{className:"flex items-center justify-between p-2 bg-bambu-dark rounded-lg hover:bg-bambu-dark-secondary cursor-pointer transition-colors",onClick:()=>C(A),children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("p",{className:"font-medium text-white text-sm truncate",children:A.name||A.serial}),s.jsxs("p",{className:"text-xs text-bambu-gray truncate",children:[T(A.model)||"Unknown"," • ",A.ip_address,A.serial.startsWith("unknown-")&&s.jsx("span",{className:"text-yellow-500",children:" • Serial required"})]})]}),s.jsx(Ur,{className:"w-4 h-4 text-bambu-gray -rotate-90 flex-shrink-0 ml-2"})]},A.serial))}),a&&s.jsx("p",{className:"mt-2 text-sm text-bambu-gray text-center",children:g?"Scanning subnet for Bambu printers...":"Scanning network..."}),f&&!a&&l.length===0&&s.jsxs("p",{className:"mt-2 text-sm text-bambu-gray text-center",children:["No printers found",g?" in the specified subnet":" on the network","."]}),f&&!a&&l.length>0&&S.length===0&&s.jsx("p",{className:"mt-2 text-sm text-bambu-gray text-center",children:"All discovered printers are already configured."})]}),s.jsxs("form",{onSubmit:A=>{A.preventDefault(),e(r)},className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name"}),s.jsx("input",{type:"text",required:!0,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:r.name,onChange:A=>i({...r,name:A.target.value}),placeholder:"My Printer"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"IP Address"}),s.jsx("input",{type:"text",required:!0,pattern:"\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:r.ip_address,onChange:A=>i({...r,ip_address:A.target.value}),placeholder:"192.168.1.100"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Serial Number"}),s.jsx("input",{type:"text",required:!0,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:r.serial_number,onChange:A=>i({...r,serial_number:A.target.value}),placeholder:"01P00A000000000"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Access Code"}),s.jsx("input",{type:"password",required:!0,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:r.access_code,onChange:A=>i({...r,access_code:A.target.value}),placeholder:"From printer settings"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Model (optional)"}),s.jsxs("select",{className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:r.model||"",onChange:A=>i({...r,model:A.target.value}),children:[s.jsx("option",{value:"",children:"Select model..."}),s.jsxs("optgroup",{label:"H2 Series",children:[s.jsx("option",{value:"H2C",children:"H2C"}),s.jsx("option",{value:"H2D",children:"H2D"}),s.jsx("option",{value:"H2D Pro",children:"H2D Pro"}),s.jsx("option",{value:"H2S",children:"H2S"})]}),s.jsxs("optgroup",{label:"X1 Series",children:[s.jsx("option",{value:"X1E",children:"X1E"}),s.jsx("option",{value:"X1C",children:"X1 Carbon"}),s.jsx("option",{value:"X1",children:"X1"})]}),s.jsxs("optgroup",{label:"P Series",children:[s.jsx("option",{value:"P2S",children:"P2S"}),s.jsx("option",{value:"P1S",children:"P1S"}),s.jsx("option",{value:"P1P",children:"P1P"})]}),s.jsxs("optgroup",{label:"A1 Series",children:[s.jsx("option",{value:"A1",children:"A1"}),s.jsx("option",{value:"A1 Mini",children:"A1 Mini"})]})]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"checkbox",id:"auto_archive",checked:r.auto_archive,onChange:A=>i({...r,auto_archive:A.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),s.jsx("label",{htmlFor:"auto_archive",className:"text-sm text-bambu-gray",children:"Auto-archive completed prints"})]}),s.jsxs("div",{className:"flex gap-3 pt-4",children:[s.jsx(Se,{type:"button",variant:"secondary",onClick:t,className:"flex-1",children:"Cancel"}),s.jsx(Se,{type:"submit",className:"flex-1",children:"Add Printer"})]})]})]})})})}function oje({printer:t,firmwareInfo:e,onClose:n}){const r=sn(),{showToast:i}=Gn(),[a,o]=w.useState(null),[l,c]=w.useState(!1),[u,d]=w.useState(null),{data:f,isLoading:m}=ct({queryKey:["firmwarePrepare",t.id],queryFn:()=>B1.prepareUpload(t.id),staleTime:3e4}),g=ht({mutationFn:()=>B1.startUpload(t.id),onSuccess:()=>{c(!0);const y=setInterval(async()=>{try{const b=await B1.getUploadStatus(t.id);o(b),(b.status==="complete"||b.status==="error")&&(clearInterval(y),d(null),c(!1),b.status==="complete"&&(i("Firmware uploaded! Trigger update from printer screen.","success"),r.invalidateQueries({queryKey:["firmwareUpdate",t.id]})))}catch{}},2e3);d(y)},onError:y=>{i(`Failed to start upload: ${y.message}`,"error"),c(!1)}});w.useEffect(()=>()=>{u&&clearInterval(u)},[u]);const x=()=>{o(null),g.mutate()};return s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:s.jsx(St,{className:"w-full max-w-md mx-4",children:s.jsxs(Et,{children:[s.jsxs("div",{className:"flex items-start gap-3 mb-4",children:[s.jsx("div",{className:"p-2 rounded-full bg-orange-500/20",children:s.jsx(Hr,{className:"w-5 h-5 text-orange-400"})}),s.jsxs("div",{className:"flex-1",children:[s.jsx("h3",{className:"text-lg font-semibold text-white",children:"Firmware Update"}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:t.name})]})]}),s.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3 mb-4",children:[s.jsxs("div",{className:"flex justify-between items-center text-sm",children:[s.jsx("span",{className:"text-bambu-gray",children:"Current:"}),s.jsx("span",{className:"text-white font-mono",children:e.current_version||"Unknown"})]}),s.jsxs("div",{className:"flex justify-between items-center text-sm mt-1",children:[s.jsx("span",{className:"text-bambu-gray",children:"Latest:"}),s.jsx("span",{className:"text-orange-400 font-mono",children:e.latest_version})]}),e.release_notes&&s.jsxs("details",{className:"mt-3 text-sm",children:[s.jsx("summary",{className:"text-orange-400 cursor-pointer hover:underline",children:"Release Notes"}),s.jsx("div",{className:"mt-2 text-bambu-gray text-xs max-h-40 overflow-y-auto whitespace-pre-wrap",children:e.release_notes})]})]}),m?s.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-sm mb-4",children:[s.jsx(ut,{className:"w-4 h-4 animate-spin"}),"Checking prerequisites..."]}):f&&!l&&!a?s.jsx("div",{className:"mb-4",children:f.can_proceed?s.jsxs("div",{className:"flex items-center gap-2 text-bambu-green text-sm",children:[s.jsx(Bs,{className:"w-4 h-4"}),"SD card ready. Click below to upload firmware."]}):s.jsx("div",{className:"space-y-1",children:f.errors.map((y,b)=>s.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm",children:[s.jsx(Mi,{className:"w-4 h-4 flex-shrink-0"}),y]},b))})}):null,(l||a)&&a&&s.jsxs("div",{className:"mb-4",children:[s.jsxs("div",{className:"flex items-center justify-between text-sm mb-1",children:[s.jsx("span",{className:"text-bambu-gray capitalize",children:a.status}),s.jsxs("span",{className:"text-white",children:[a.progress,"%"]})]}),s.jsx("div",{className:"w-full bg-bambu-dark-tertiary rounded-full h-2",children:s.jsx("div",{className:`h-2 rounded-full transition-all ${a.status==="error"?"bg-status-error":a.status==="complete"?"bg-status-ok":"bg-orange-500"} ${a.status==="uploading"?"animate-pulse":""}`,style:{width:`${a.progress}%`}})}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a.message}),a.error&&s.jsx("p",{className:"text-xs text-red-400 mt-1",children:a.error})]}),a?.status==="complete"&&s.jsxs("div",{className:"bg-bambu-green/10 border border-bambu-green/30 rounded-lg p-3 mb-4",children:[s.jsx("p",{className:"text-sm text-bambu-green font-medium mb-2",children:"Firmware uploaded to SD card!"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"To apply the update on your printer:"}),s.jsxs("ol",{className:"text-xs text-bambu-gray mt-1 list-decimal list-inside space-y-1",children:[s.jsxs("li",{children:["On the printer's touchscreen, go to ",s.jsx("strong",{className:"text-white",children:"Settings"})]}),s.jsxs("li",{children:["Navigate to ",s.jsx("strong",{className:"text-white",children:"Firmware"})]}),s.jsxs("li",{children:["Select ",s.jsx("strong",{className:"text-white",children:"Update from SD card"})]}),s.jsx("li",{children:"The update will take 10-20 minutes"})]})]}),s.jsxs("div",{className:"flex gap-2 justify-end",children:[s.jsx(Se,{variant:"secondary",onClick:n,children:a?.status==="complete"?"Done":"Cancel"}),f?.can_proceed&&!l&&a?.status!=="complete"&&s.jsx(Se,{onClick:x,disabled:g.isPending,children:g.isPending?s.jsxs(s.Fragment,{children:[s.jsx(ut,{className:"w-4 h-4 animate-spin mr-2"}),"Starting..."]}):s.jsxs(s.Fragment,{children:[s.jsx(Hr,{className:"w-4 h-4 mr-2"}),"Upload Firmware"]})})]})]})})})}function lje({printer:t,onClose:e}){const n=sn(),[r,i]=w.useState({name:t.name,ip_address:t.ip_address,access_code:"",model:t.model||"",location:t.location||"",auto_archive:t.auto_archive}),a=ht({mutationFn:l=>fe.updatePrinter(t.id,l),onSuccess:()=>{n.invalidateQueries({queryKey:["printers"]}),n.invalidateQueries({queryKey:["printerStatus",t.id]}),e()}});w.useEffect(()=>{const l=c=>{c.key==="Escape"&&e()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[e]);const o=l=>{l.preventDefault();const c={name:r.name,ip_address:r.ip_address,model:r.model||void 0,location:r.location||void 0,auto_archive:r.auto_archive};r.access_code&&(c.access_code=r.access_code),a.mutate(c)};return s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",onClick:e,children:s.jsx(St,{className:"w-full max-w-md",onClick:l=>l.stopPropagation(),children:s.jsxs(Et,{children:[s.jsx("h2",{className:"text-xl font-semibold mb-4",children:"Edit Printer"}),s.jsxs("form",{onSubmit:o,className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name"}),s.jsx("input",{type:"text",required:!0,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:r.name,onChange:l=>i({...r,name:l.target.value}),placeholder:"My Printer"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"IP Address"}),s.jsx("input",{type:"text",required:!0,pattern:"\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:r.ip_address,onChange:l=>i({...r,ip_address:l.target.value}),placeholder:"192.168.1.100"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Serial Number"}),s.jsx("input",{type:"text",disabled:!0,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray cursor-not-allowed",value:t.serial_number}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Serial number cannot be changed"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Access Code"}),s.jsx("input",{type:"password",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:r.access_code,onChange:l=>i({...r,access_code:l.target.value}),placeholder:"Leave empty to keep current"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Model"}),s.jsxs("select",{className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:r.model,onChange:l=>i({...r,model:l.target.value}),children:[s.jsx("option",{value:"",children:"Select model..."}),s.jsxs("optgroup",{label:"H2 Series",children:[s.jsx("option",{value:"H2C",children:"H2C"}),s.jsx("option",{value:"H2D",children:"H2D"}),s.jsx("option",{value:"H2D Pro",children:"H2D Pro"}),s.jsx("option",{value:"H2S",children:"H2S"})]}),s.jsxs("optgroup",{label:"X1 Series",children:[s.jsx("option",{value:"X1E",children:"X1E"}),s.jsx("option",{value:"X1C",children:"X1 Carbon"}),s.jsx("option",{value:"X1",children:"X1"})]}),s.jsxs("optgroup",{label:"P Series",children:[s.jsx("option",{value:"P2S",children:"P2S"}),s.jsx("option",{value:"P1S",children:"P1S"}),s.jsx("option",{value:"P1P",children:"P1P"})]}),s.jsxs("optgroup",{label:"A1 Series",children:[s.jsx("option",{value:"A1",children:"A1"}),s.jsx("option",{value:"A1 Mini",children:"A1 Mini"})]})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Location / Group"}),s.jsx("input",{type:"text",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:r.location,onChange:l=>i({...r,location:l.target.value}),placeholder:"e.g., Workshop, Office, Basement"}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Used to group printers on the dashboard"})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"checkbox",id:"edit_auto_archive",checked:r.auto_archive,onChange:l=>i({...r,auto_archive:l.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),s.jsx("label",{htmlFor:"edit_auto_archive",className:"text-sm text-bambu-gray",children:"Auto-archive completed prints"})]}),s.jsxs("div",{className:"flex gap-3 pt-4",children:[s.jsx(Se,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),s.jsx(Se,{type:"submit",className:"flex-1",disabled:a.isPending,children:a.isPending?"Saving...":"Save Changes"})]})]})]})})})}function cje(t){const{data:e}=ct({queryKey:["printerStatus",t],queryFn:()=>fe.getPrinterStatus(t),refetchInterval:3e4});return!e?.connected}function uje({printer:t,plug:e,onPowerOn:n,isPowering:r}){const i=cje(t.id),{data:a}=ct({queryKey:["smartPlugStatus",e.id],queryFn:()=>fe.getSmartPlugStatus(e.id),refetchInterval:1e4});return i?s.jsxs("div",{className:"flex items-center justify-between px-3 py-2 hover:bg-gray-100 dark:hover:bg-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("span",{className:"text-sm text-gray-900 dark:text-white truncate",children:t.name}),a&&s.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${a.state==="ON"?"bg-bambu-green/20 text-bambu-green":"bg-red-500/20 text-red-400"}`,children:a.state||"?"})]}),s.jsxs("button",{onClick:()=>n(e.id),disabled:r||a?.state==="ON",className:`px-2 py-1 text-xs rounded transition-colors flex items-center gap-1 ${a?.state==="ON"?"bg-bambu-green/20 text-bambu-green cursor-default":"bg-bambu-green/20 text-bambu-green hover:bg-bambu-green hover:text-white"}`,children:[s.jsx(gu,{className:"w-3 h-3"}),r?"...":"On"]})]}):null}function dje(){const[t,e]=w.useState(!1),[n,r]=w.useState(()=>localStorage.getItem("hideDisconnectedPrinters")==="true"),[i,a]=w.useState(!1),[o,l]=w.useState(null),[c,u]=w.useState(()=>localStorage.getItem("printerSortBy")||"name"),[d,f]=w.useState(()=>localStorage.getItem("printerSortAsc")!=="false"),[m,g]=w.useState(()=>{const G=localStorage.getItem("printerCardSize");return G?parseInt(G,10):2}),x=m===1?"compact":"expanded",y=sn(),[b,v]=w.useState(()=>{const G=localStorage.getItem("openEmbeddedCameras");if(G)try{const oe=JSON.parse(G);return new Map(oe.map(se=>[se.id,se]))}catch{return new Map}return new Map});w.useEffect(()=>{const G=Array.from(b.values());G.length>0?localStorage.setItem("openEmbeddedCameras",JSON.stringify(G)):localStorage.removeItem("openEmbeddedCameras")},[b]);const{data:N,isLoading:S}=ct({queryKey:["printers"],queryFn:fe.getPrinters}),{data:E}=ct({queryKey:["settings"],queryFn:fe.getSettings});w.useEffect(()=>{E?.camera_view_mode==="window"&&b.size>0&&v(new Map)},[E?.camera_view_mode,b.size]);const{data:T}=ct({queryKey:["smart-plugs"],queryFn:fe.getSmartPlugs}),{data:C}=ct({queryKey:["maintenanceOverview"],queryFn:fe.getMaintenanceOverview,staleTime:60*1e3}),{data:A}=ct({queryKey:["spoolman-status"],queryFn:fe.getSpoolmanStatus,staleTime:60*1e3}),D=A?.enabled&&A?.connected,{data:k}=ct({queryKey:["unlinked-spools"],queryFn:fe.getUnlinkedSpools,enabled:!!D,staleTime:30*1e3}),R=k&&k.length>0,F=C?.reduce((G,oe)=>(G[oe.printer_id]={due_count:oe.due_count,warning_count:oe.warning_count,total_print_hours:oe.total_print_hours},G),{})||{},O=T?.reduce((G,oe)=>(oe.printer_id&&(G[oe.printer_id]=oe),G),{})||{},X=ht({mutationFn:fe.createPrinter,onSuccess:()=>{y.invalidateQueries({queryKey:["printers"]}),y.invalidateQueries({queryKey:["maintenanceOverview"]}),e(!1)}}),j=ht({mutationFn:G=>fe.controlSmartPlug(G,"on"),onSuccess:()=>{y.invalidateQueries({queryKey:["smart-plugs"]}),l(null)},onError:()=>{l(null)}}),W=()=>{const G=!n;r(G),localStorage.setItem("hideDisconnectedPrinters",String(G))},Y=G=>{u(G),localStorage.setItem("printerSortBy",G)},q=()=>{const G=!d;f(G),localStorage.setItem("printerSortAsc",String(G))},Z=()=>{switch(m){case 1:return"grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5";case 2:return"grid-cols-1 md:grid-cols-2 xl:grid-cols-3";case 3:return"grid-cols-1 lg:grid-cols-2";case 4:return"grid-cols-1";default:return"grid-cols-1 md:grid-cols-2 xl:grid-cols-3"}},ee=["S","M","L","XL"],ne=w.useMemo(()=>{if(!N)return[];const G=[...N];switch(c){case"name":G.sort((oe,se)=>oe.name.localeCompare(se.name));break;case"model":G.sort((oe,se)=>(oe.model||"").localeCompare(se.model||""));break;case"location":G.sort((oe,se)=>{const de=oe.location||"",me=se.location||"";return!de&&me?1:de&&!me?-1:de.localeCompare(me)||oe.name.localeCompare(se.name)});break;case"status":G.sort((oe,se)=>{const de=y.getQueryData(["printerStatus",oe.id]),me=y.getQueryData(["printerStatus",se.id]),ue=Ee=>Ee?.connected?Ee.state==="RUNNING"?0:1:2;return ue(de)-ue(me)});break}return d||G.reverse(),G},[N,c,d,y]),z=w.useMemo(()=>{if(c!=="location")return null;const G={};return ne.forEach(oe=>{const se=oe.location||"Ungrouped";G[se]||(G[se]=[]),G[se].push(oe)}),G},[c,ne]);return s.jsxs("div",{className:"p-4 md:p-8",children:[s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-2xl font-bold text-white",children:"Printers"}),s.jsx(aje,{printers:N})]}),s.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 flex-wrap",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs("select",{value:c,onChange:G=>Y(G.target.value),className:"text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg px-2 py-1.5 text-white focus:border-bambu-green focus:outline-none",children:[s.jsx("option",{value:"name",children:"Name"}),s.jsx("option",{value:"status",children:"Status"}),s.jsx("option",{value:"model",children:"Model"}),s.jsx("option",{value:"location",children:"Location"})]}),s.jsx("button",{onClick:q,className:"p-1.5 rounded-lg hover:bg-bambu-dark-tertiary transition-colors",title:d?"Sort descending":"Sort ascending",children:d?s.jsx(rg,{className:"w-4 h-4 text-bambu-gray"}):s.jsx(h0,{className:"w-4 h-4 text-bambu-gray"})})]}),s.jsx("div",{className:"flex items-center bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:ee.map((G,oe)=>{const se=oe+1,de=m===se;return s.jsx("button",{onClick:()=>{g(se),localStorage.setItem("printerCardSize",String(se))},className:`px-2 py-1.5 text-xs font-medium transition-colors ${oe===0?"rounded-l-lg":""} ${oe===ee.length-1?"rounded-r-lg":""} ${de?"bg-bambu-green text-white":"text-bambu-gray hover:bg-bambu-dark-tertiary hover:text-white"}`,title:`${G==="S"?"Small":G==="M"?"Medium":G==="L"?"Large":"Extra large"} cards`,children:G},G)})}),s.jsx("div",{className:"w-px h-6 bg-bambu-dark-tertiary"}),s.jsxs("label",{className:"flex items-center gap-2 text-sm text-bambu-gray cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:n,onChange:W,className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),"Hide offline"]}),n&&Object.keys(O).length>0&&s.jsxs("div",{className:"relative",children:[s.jsxs("button",{onClick:()=>a(!i),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm bg-white dark:bg-bambu-dark-secondary border border-gray-200 dark:border-bambu-dark-tertiary rounded-lg text-gray-600 dark:text-bambu-gray hover:text-gray-900 dark:hover:text-white hover:border-bambu-green transition-colors",children:[s.jsx(gu,{className:"w-4 h-4"}),"Power On",s.jsx(Ur,{className:`w-3 h-3 transition-transform ${i?"rotate-180":""}`})]}),i&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>a(!1)}),s.jsxs("div",{className:"absolute right-0 mt-2 w-56 bg-white dark:bg-bambu-dark-secondary border border-gray-200 dark:border-bambu-dark-tertiary rounded-lg shadow-lg z-20 py-1",children:[s.jsx("div",{className:"px-3 py-2 text-xs text-gray-500 dark:text-bambu-gray border-b border-gray-200 dark:border-bambu-dark-tertiary",children:"Offline printers with smart plugs"}),N?.filter(G=>O[G.id]).map(G=>s.jsx(uje,{printer:G,plug:O[G.id],onPowerOn:oe=>{l(oe),j.mutate(oe)},isPowering:o===O[G.id]?.id},G.id)),N?.filter(G=>O[G.id]).length===0&&s.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:"No printers with smart plugs"})]})]})]}),s.jsxs(Se,{onClick:()=>e(!0),children:[s.jsx(Jn,{className:"w-4 h-4"}),"Add Printer"]})]})]}),S?s.jsx("div",{className:"text-center py-12 text-bambu-gray",children:"Loading printers..."}):N?.length===0?s.jsx(St,{children:s.jsxs(Et,{className:"text-center py-12",children:[s.jsx("p",{className:"text-bambu-gray mb-4",children:"No printers configured yet"}),s.jsxs(Se,{onClick:()=>e(!0),children:[s.jsx(Jn,{className:"w-4 h-4"}),"Add Your First Printer"]})]})}):z?s.jsx("div",{className:"space-y-6",children:Object.entries(z).map(([G,oe])=>s.jsxs("div",{children:[s.jsxs("h2",{className:"text-lg font-semibold text-white mb-3 flex items-center gap-2",children:[s.jsx("span",{className:"w-2 h-2 rounded-full bg-bambu-green"}),G,s.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",oe.length,")"]})]}),s.jsx("div",{className:`grid gap-4 ${m>=3?"gap-6":""} ${Z()}`,children:oe.map(se=>s.jsx(uH,{printer:se,hideIfDisconnected:n,maintenanceInfo:F[se.id],viewMode:x,cardSize:m,amsThresholds:E?{humidityGood:Number(E.ams_humidity_good)||40,humidityFair:Number(E.ams_humidity_fair)||60,tempGood:Number(E.ams_temp_good)||28,tempFair:Number(E.ams_temp_fair)||35}:void 0,spoolmanEnabled:D,hasUnlinkedSpools:R,timeFormat:E?.time_format||"system",cameraViewMode:E?.camera_view_mode||"window",onOpenEmbeddedCamera:(de,me)=>v(ue=>new Map(ue).set(de,{id:de,name:me})),checkPrinterFirmware:E?.check_printer_firmware!==!1},se.id))})]},G))}):s.jsx("div",{className:`grid gap-4 ${m>=3?"gap-6":""} ${Z()}`,children:ne.map(G=>s.jsx(uH,{printer:G,hideIfDisconnected:n,maintenanceInfo:F[G.id],viewMode:x,cardSize:m,spoolmanEnabled:D,hasUnlinkedSpools:R,amsThresholds:E?{humidityGood:Number(E.ams_humidity_good)||40,humidityFair:Number(E.ams_humidity_fair)||60,tempGood:Number(E.ams_temp_good)||28,tempFair:Number(E.ams_temp_fair)||35}:void 0,timeFormat:E?.time_format||"system",cameraViewMode:E?.camera_view_mode||"window",onOpenEmbeddedCamera:(oe,se)=>v(de=>new Map(de).set(oe,{id:oe,name:se})),checkPrinterFirmware:E?.check_printer_firmware!==!1},G.id))}),t&&s.jsx(sje,{onClose:()=>e(!1),onAdd:G=>X.mutate(G),existingSerials:N?.map(G=>G.serial_number)||[]}),Array.from(b.values()).map((G,oe)=>s.jsx(Ufe,{printerId:G.id,printerName:G.name,viewerIndex:oe,onClose:()=>v(se=>{const de=new Map(se);return de.delete(G.id),de})},G.id))]})}function hje(){const t=navigator.userAgent.toLowerCase(),e=navigator.platform?.toLowerCase()||"";return t.includes("win")||e.includes("win")?"windows":t.includes("mac")||e.includes("mac")?"macos":t.includes("linux")||e.includes("linux")?"linux":"unknown"}function fje(){switch(hje()){case"windows":return"bambustudio://";case"macos":case"linux":default:return"bambustudioopen://"}}function Bc(t){const e=fje();window.location.href=`${e}${encodeURIComponent(t)}`}const vO="181",Kp={ROTATE:0,DOLLY:1,PAN:2},Up={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},mje=0,dH=1,pje=2,IZ=1,gje=2,Dc=3,Xd=0,ys=1,kl=2,eu=0,Xp=1,hH=2,fH=3,mH=4,xje=5,Gh=100,bje=101,yje=102,vje=103,_je=104,wje=200,Sje=201,Nje=202,Mje=203,iP=204,aP=205,Eje=206,Tje=207,Aje=208,Cje=209,kje=210,jje=211,Pje=212,Rje=213,Dje=214,sP=0,oP=1,lP=2,gg=3,cP=4,uP=5,dP=6,hP=7,_O=0,Oje=1,Lje=2,Rd=0,Ije=1,Fje=2,Uje=3,zje=4,Bje=5,$je=6,Hje=7,FZ=300,xg=301,bg=302,fP=303,mP=304,zN=306,pP=1e3,Wc=1001,gP=1002,qs=1003,Vje=1004,w_=1005,To=1006,NC=1007,rf=1008,Wl=1009,UZ=1010,zZ=1011,R0=1012,wO=1013,Uf=1014,qc=1015,Zg=1016,SO=1017,NO=1018,D0=1020,BZ=35902,$Z=35899,HZ=1021,VZ=1022,rl=1023,O0=1026,L0=1027,GZ=1028,MO=1029,EO=1030,TO=1031,AO=1033,X1=33776,Y1=33777,Q1=33778,Z1=33779,xP=35840,bP=35841,yP=35842,vP=35843,_P=36196,wP=37492,SP=37496,NP=37808,MP=37809,EP=37810,TP=37811,AP=37812,CP=37813,kP=37814,jP=37815,PP=37816,RP=37817,DP=37818,OP=37819,LP=37820,IP=37821,FP=36492,UP=36494,zP=36495,BP=36283,$P=36284,HP=36285,VP=36286,Gje=3200,Wje=3201,WZ=0,qje=1,xd="",bo="srgb",yg="srgb-linear",vS="linear",ur="srgb",Hm=7680,pH=519,Kje=512,Xje=513,Yje=514,qZ=515,Qje=516,Zje=517,Jje=518,e3e=519,gH=35044,xH="300 es",Dl=2e3,_S=2001;function KZ(t){for(let e=t.length-1;e>=0;--e)if(t[e]>=65535)return!0;return!1}function wS(t){return document.createElementNS("http://www.w3.org/1999/xhtml",t)}function t3e(){const t=wS("canvas");return t.style.display="block",t}const bH={};function yH(...t){const e="THREE."+t.shift();console.log(e,...t)}function mn(...t){const e="THREE."+t.shift();console.warn(e,...t)}function di(...t){const e="THREE."+t.shift();console.error(e,...t)}function I0(...t){const e=t.join(" ");e in bH||(bH[e]=!0,mn(...t))}function n3e(t,e,n){return new Promise(function(r,i){function a(){switch(t.clientWaitSync(e,t.SYNC_FLUSH_COMMANDS_BIT,0)){case t.WAIT_FAILED:i();break;case t.TIMEOUT_EXPIRED:setTimeout(a,n);break;default:r()}}setTimeout(a,n)})}let tm=class{addEventListener(e,n){this._listeners===void 0&&(this._listeners={});const r=this._listeners;r[e]===void 0&&(r[e]=[]),r[e].indexOf(n)===-1&&r[e].push(n)}hasEventListener(e,n){const r=this._listeners;return r===void 0?!1:r[e]!==void 0&&r[e].indexOf(n)!==-1}removeEventListener(e,n){const r=this._listeners;if(r===void 0)return;const i=r[e];if(i!==void 0){const a=i.indexOf(n);a!==-1&&i.splice(a,1)}}dispatchEvent(e){const n=this._listeners;if(n===void 0)return;const r=n[e.type];if(r!==void 0){e.target=this;const i=r.slice(0);for(let a=0,o=i.length;a>8&255]+Ma[t>>16&255]+Ma[t>>24&255]+"-"+Ma[e&255]+Ma[e>>8&255]+"-"+Ma[e>>16&15|64]+Ma[e>>24&255]+"-"+Ma[n&63|128]+Ma[n>>8&255]+"-"+Ma[n>>16&255]+Ma[n>>24&255]+Ma[r&255]+Ma[r>>8&255]+Ma[r>>16&255]+Ma[r>>24&255]).toLowerCase()}function Rn(t,e,n){return Math.max(e,Math.min(n,t))}function r3e(t,e){return(t%e+e)%e}function MC(t,e,n){return(1-n)*t+n*e}function sb(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return t/4294967295;case Uint16Array:return t/65535;case Uint8Array:return t/255;case Int32Array:return Math.max(t/2147483647,-1);case Int16Array:return Math.max(t/32767,-1);case Int8Array:return Math.max(t/127,-1);default:throw new Error("Invalid component type.")}}function ds(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return Math.round(t*4294967295);case Uint16Array:return Math.round(t*65535);case Uint8Array:return Math.round(t*255);case Int32Array:return Math.round(t*2147483647);case Int16Array:return Math.round(t*32767);case Int8Array:return Math.round(t*127);default:throw new Error("Invalid component type.")}}const i3e={DEG2RAD:J1};let Tn=class XZ{constructor(e=0,n=0){XZ.prototype.isVector2=!0,this.x=e,this.y=n}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,n){return this.x=e,this.y=n,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,n){switch(e){case 0:this.x=n;break;case 1:this.y=n;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,n){return this.x=e.x+n.x,this.y=e.y+n.y,this}addScaledVector(e,n){return this.x+=e.x*n,this.y+=e.y*n,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,n){return this.x=e.x-n.x,this.y=e.y-n.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){const n=this.x,r=this.y,i=e.elements;return this.x=i[0]*n+i[3]*r+i[6],this.y=i[1]*n+i[4]*r+i[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,n){return this.x=Rn(this.x,e.x,n.x),this.y=Rn(this.y,e.y,n.y),this}clampScalar(e,n){return this.x=Rn(this.x,e,n),this.y=Rn(this.y,e,n),this}clampLength(e,n){const r=this.length();return this.divideScalar(r||1).multiplyScalar(Rn(r,e,n))}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(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.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(e){const n=Math.sqrt(this.lengthSq()*e.lengthSq());if(n===0)return Math.PI/2;const r=this.dot(e)/n;return Math.acos(Rn(r,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const n=this.x-e.x,r=this.y-e.y;return n*n+r*r}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,n){return this.x+=(e.x-this.x)*n,this.y+=(e.y-this.y)*n,this}lerpVectors(e,n,r){return this.x=e.x+(n.x-e.x)*r,this.y=e.y+(n.y-e.y)*r,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,n=0){return this.x=e[n],this.y=e[n+1],this}toArray(e=[],n=0){return e[n]=this.x,e[n+1]=this.y,e}fromBufferAttribute(e,n){return this.x=e.getX(n),this.y=e.getY(n),this}rotateAround(e,n){const r=Math.cos(n),i=Math.sin(n),a=this.x-e.x,o=this.y-e.y;return this.x=a*r-o*i+e.x,this.y=a*i+o*r+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}},zf=class{constructor(e=0,n=0,r=0,i=1){this.isQuaternion=!0,this._x=e,this._y=n,this._z=r,this._w=i}static slerpFlat(e,n,r,i,a,o,l){let c=r[i+0],u=r[i+1],d=r[i+2],f=r[i+3],m=a[o+0],g=a[o+1],x=a[o+2],y=a[o+3];if(l<=0){e[n+0]=c,e[n+1]=u,e[n+2]=d,e[n+3]=f;return}if(l>=1){e[n+0]=m,e[n+1]=g,e[n+2]=x,e[n+3]=y;return}if(f!==y||c!==m||u!==g||d!==x){let b=c*m+u*g+d*x+f*y;b<0&&(m=-m,g=-g,x=-x,y=-y,b=-b);let v=1-l;if(b<.9995){const N=Math.acos(b),S=Math.sin(N);v=Math.sin(v*N)/S,l=Math.sin(l*N)/S,c=c*v+m*l,u=u*v+g*l,d=d*v+x*l,f=f*v+y*l}else{c=c*v+m*l,u=u*v+g*l,d=d*v+x*l,f=f*v+y*l;const N=1/Math.sqrt(c*c+u*u+d*d+f*f);c*=N,u*=N,d*=N,f*=N}}e[n]=c,e[n+1]=u,e[n+2]=d,e[n+3]=f}static multiplyQuaternionsFlat(e,n,r,i,a,o){const l=r[i],c=r[i+1],u=r[i+2],d=r[i+3],f=a[o],m=a[o+1],g=a[o+2],x=a[o+3];return e[n]=l*x+d*f+c*g-u*m,e[n+1]=c*x+d*m+u*f-l*g,e[n+2]=u*x+d*g+l*m-c*f,e[n+3]=d*x-l*f-c*m-u*g,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,n,r,i){return this._x=e,this._y=n,this._z=r,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,n=!0){const r=e._x,i=e._y,a=e._z,o=e._order,l=Math.cos,c=Math.sin,u=l(r/2),d=l(i/2),f=l(a/2),m=c(r/2),g=c(i/2),x=c(a/2);switch(o){case"XYZ":this._x=m*d*f+u*g*x,this._y=u*g*f-m*d*x,this._z=u*d*x+m*g*f,this._w=u*d*f-m*g*x;break;case"YXZ":this._x=m*d*f+u*g*x,this._y=u*g*f-m*d*x,this._z=u*d*x-m*g*f,this._w=u*d*f+m*g*x;break;case"ZXY":this._x=m*d*f-u*g*x,this._y=u*g*f+m*d*x,this._z=u*d*x+m*g*f,this._w=u*d*f-m*g*x;break;case"ZYX":this._x=m*d*f-u*g*x,this._y=u*g*f+m*d*x,this._z=u*d*x-m*g*f,this._w=u*d*f+m*g*x;break;case"YZX":this._x=m*d*f+u*g*x,this._y=u*g*f+m*d*x,this._z=u*d*x-m*g*f,this._w=u*d*f-m*g*x;break;case"XZY":this._x=m*d*f-u*g*x,this._y=u*g*f-m*d*x,this._z=u*d*x+m*g*f,this._w=u*d*f+m*g*x;break;default:mn("Quaternion: .setFromEuler() encountered an unknown order: "+o)}return n===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,n){const r=n/2,i=Math.sin(r);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(r),this._onChangeCallback(),this}setFromRotationMatrix(e){const n=e.elements,r=n[0],i=n[4],a=n[8],o=n[1],l=n[5],c=n[9],u=n[2],d=n[6],f=n[10],m=r+l+f;if(m>0){const g=.5/Math.sqrt(m+1);this._w=.25/g,this._x=(d-c)*g,this._y=(a-u)*g,this._z=(o-i)*g}else if(r>l&&r>f){const g=2*Math.sqrt(1+r-l-f);this._w=(d-c)/g,this._x=.25*g,this._y=(i+o)/g,this._z=(a+u)/g}else if(l>f){const g=2*Math.sqrt(1+l-r-f);this._w=(a-u)/g,this._x=(i+o)/g,this._y=.25*g,this._z=(c+d)/g}else{const g=2*Math.sqrt(1+f-r-l);this._w=(o-i)/g,this._x=(a+u)/g,this._y=(c+d)/g,this._z=.25*g}return this._onChangeCallback(),this}setFromUnitVectors(e,n){let r=e.dot(n)+1;return r<1e-8?(r=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=r):(this._x=0,this._y=-e.z,this._z=e.y,this._w=r)):(this._x=e.y*n.z-e.z*n.y,this._y=e.z*n.x-e.x*n.z,this._z=e.x*n.y-e.y*n.x,this._w=r),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(Rn(this.dot(e),-1,1)))}rotateTowards(e,n){const r=this.angleTo(e);if(r===0)return this;const i=Math.min(1,n/r);return this.slerp(e,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(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._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 e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,n){const r=e._x,i=e._y,a=e._z,o=e._w,l=n._x,c=n._y,u=n._z,d=n._w;return this._x=r*d+o*l+i*u-a*c,this._y=i*d+o*c+a*l-r*u,this._z=a*d+o*u+r*c-i*l,this._w=o*d-r*l-i*c-a*u,this._onChangeCallback(),this}slerp(e,n){if(n<=0)return this;if(n>=1)return this.copy(e);let r=e._x,i=e._y,a=e._z,o=e._w,l=this.dot(e);l<0&&(r=-r,i=-i,a=-a,o=-o,l=-l);let c=1-n;if(l<.9995){const u=Math.acos(l),d=Math.sin(u);c=Math.sin(c*u)/d,n=Math.sin(n*u)/d,this._x=this._x*c+r*n,this._y=this._y*c+i*n,this._z=this._z*c+a*n,this._w=this._w*c+o*n,this._onChangeCallback()}else this._x=this._x*c+r*n,this._y=this._y*c+i*n,this._z=this._z*c+a*n,this._w=this._w*c+o*n,this.normalize();return this}slerpQuaternions(e,n,r){return this.copy(e).slerp(n,r)}random(){const e=2*Math.PI*Math.random(),n=2*Math.PI*Math.random(),r=Math.random(),i=Math.sqrt(1-r),a=Math.sqrt(r);return this.set(i*Math.sin(e),i*Math.cos(e),a*Math.sin(n),a*Math.cos(n))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,n=0){return this._x=e[n],this._y=e[n+1],this._z=e[n+2],this._w=e[n+3],this._onChangeCallback(),this}toArray(e=[],n=0){return e[n]=this._x,e[n+1]=this._y,e[n+2]=this._z,e[n+3]=this._w,e}fromBufferAttribute(e,n){return this._x=e.getX(n),this._y=e.getY(n),this._z=e.getZ(n),this._w=e.getW(n),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}},ot=class YZ{constructor(e=0,n=0,r=0){YZ.prototype.isVector3=!0,this.x=e,this.y=n,this.z=r}set(e,n,r){return r===void 0&&(r=this.z),this.x=e,this.y=n,this.z=r,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,n){switch(e){case 0:this.x=n;break;case 1:this.y=n;break;case 2:this.z=n;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,n){return this.x=e.x+n.x,this.y=e.y+n.y,this.z=e.z+n.z,this}addScaledVector(e,n){return this.x+=e.x*n,this.y+=e.y*n,this.z+=e.z*n,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,n){return this.x=e.x-n.x,this.y=e.y-n.y,this.z=e.z-n.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,n){return this.x=e.x*n.x,this.y=e.y*n.y,this.z=e.z*n.z,this}applyEuler(e){return this.applyQuaternion(vH.setFromEuler(e))}applyAxisAngle(e,n){return this.applyQuaternion(vH.setFromAxisAngle(e,n))}applyMatrix3(e){const n=this.x,r=this.y,i=this.z,a=e.elements;return this.x=a[0]*n+a[3]*r+a[6]*i,this.y=a[1]*n+a[4]*r+a[7]*i,this.z=a[2]*n+a[5]*r+a[8]*i,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const n=this.x,r=this.y,i=this.z,a=e.elements,o=1/(a[3]*n+a[7]*r+a[11]*i+a[15]);return this.x=(a[0]*n+a[4]*r+a[8]*i+a[12])*o,this.y=(a[1]*n+a[5]*r+a[9]*i+a[13])*o,this.z=(a[2]*n+a[6]*r+a[10]*i+a[14])*o,this}applyQuaternion(e){const n=this.x,r=this.y,i=this.z,a=e.x,o=e.y,l=e.z,c=e.w,u=2*(o*i-l*r),d=2*(l*n-a*i),f=2*(a*r-o*n);return this.x=n+c*u+o*f-l*d,this.y=r+c*d+l*u-a*f,this.z=i+c*f+a*d-o*u,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){const n=this.x,r=this.y,i=this.z,a=e.elements;return this.x=a[0]*n+a[4]*r+a[8]*i,this.y=a[1]*n+a[5]*r+a[9]*i,this.z=a[2]*n+a[6]*r+a[10]*i,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,n){return this.x=Rn(this.x,e.x,n.x),this.y=Rn(this.y,e.y,n.y),this.z=Rn(this.z,e.z,n.z),this}clampScalar(e,n){return this.x=Rn(this.x,e,n),this.y=Rn(this.y,e,n),this.z=Rn(this.z,e,n),this}clampLength(e,n){const r=this.length();return this.divideScalar(r||1).multiplyScalar(Rn(r,e,n))}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(e){return this.x*e.x+this.y*e.y+this.z*e.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(e){return this.normalize().multiplyScalar(e)}lerp(e,n){return this.x+=(e.x-this.x)*n,this.y+=(e.y-this.y)*n,this.z+=(e.z-this.z)*n,this}lerpVectors(e,n,r){return this.x=e.x+(n.x-e.x)*r,this.y=e.y+(n.y-e.y)*r,this.z=e.z+(n.z-e.z)*r,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,n){const r=e.x,i=e.y,a=e.z,o=n.x,l=n.y,c=n.z;return this.x=i*c-a*l,this.y=a*o-r*c,this.z=r*l-i*o,this}projectOnVector(e){const n=e.lengthSq();if(n===0)return this.set(0,0,0);const r=e.dot(this)/n;return this.copy(e).multiplyScalar(r)}projectOnPlane(e){return EC.copy(this).projectOnVector(e),this.sub(EC)}reflect(e){return this.sub(EC.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){const n=Math.sqrt(this.lengthSq()*e.lengthSq());if(n===0)return Math.PI/2;const r=this.dot(e)/n;return Math.acos(Rn(r,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const n=this.x-e.x,r=this.y-e.y,i=this.z-e.z;return n*n+r*r+i*i}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,n,r){const i=Math.sin(n)*e;return this.x=i*Math.sin(r),this.y=Math.cos(n)*e,this.z=i*Math.cos(r),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,n,r){return this.x=e*Math.sin(n),this.y=r,this.z=e*Math.cos(n),this}setFromMatrixPosition(e){const n=e.elements;return this.x=n[12],this.y=n[13],this.z=n[14],this}setFromMatrixScale(e){const n=this.setFromMatrixColumn(e,0).length(),r=this.setFromMatrixColumn(e,1).length(),i=this.setFromMatrixColumn(e,2).length();return this.x=n,this.y=r,this.z=i,this}setFromMatrixColumn(e,n){return this.fromArray(e.elements,n*4)}setFromMatrix3Column(e,n){return this.fromArray(e.elements,n*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,n=0){return this.x=e[n],this.y=e[n+1],this.z=e[n+2],this}toArray(e=[],n=0){return e[n]=this.x,e[n+1]=this.y,e[n+2]=this.z,e}fromBufferAttribute(e,n){return this.x=e.getX(n),this.y=e.getY(n),this.z=e.getZ(n),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const e=Math.random()*Math.PI*2,n=Math.random()*2-1,r=Math.sqrt(1-n*n);return this.x=r*Math.cos(e),this.y=n,this.z=r*Math.sin(e),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}};const EC=new ot,vH=new zf;let Cn=class QZ{constructor(e,n,r,i,a,o,l,c,u){QZ.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,n,r,i,a,o,l,c,u)}set(e,n,r,i,a,o,l,c,u){const d=this.elements;return d[0]=e,d[1]=i,d[2]=l,d[3]=n,d[4]=a,d[5]=c,d[6]=r,d[7]=o,d[8]=u,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){const n=this.elements,r=e.elements;return n[0]=r[0],n[1]=r[1],n[2]=r[2],n[3]=r[3],n[4]=r[4],n[5]=r[5],n[6]=r[6],n[7]=r[7],n[8]=r[8],this}extractBasis(e,n,r){return e.setFromMatrix3Column(this,0),n.setFromMatrix3Column(this,1),r.setFromMatrix3Column(this,2),this}setFromMatrix4(e){const n=e.elements;return this.set(n[0],n[4],n[8],n[1],n[5],n[9],n[2],n[6],n[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,n){const r=e.elements,i=n.elements,a=this.elements,o=r[0],l=r[3],c=r[6],u=r[1],d=r[4],f=r[7],m=r[2],g=r[5],x=r[8],y=i[0],b=i[3],v=i[6],N=i[1],S=i[4],E=i[7],T=i[2],C=i[5],A=i[8];return a[0]=o*y+l*N+c*T,a[3]=o*b+l*S+c*C,a[6]=o*v+l*E+c*A,a[1]=u*y+d*N+f*T,a[4]=u*b+d*S+f*C,a[7]=u*v+d*E+f*A,a[2]=m*y+g*N+x*T,a[5]=m*b+g*S+x*C,a[8]=m*v+g*E+x*A,this}multiplyScalar(e){const n=this.elements;return n[0]*=e,n[3]*=e,n[6]*=e,n[1]*=e,n[4]*=e,n[7]*=e,n[2]*=e,n[5]*=e,n[8]*=e,this}determinant(){const e=this.elements,n=e[0],r=e[1],i=e[2],a=e[3],o=e[4],l=e[5],c=e[6],u=e[7],d=e[8];return n*o*d-n*l*u-r*a*d+r*l*c+i*a*u-i*o*c}invert(){const e=this.elements,n=e[0],r=e[1],i=e[2],a=e[3],o=e[4],l=e[5],c=e[6],u=e[7],d=e[8],f=d*o-l*u,m=l*c-d*a,g=u*a-o*c,x=n*f+r*m+i*g;if(x===0)return this.set(0,0,0,0,0,0,0,0,0);const y=1/x;return e[0]=f*y,e[1]=(i*u-d*r)*y,e[2]=(l*r-i*o)*y,e[3]=m*y,e[4]=(d*n-i*c)*y,e[5]=(i*a-l*n)*y,e[6]=g*y,e[7]=(r*c-u*n)*y,e[8]=(o*n-r*a)*y,this}transpose(){let e;const n=this.elements;return e=n[1],n[1]=n[3],n[3]=e,e=n[2],n[2]=n[6],n[6]=e,e=n[5],n[5]=n[7],n[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){const n=this.elements;return e[0]=n[0],e[1]=n[3],e[2]=n[6],e[3]=n[1],e[4]=n[4],e[5]=n[7],e[6]=n[2],e[7]=n[5],e[8]=n[8],this}setUvTransform(e,n,r,i,a,o,l){const c=Math.cos(a),u=Math.sin(a);return this.set(r*c,r*u,-r*(c*o+u*l)+o+e,-i*u,i*c,-i*(-u*o+c*l)+l+n,0,0,1),this}scale(e,n){return this.premultiply(TC.makeScale(e,n)),this}rotate(e){return this.premultiply(TC.makeRotation(-e)),this}translate(e,n){return this.premultiply(TC.makeTranslation(e,n)),this}makeTranslation(e,n){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,n,0,0,1),this}makeRotation(e){const n=Math.cos(e),r=Math.sin(e);return this.set(n,-r,0,r,n,0,0,0,1),this}makeScale(e,n){return this.set(e,0,0,0,n,0,0,0,1),this}equals(e){const n=this.elements,r=e.elements;for(let i=0;i<9;i++)if(n[i]!==r[i])return!1;return!0}fromArray(e,n=0){for(let r=0;r<9;r++)this.elements[r]=e[r+n];return this}toArray(e=[],n=0){const r=this.elements;return e[n]=r[0],e[n+1]=r[1],e[n+2]=r[2],e[n+3]=r[3],e[n+4]=r[4],e[n+5]=r[5],e[n+6]=r[6],e[n+7]=r[7],e[n+8]=r[8],e}clone(){return new this.constructor().fromArray(this.elements)}};const TC=new Cn,_H=new Cn().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),wH=new Cn().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function a3e(){const t={enabled:!0,workingColorSpace:yg,spaces:{},convert:function(i,a,o){return this.enabled===!1||a===o||!a||!o||(this.spaces[a].transfer===ur&&(i.r=tu(i.r),i.g=tu(i.g),i.b=tu(i.b)),this.spaces[a].primaries!==this.spaces[o].primaries&&(i.applyMatrix3(this.spaces[a].toXYZ),i.applyMatrix3(this.spaces[o].fromXYZ)),this.spaces[o].transfer===ur&&(i.r=Yp(i.r),i.g=Yp(i.g),i.b=Yp(i.b))),i},workingToColorSpace:function(i,a){return this.convert(i,this.workingColorSpace,a)},colorSpaceToWorking:function(i,a){return this.convert(i,a,this.workingColorSpace)},getPrimaries:function(i){return this.spaces[i].primaries},getTransfer:function(i){return i===xd?vS:this.spaces[i].transfer},getToneMappingMode:function(i){return this.spaces[i].outputColorSpaceConfig.toneMappingMode||"standard"},getLuminanceCoefficients:function(i,a=this.workingColorSpace){return i.fromArray(this.spaces[a].luminanceCoefficients)},define:function(i){Object.assign(this.spaces,i)},_getMatrix:function(i,a,o){return i.copy(this.spaces[a].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,a){return I0("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),t.workingToColorSpace(i,a)},toWorkingColorSpace:function(i,a){return I0("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),t.colorSpaceToWorking(i,a)}},e=[.64,.33,.3,.6,.15,.06],n=[.2126,.7152,.0722],r=[.3127,.329];return t.define({[yg]:{primaries:e,whitePoint:r,transfer:vS,toXYZ:_H,fromXYZ:wH,luminanceCoefficients:n,workingColorSpaceConfig:{unpackColorSpace:bo},outputColorSpaceConfig:{drawingBufferColorSpace:bo}},[bo]:{primaries:e,whitePoint:r,transfer:ur,toXYZ:_H,fromXYZ:wH,luminanceCoefficients:n,outputColorSpaceConfig:{drawingBufferColorSpace:bo}}}),t}const Kn=a3e();function tu(t){return t<.04045?t*.0773993808:Math.pow(t*.9478672986+.0521327014,2.4)}function Yp(t){return t<.0031308?t*12.92:1.055*Math.pow(t,.41666)-.055}let Vm,s3e=class{static getDataURL(e,n="image/png"){if(/^data:/i.test(e.src)||typeof HTMLCanvasElement>"u")return e.src;let r;if(e instanceof HTMLCanvasElement)r=e;else{Vm===void 0&&(Vm=wS("canvas")),Vm.width=e.width,Vm.height=e.height;const i=Vm.getContext("2d");e instanceof ImageData?i.putImageData(e,0,0):i.drawImage(e,0,0,e.width,e.height),r=Vm}return r.toDataURL(n)}static sRGBToLinear(e){if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap){const n=wS("canvas");n.width=e.width,n.height=e.height;const r=n.getContext("2d");r.drawImage(e,0,0,e.width,e.height);const i=r.getImageData(0,0,e.width,e.height),a=i.data;for(let o=0;o1),this.pmremVersion=0}get width(){return this.source.getSize(CC).x}get height(){return this.source.getSize(CC).y}get depth(){return this.source.getSize(CC).z}get image(){return this.source.data}set image(e=null){this.source.data=e}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(e,n){this.updateRanges.push({start:e,count:n})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(e){return this.name=e.name,this.source=e.source,this.mipmaps=e.mipmaps.slice(0),this.mapping=e.mapping,this.channel=e.channel,this.wrapS=e.wrapS,this.wrapT=e.wrapT,this.magFilter=e.magFilter,this.minFilter=e.minFilter,this.anisotropy=e.anisotropy,this.format=e.format,this.internalFormat=e.internalFormat,this.type=e.type,this.offset.copy(e.offset),this.repeat.copy(e.repeat),this.center.copy(e.center),this.rotation=e.rotation,this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrix.copy(e.matrix),this.generateMipmaps=e.generateMipmaps,this.premultiplyAlpha=e.premultiplyAlpha,this.flipY=e.flipY,this.unpackAlignment=e.unpackAlignment,this.colorSpace=e.colorSpace,this.renderTarget=e.renderTarget,this.isRenderTargetTexture=e.isRenderTargetTexture,this.isArrayTexture=e.isArrayTexture,this.userData=JSON.parse(JSON.stringify(e.userData)),this.needsUpdate=!0,this}setValues(e){for(const n in e){const r=e[n];if(r===void 0){mn(`Texture.setValues(): parameter '${n}' has value of undefined.`);continue}const i=this[n];if(i===void 0){mn(`Texture.setValues(): property '${n}' does not exist.`);continue}i&&r&&i.isVector2&&r.isVector2||i&&r&&i.isVector3&&r.isVector3||i&&r&&i.isMatrix3&&r.isMatrix3?i.copy(r):this[n]=r}}toJSON(e){const n=e===void 0||typeof e=="string";if(!n&&e.textures[this.uuid]!==void 0)return e.textures[this.uuid];const r={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(e).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&&(r.userData=this.userData),n||(e.textures[this.uuid]=r),r}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(e){if(this.mapping!==FZ)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case pP:e.x=e.x-Math.floor(e.x);break;case Wc:e.x=e.x<0?0:1;break;case gP:Math.abs(Math.floor(e.x)%2)===1?e.x=Math.ceil(e.x)-e.x:e.x=e.x-Math.floor(e.x);break}if(e.y<0||e.y>1)switch(this.wrapT){case pP:e.y=e.y-Math.floor(e.y);break;case Wc:e.y=e.y<0?0:1;break;case gP:Math.abs(Math.floor(e.y)%2)===1?e.y=Math.ceil(e.y)-e.y:e.y=e.y-Math.floor(e.y);break}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){e===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(e){e===!0&&this.pmremVersion++}};pl.DEFAULT_IMAGE=null;pl.DEFAULT_MAPPING=FZ;pl.DEFAULT_ANISOTROPY=1;let wi=class ZZ{constructor(e=0,n=0,r=0,i=1){ZZ.prototype.isVector4=!0,this.x=e,this.y=n,this.z=r,this.w=i}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,n,r,i){return this.x=e,this.y=n,this.z=r,this.w=i,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,n){switch(e){case 0:this.x=n;break;case 1:this.y=n;break;case 2:this.z=n;break;case 3:this.w=n;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){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: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w!==void 0?e.w:1,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,n){return this.x=e.x+n.x,this.y=e.y+n.y,this.z=e.z+n.z,this.w=e.w+n.w,this}addScaledVector(e,n){return this.x+=e.x*n,this.y+=e.y*n,this.z+=e.z*n,this.w+=e.w*n,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,n){return this.x=e.x-n.x,this.y=e.y-n.y,this.z=e.z-n.z,this.w=e.w-n.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){const n=this.x,r=this.y,i=this.z,a=this.w,o=e.elements;return this.x=o[0]*n+o[4]*r+o[8]*i+o[12]*a,this.y=o[1]*n+o[5]*r+o[9]*i+o[13]*a,this.z=o[2]*n+o[6]*r+o[10]*i+o[14]*a,this.w=o[3]*n+o[7]*r+o[11]*i+o[15]*a,this}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this.w/=e.w,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);const n=Math.sqrt(1-e.w*e.w);return n<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/n,this.y=e.y/n,this.z=e.z/n),this}setAxisAngleFromRotationMatrix(e){let n,r,i,a;const c=e.elements,u=c[0],d=c[4],f=c[8],m=c[1],g=c[5],x=c[9],y=c[2],b=c[6],v=c[10];if(Math.abs(d-m)<.01&&Math.abs(f-y)<.01&&Math.abs(x-b)<.01){if(Math.abs(d+m)<.1&&Math.abs(f+y)<.1&&Math.abs(x+b)<.1&&Math.abs(u+g+v-3)<.1)return this.set(1,0,0,0),this;n=Math.PI;const S=(u+1)/2,E=(g+1)/2,T=(v+1)/2,C=(d+m)/4,A=(f+y)/4,D=(x+b)/4;return S>E&&S>T?S<.01?(r=0,i=.707106781,a=.707106781):(r=Math.sqrt(S),i=C/r,a=A/r):E>T?E<.01?(r=.707106781,i=0,a=.707106781):(i=Math.sqrt(E),r=C/i,a=D/i):T<.01?(r=.707106781,i=.707106781,a=0):(a=Math.sqrt(T),r=A/a,i=D/a),this.set(r,i,a,n),this}let N=Math.sqrt((b-x)*(b-x)+(f-y)*(f-y)+(m-d)*(m-d));return Math.abs(N)<.001&&(N=1),this.x=(b-x)/N,this.y=(f-y)/N,this.z=(m-d)/N,this.w=Math.acos((u+g+v-1)/2),this}setFromMatrixPosition(e){const n=e.elements;return this.x=n[12],this.y=n[13],this.z=n[14],this.w=n[15],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,n){return this.x=Rn(this.x,e.x,n.x),this.y=Rn(this.y,e.y,n.y),this.z=Rn(this.z,e.z,n.z),this.w=Rn(this.w,e.w,n.w),this}clampScalar(e,n){return this.x=Rn(this.x,e,n),this.y=Rn(this.y,e,n),this.z=Rn(this.z,e,n),this.w=Rn(this.w,e,n),this}clampLength(e,n){const r=this.length();return this.divideScalar(r||1).multiplyScalar(Rn(r,e,n))}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(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.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(e){return this.normalize().multiplyScalar(e)}lerp(e,n){return this.x+=(e.x-this.x)*n,this.y+=(e.y-this.y)*n,this.z+=(e.z-this.z)*n,this.w+=(e.w-this.w)*n,this}lerpVectors(e,n,r){return this.x=e.x+(n.x-e.x)*r,this.y=e.y+(n.y-e.y)*r,this.z=e.z+(n.z-e.z)*r,this.w=e.w+(n.w-e.w)*r,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,n=0){return this.x=e[n],this.y=e[n+1],this.z=e[n+2],this.w=e[n+3],this}toArray(e=[],n=0){return e[n]=this.x,e[n+1]=this.y,e[n+2]=this.z,e[n+3]=this.w,e}fromBufferAttribute(e,n){return this.x=e.getX(n),this.y=e.getY(n),this.z=e.getZ(n),this.w=e.getW(n),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}},c3e=class extends tm{constructor(e=1,n=1,r={}){super(),r=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:To,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1,depth:1,multiview:!1},r),this.isRenderTarget=!0,this.width=e,this.height=n,this.depth=r.depth,this.scissor=new wi(0,0,e,n),this.scissorTest=!1,this.viewport=new wi(0,0,e,n);const i={width:e,height:n,depth:r.depth},a=new pl(i);this.textures=[];const o=r.count;for(let l=0;l1);this.dispose()}this.viewport.set(0,0,e,n),this.scissor.set(0,0,e,n)}clone(){return new this.constructor().copy(this)}copy(e){this.width=e.width,this.height=e.height,this.depth=e.depth,this.scissor.copy(e.scissor),this.scissorTest=e.scissorTest,this.viewport.copy(e.viewport),this.textures.length=0;for(let n=0,r=e.textures.length;n=this.min.x&&e.x<=this.max.x&&e.y>=this.min.y&&e.y<=this.max.y&&e.z>=this.min.z&&e.z<=this.max.z}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y&&this.min.z<=e.min.z&&e.max.z<=this.max.z}getParameter(e,n){return n.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y),(e.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(e){return e.max.x>=this.min.x&&e.min.x<=this.max.x&&e.max.y>=this.min.y&&e.min.y<=this.max.y&&e.max.z>=this.min.z&&e.min.z<=this.max.z}intersectsSphere(e){return this.clampPoint(e.center,Go),Go.distanceToSquared(e.center)<=e.radius*e.radius}intersectsPlane(e){let n,r;return e.normal.x>0?(n=e.normal.x*this.min.x,r=e.normal.x*this.max.x):(n=e.normal.x*this.max.x,r=e.normal.x*this.min.x),e.normal.y>0?(n+=e.normal.y*this.min.y,r+=e.normal.y*this.max.y):(n+=e.normal.y*this.max.y,r+=e.normal.y*this.min.y),e.normal.z>0?(n+=e.normal.z*this.min.z,r+=e.normal.z*this.max.z):(n+=e.normal.z*this.max.z,r+=e.normal.z*this.min.z),n<=-e.constant&&r>=-e.constant}intersectsTriangle(e){if(this.isEmpty())return!1;this.getCenter(ob),N_.subVectors(this.max,ob),Gm.subVectors(e.a,ob),Wm.subVectors(e.b,ob),qm.subVectors(e.c,ob),Wu.subVectors(Wm,Gm),qu.subVectors(qm,Wm),Ah.subVectors(Gm,qm);let n=[0,-Wu.z,Wu.y,0,-qu.z,qu.y,0,-Ah.z,Ah.y,Wu.z,0,-Wu.x,qu.z,0,-qu.x,Ah.z,0,-Ah.x,-Wu.y,Wu.x,0,-qu.y,qu.x,0,-Ah.y,Ah.x,0];return!kC(n,Gm,Wm,qm,N_)||(n=[1,0,0,0,1,0,0,0,1],!kC(n,Gm,Wm,qm,N_))?!1:(M_.crossVectors(Wu,qu),n=[M_.x,M_.y,M_.z],kC(n,Gm,Wm,qm,N_))}clampPoint(e,n){return n.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,Go).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=this.getSize(Go).length()*.5),e}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}applyMatrix4(e){return this.isEmpty()?this:(yc[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),yc[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),yc[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),yc[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),yc[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),yc[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),yc[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),yc[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(yc),this)}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(e){return this.min.fromArray(e.min),this.max.fromArray(e.max),this}};const yc=[new ot,new ot,new ot,new ot,new ot,new ot,new ot,new ot],Go=new ot,S_=new $f,Gm=new ot,Wm=new ot,qm=new ot,Wu=new ot,qu=new ot,Ah=new ot,ob=new ot,N_=new ot,M_=new ot,Ch=new ot;function kC(t,e,n,r,i){for(let a=0,o=t.length-3;a<=o;a+=3){Ch.fromArray(t,a);const l=i.x*Math.abs(Ch.x)+i.y*Math.abs(Ch.y)+i.z*Math.abs(Ch.z),c=e.dot(Ch),u=n.dot(Ch),d=r.dot(Ch);if(Math.max(-Math.max(c,u,d),Math.min(c,u,d))>l)return!1}return!0}const d3e=new $f,lb=new ot,jC=new ot;let BN=class{constructor(e=new ot,n=-1){this.isSphere=!0,this.center=e,this.radius=n}set(e,n){return this.center.copy(e),this.radius=n,this}setFromPoints(e,n){const r=this.center;n!==void 0?r.copy(n):d3e.setFromPoints(e).getCenter(r);let i=0;for(let a=0,o=e.length;athis.radius*this.radius&&(n.sub(this.center).normalize(),n.multiplyScalar(this.radius).add(this.center)),n}getBoundingBox(e){return this.isEmpty()?(e.makeEmpty(),e):(e.set(this.center,this.center),e.expandByScalar(this.radius),e)}applyMatrix4(e){return this.center.applyMatrix4(e),this.radius=this.radius*e.getMaxScaleOnAxis(),this}translate(e){return this.center.add(e),this}expandByPoint(e){if(this.isEmpty())return this.center.copy(e),this.radius=0,this;lb.subVectors(e,this.center);const n=lb.lengthSq();if(n>this.radius*this.radius){const r=Math.sqrt(n),i=(r-this.radius)*.5;this.center.addScaledVector(lb,i/r),this.radius+=i}return this}union(e){return e.isEmpty()?this:this.isEmpty()?(this.copy(e),this):(this.center.equals(e.center)===!0?this.radius=Math.max(this.radius,e.radius):(jC.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint(lb.copy(e.center).add(jC)),this.expandByPoint(lb.copy(e.center).sub(jC))),this)}equals(e){return e.center.equals(this.center)&&e.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(e){return this.radius=e.radius,this.center.fromArray(e.center),this}};const vc=new ot,PC=new ot,E_=new ot,Ku=new ot,RC=new ot,T_=new ot,DC=new ot;let kO=class{constructor(e=new ot,n=new ot(0,0,-1)){this.origin=e,this.direction=n}set(e,n){return this.origin.copy(e),this.direction.copy(n),this}copy(e){return this.origin.copy(e.origin),this.direction.copy(e.direction),this}at(e,n){return n.copy(this.origin).addScaledVector(this.direction,e)}lookAt(e){return this.direction.copy(e).sub(this.origin).normalize(),this}recast(e){return this.origin.copy(this.at(e,vc)),this}closestPointToPoint(e,n){n.subVectors(e,this.origin);const r=n.dot(this.direction);return r<0?n.copy(this.origin):n.copy(this.origin).addScaledVector(this.direction,r)}distanceToPoint(e){return Math.sqrt(this.distanceSqToPoint(e))}distanceSqToPoint(e){const n=vc.subVectors(e,this.origin).dot(this.direction);return n<0?this.origin.distanceToSquared(e):(vc.copy(this.origin).addScaledVector(this.direction,n),vc.distanceToSquared(e))}distanceSqToSegment(e,n,r,i){PC.copy(e).add(n).multiplyScalar(.5),E_.copy(n).sub(e).normalize(),Ku.copy(this.origin).sub(PC);const a=e.distanceTo(n)*.5,o=-this.direction.dot(E_),l=Ku.dot(this.direction),c=-Ku.dot(E_),u=Ku.lengthSq(),d=Math.abs(1-o*o);let f,m,g,x;if(d>0)if(f=o*c-l,m=o*l-c,x=a*d,f>=0)if(m>=-x)if(m<=x){const y=1/d;f*=y,m*=y,g=f*(f+o*m+2*l)+m*(o*f+m+2*c)+u}else m=a,f=Math.max(0,-(o*m+l)),g=-f*f+m*(m+2*c)+u;else m=-a,f=Math.max(0,-(o*m+l)),g=-f*f+m*(m+2*c)+u;else m<=-x?(f=Math.max(0,-(-o*a+l)),m=f>0?-a:Math.min(Math.max(-a,-c),a),g=-f*f+m*(m+2*c)+u):m<=x?(f=0,m=Math.min(Math.max(-a,-c),a),g=m*(m+2*c)+u):(f=Math.max(0,-(o*a+l)),m=f>0?a:Math.min(Math.max(-a,-c),a),g=-f*f+m*(m+2*c)+u);else m=o>0?-a:a,f=Math.max(0,-(o*m+l)),g=-f*f+m*(m+2*c)+u;return r&&r.copy(this.origin).addScaledVector(this.direction,f),i&&i.copy(PC).addScaledVector(E_,m),g}intersectSphere(e,n){vc.subVectors(e.center,this.origin);const r=vc.dot(this.direction),i=vc.dot(vc)-r*r,a=e.radius*e.radius;if(i>a)return null;const o=Math.sqrt(a-i),l=r-o,c=r+o;return c<0?null:l<0?this.at(c,n):this.at(l,n)}intersectsSphere(e){return e.radius<0?!1:this.distanceSqToPoint(e.center)<=e.radius*e.radius}distanceToPlane(e){const n=e.normal.dot(this.direction);if(n===0)return e.distanceToPoint(this.origin)===0?0:null;const r=-(this.origin.dot(e.normal)+e.constant)/n;return r>=0?r:null}intersectPlane(e,n){const r=this.distanceToPlane(e);return r===null?null:this.at(r,n)}intersectsPlane(e){const n=e.distanceToPoint(this.origin);return n===0||e.normal.dot(this.direction)*n<0}intersectBox(e,n){let r,i,a,o,l,c;const u=1/this.direction.x,d=1/this.direction.y,f=1/this.direction.z,m=this.origin;return u>=0?(r=(e.min.x-m.x)*u,i=(e.max.x-m.x)*u):(r=(e.max.x-m.x)*u,i=(e.min.x-m.x)*u),d>=0?(a=(e.min.y-m.y)*d,o=(e.max.y-m.y)*d):(a=(e.max.y-m.y)*d,o=(e.min.y-m.y)*d),r>o||a>i||((a>r||isNaN(r))&&(r=a),(o=0?(l=(e.min.z-m.z)*f,c=(e.max.z-m.z)*f):(l=(e.max.z-m.z)*f,c=(e.min.z-m.z)*f),r>c||l>i)||((l>r||r!==r)&&(r=l),(c=0?r:i,n)}intersectsBox(e){return this.intersectBox(e,vc)!==null}intersectTriangle(e,n,r,i,a){RC.subVectors(n,e),T_.subVectors(r,e),DC.crossVectors(RC,T_);let o=this.direction.dot(DC),l;if(o>0){if(i)return null;l=1}else if(o<0)l=-1,o=-o;else return null;Ku.subVectors(this.origin,e);const c=l*this.direction.dot(T_.crossVectors(Ku,T_));if(c<0)return null;const u=l*this.direction.dot(RC.cross(Ku));if(u<0||c+u>o)return null;const d=-l*Ku.dot(DC);return d<0?null:this.at(d/o,a)}applyMatrix4(e){return this.origin.applyMatrix4(e),this.direction.transformDirection(e),this}equals(e){return e.origin.equals(this.origin)&&e.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}},Ti=class WP{constructor(e,n,r,i,a,o,l,c,u,d,f,m,g,x,y,b){WP.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],e!==void 0&&this.set(e,n,r,i,a,o,l,c,u,d,f,m,g,x,y,b)}set(e,n,r,i,a,o,l,c,u,d,f,m,g,x,y,b){const v=this.elements;return v[0]=e,v[4]=n,v[8]=r,v[12]=i,v[1]=a,v[5]=o,v[9]=l,v[13]=c,v[2]=u,v[6]=d,v[10]=f,v[14]=m,v[3]=g,v[7]=x,v[11]=y,v[15]=b,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 WP().fromArray(this.elements)}copy(e){const n=this.elements,r=e.elements;return n[0]=r[0],n[1]=r[1],n[2]=r[2],n[3]=r[3],n[4]=r[4],n[5]=r[5],n[6]=r[6],n[7]=r[7],n[8]=r[8],n[9]=r[9],n[10]=r[10],n[11]=r[11],n[12]=r[12],n[13]=r[13],n[14]=r[14],n[15]=r[15],this}copyPosition(e){const n=this.elements,r=e.elements;return n[12]=r[12],n[13]=r[13],n[14]=r[14],this}setFromMatrix3(e){const n=e.elements;return this.set(n[0],n[3],n[6],0,n[1],n[4],n[7],0,n[2],n[5],n[8],0,0,0,0,1),this}extractBasis(e,n,r){return e.setFromMatrixColumn(this,0),n.setFromMatrixColumn(this,1),r.setFromMatrixColumn(this,2),this}makeBasis(e,n,r){return this.set(e.x,n.x,r.x,0,e.y,n.y,r.y,0,e.z,n.z,r.z,0,0,0,0,1),this}extractRotation(e){const n=this.elements,r=e.elements,i=1/Km.setFromMatrixColumn(e,0).length(),a=1/Km.setFromMatrixColumn(e,1).length(),o=1/Km.setFromMatrixColumn(e,2).length();return n[0]=r[0]*i,n[1]=r[1]*i,n[2]=r[2]*i,n[3]=0,n[4]=r[4]*a,n[5]=r[5]*a,n[6]=r[6]*a,n[7]=0,n[8]=r[8]*o,n[9]=r[9]*o,n[10]=r[10]*o,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,this}makeRotationFromEuler(e){const n=this.elements,r=e.x,i=e.y,a=e.z,o=Math.cos(r),l=Math.sin(r),c=Math.cos(i),u=Math.sin(i),d=Math.cos(a),f=Math.sin(a);if(e.order==="XYZ"){const m=o*d,g=o*f,x=l*d,y=l*f;n[0]=c*d,n[4]=-c*f,n[8]=u,n[1]=g+x*u,n[5]=m-y*u,n[9]=-l*c,n[2]=y-m*u,n[6]=x+g*u,n[10]=o*c}else if(e.order==="YXZ"){const m=c*d,g=c*f,x=u*d,y=u*f;n[0]=m+y*l,n[4]=x*l-g,n[8]=o*u,n[1]=o*f,n[5]=o*d,n[9]=-l,n[2]=g*l-x,n[6]=y+m*l,n[10]=o*c}else if(e.order==="ZXY"){const m=c*d,g=c*f,x=u*d,y=u*f;n[0]=m-y*l,n[4]=-o*f,n[8]=x+g*l,n[1]=g+x*l,n[5]=o*d,n[9]=y-m*l,n[2]=-o*u,n[6]=l,n[10]=o*c}else if(e.order==="ZYX"){const m=o*d,g=o*f,x=l*d,y=l*f;n[0]=c*d,n[4]=x*u-g,n[8]=m*u+y,n[1]=c*f,n[5]=y*u+m,n[9]=g*u-x,n[2]=-u,n[6]=l*c,n[10]=o*c}else if(e.order==="YZX"){const m=o*c,g=o*u,x=l*c,y=l*u;n[0]=c*d,n[4]=y-m*f,n[8]=x*f+g,n[1]=f,n[5]=o*d,n[9]=-l*d,n[2]=-u*d,n[6]=g*f+x,n[10]=m-y*f}else if(e.order==="XZY"){const m=o*c,g=o*u,x=l*c,y=l*u;n[0]=c*d,n[4]=-f,n[8]=u*d,n[1]=m*f+y,n[5]=o*d,n[9]=g*f-x,n[2]=x*f-g,n[6]=l*d,n[10]=y*f+m}return n[3]=0,n[7]=0,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,this}makeRotationFromQuaternion(e){return this.compose(h3e,e,f3e)}lookAt(e,n,r){const i=this.elements;return Os.subVectors(e,n),Os.lengthSq()===0&&(Os.z=1),Os.normalize(),Xu.crossVectors(r,Os),Xu.lengthSq()===0&&(Math.abs(r.z)===1?Os.x+=1e-4:Os.z+=1e-4,Os.normalize(),Xu.crossVectors(r,Os)),Xu.normalize(),A_.crossVectors(Os,Xu),i[0]=Xu.x,i[4]=A_.x,i[8]=Os.x,i[1]=Xu.y,i[5]=A_.y,i[9]=Os.y,i[2]=Xu.z,i[6]=A_.z,i[10]=Os.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,n){const r=e.elements,i=n.elements,a=this.elements,o=r[0],l=r[4],c=r[8],u=r[12],d=r[1],f=r[5],m=r[9],g=r[13],x=r[2],y=r[6],b=r[10],v=r[14],N=r[3],S=r[7],E=r[11],T=r[15],C=i[0],A=i[4],D=i[8],k=i[12],R=i[1],F=i[5],O=i[9],X=i[13],j=i[2],W=i[6],Y=i[10],q=i[14],Z=i[3],ee=i[7],ne=i[11],z=i[15];return a[0]=o*C+l*R+c*j+u*Z,a[4]=o*A+l*F+c*W+u*ee,a[8]=o*D+l*O+c*Y+u*ne,a[12]=o*k+l*X+c*q+u*z,a[1]=d*C+f*R+m*j+g*Z,a[5]=d*A+f*F+m*W+g*ee,a[9]=d*D+f*O+m*Y+g*ne,a[13]=d*k+f*X+m*q+g*z,a[2]=x*C+y*R+b*j+v*Z,a[6]=x*A+y*F+b*W+v*ee,a[10]=x*D+y*O+b*Y+v*ne,a[14]=x*k+y*X+b*q+v*z,a[3]=N*C+S*R+E*j+T*Z,a[7]=N*A+S*F+E*W+T*ee,a[11]=N*D+S*O+E*Y+T*ne,a[15]=N*k+S*X+E*q+T*z,this}multiplyScalar(e){const n=this.elements;return n[0]*=e,n[4]*=e,n[8]*=e,n[12]*=e,n[1]*=e,n[5]*=e,n[9]*=e,n[13]*=e,n[2]*=e,n[6]*=e,n[10]*=e,n[14]*=e,n[3]*=e,n[7]*=e,n[11]*=e,n[15]*=e,this}determinant(){const e=this.elements,n=e[0],r=e[4],i=e[8],a=e[12],o=e[1],l=e[5],c=e[9],u=e[13],d=e[2],f=e[6],m=e[10],g=e[14],x=e[3],y=e[7],b=e[11],v=e[15];return x*(+a*c*f-i*u*f-a*l*m+r*u*m+i*l*g-r*c*g)+y*(+n*c*g-n*u*m+a*o*m-i*o*g+i*u*d-a*c*d)+b*(+n*u*f-n*l*g-a*o*f+r*o*g+a*l*d-r*u*d)+v*(-i*l*d-n*c*f+n*l*m+i*o*f-r*o*m+r*c*d)}transpose(){const e=this.elements;let n;return n=e[1],e[1]=e[4],e[4]=n,n=e[2],e[2]=e[8],e[8]=n,n=e[6],e[6]=e[9],e[9]=n,n=e[3],e[3]=e[12],e[12]=n,n=e[7],e[7]=e[13],e[13]=n,n=e[11],e[11]=e[14],e[14]=n,this}setPosition(e,n,r){const i=this.elements;return e.isVector3?(i[12]=e.x,i[13]=e.y,i[14]=e.z):(i[12]=e,i[13]=n,i[14]=r),this}invert(){const e=this.elements,n=e[0],r=e[1],i=e[2],a=e[3],o=e[4],l=e[5],c=e[6],u=e[7],d=e[8],f=e[9],m=e[10],g=e[11],x=e[12],y=e[13],b=e[14],v=e[15],N=f*b*u-y*m*u+y*c*g-l*b*g-f*c*v+l*m*v,S=x*m*u-d*b*u-x*c*g+o*b*g+d*c*v-o*m*v,E=d*y*u-x*f*u+x*l*g-o*y*g-d*l*v+o*f*v,T=x*f*c-d*y*c-x*l*m+o*y*m+d*l*b-o*f*b,C=n*N+r*S+i*E+a*T;if(C===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const A=1/C;return e[0]=N*A,e[1]=(y*m*a-f*b*a-y*i*g+r*b*g+f*i*v-r*m*v)*A,e[2]=(l*b*a-y*c*a+y*i*u-r*b*u-l*i*v+r*c*v)*A,e[3]=(f*c*a-l*m*a-f*i*u+r*m*u+l*i*g-r*c*g)*A,e[4]=S*A,e[5]=(d*b*a-x*m*a+x*i*g-n*b*g-d*i*v+n*m*v)*A,e[6]=(x*c*a-o*b*a-x*i*u+n*b*u+o*i*v-n*c*v)*A,e[7]=(o*m*a-d*c*a+d*i*u-n*m*u-o*i*g+n*c*g)*A,e[8]=E*A,e[9]=(x*f*a-d*y*a-x*r*g+n*y*g+d*r*v-n*f*v)*A,e[10]=(o*y*a-x*l*a+x*r*u-n*y*u-o*r*v+n*l*v)*A,e[11]=(d*l*a-o*f*a-d*r*u+n*f*u+o*r*g-n*l*g)*A,e[12]=T*A,e[13]=(d*y*i-x*f*i+x*r*m-n*y*m-d*r*b+n*f*b)*A,e[14]=(x*l*i-o*y*i-x*r*c+n*y*c+o*r*b-n*l*b)*A,e[15]=(o*f*i-d*l*i+d*r*c-n*f*c-o*r*m+n*l*m)*A,this}scale(e){const n=this.elements,r=e.x,i=e.y,a=e.z;return n[0]*=r,n[4]*=i,n[8]*=a,n[1]*=r,n[5]*=i,n[9]*=a,n[2]*=r,n[6]*=i,n[10]*=a,n[3]*=r,n[7]*=i,n[11]*=a,this}getMaxScaleOnAxis(){const e=this.elements,n=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],r=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],i=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(n,r,i))}makeTranslation(e,n,r){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,n,0,0,1,r,0,0,0,1),this}makeRotationX(e){const n=Math.cos(e),r=Math.sin(e);return this.set(1,0,0,0,0,n,-r,0,0,r,n,0,0,0,0,1),this}makeRotationY(e){const n=Math.cos(e),r=Math.sin(e);return this.set(n,0,r,0,0,1,0,0,-r,0,n,0,0,0,0,1),this}makeRotationZ(e){const n=Math.cos(e),r=Math.sin(e);return this.set(n,-r,0,0,r,n,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,n){const r=Math.cos(n),i=Math.sin(n),a=1-r,o=e.x,l=e.y,c=e.z,u=a*o,d=a*l;return this.set(u*o+r,u*l-i*c,u*c+i*l,0,u*l+i*c,d*l+r,d*c-i*o,0,u*c-i*l,d*c+i*o,a*c*c+r,0,0,0,0,1),this}makeScale(e,n,r){return this.set(e,0,0,0,0,n,0,0,0,0,r,0,0,0,0,1),this}makeShear(e,n,r,i,a,o){return this.set(1,r,a,0,e,1,o,0,n,i,1,0,0,0,0,1),this}compose(e,n,r){const i=this.elements,a=n._x,o=n._y,l=n._z,c=n._w,u=a+a,d=o+o,f=l+l,m=a*u,g=a*d,x=a*f,y=o*d,b=o*f,v=l*f,N=c*u,S=c*d,E=c*f,T=r.x,C=r.y,A=r.z;return i[0]=(1-(y+v))*T,i[1]=(g+E)*T,i[2]=(x-S)*T,i[3]=0,i[4]=(g-E)*C,i[5]=(1-(m+v))*C,i[6]=(b+N)*C,i[7]=0,i[8]=(x+S)*A,i[9]=(b-N)*A,i[10]=(1-(m+y))*A,i[11]=0,i[12]=e.x,i[13]=e.y,i[14]=e.z,i[15]=1,this}decompose(e,n,r){const i=this.elements;let a=Km.set(i[0],i[1],i[2]).length();const o=Km.set(i[4],i[5],i[6]).length(),l=Km.set(i[8],i[9],i[10]).length();this.determinant()<0&&(a=-a),e.x=i[12],e.y=i[13],e.z=i[14],Wo.copy(this);const u=1/a,d=1/o,f=1/l;return Wo.elements[0]*=u,Wo.elements[1]*=u,Wo.elements[2]*=u,Wo.elements[4]*=d,Wo.elements[5]*=d,Wo.elements[6]*=d,Wo.elements[8]*=f,Wo.elements[9]*=f,Wo.elements[10]*=f,n.setFromRotationMatrix(Wo),r.x=a,r.y=o,r.z=l,this}makePerspective(e,n,r,i,a,o,l=Dl,c=!1){const u=this.elements,d=2*a/(n-e),f=2*a/(r-i),m=(n+e)/(n-e),g=(r+i)/(r-i);let x,y;if(c)x=a/(o-a),y=o*a/(o-a);else if(l===Dl)x=-(o+a)/(o-a),y=-2*o*a/(o-a);else if(l===_S)x=-o/(o-a),y=-o*a/(o-a);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+l);return u[0]=d,u[4]=0,u[8]=m,u[12]=0,u[1]=0,u[5]=f,u[9]=g,u[13]=0,u[2]=0,u[6]=0,u[10]=x,u[14]=y,u[3]=0,u[7]=0,u[11]=-1,u[15]=0,this}makeOrthographic(e,n,r,i,a,o,l=Dl,c=!1){const u=this.elements,d=2/(n-e),f=2/(r-i),m=-(n+e)/(n-e),g=-(r+i)/(r-i);let x,y;if(c)x=1/(o-a),y=o/(o-a);else if(l===Dl)x=-2/(o-a),y=-(o+a)/(o-a);else if(l===_S)x=-1/(o-a),y=-a/(o-a);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+l);return u[0]=d,u[4]=0,u[8]=0,u[12]=m,u[1]=0,u[5]=f,u[9]=0,u[13]=g,u[2]=0,u[6]=0,u[10]=x,u[14]=y,u[3]=0,u[7]=0,u[11]=0,u[15]=1,this}equals(e){const n=this.elements,r=e.elements;for(let i=0;i<16;i++)if(n[i]!==r[i])return!1;return!0}fromArray(e,n=0){for(let r=0;r<16;r++)this.elements[r]=e[r+n];return this}toArray(e=[],n=0){const r=this.elements;return e[n]=r[0],e[n+1]=r[1],e[n+2]=r[2],e[n+3]=r[3],e[n+4]=r[4],e[n+5]=r[5],e[n+6]=r[6],e[n+7]=r[7],e[n+8]=r[8],e[n+9]=r[9],e[n+10]=r[10],e[n+11]=r[11],e[n+12]=r[12],e[n+13]=r[13],e[n+14]=r[14],e[n+15]=r[15],e}};const Km=new ot,Wo=new Ti,h3e=new ot(0,0,0),f3e=new ot(1,1,1),Xu=new ot,A_=new ot,Os=new ot,SH=new Ti,NH=new zf;let Yd=class eJ{constructor(e=0,n=0,r=0,i=eJ.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=n,this._z=r,this._order=i}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,n,r,i=this._order){return this._x=e,this._y=n,this._z=r,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,n=this._order,r=!0){const i=e.elements,a=i[0],o=i[4],l=i[8],c=i[1],u=i[5],d=i[9],f=i[2],m=i[6],g=i[10];switch(n){case"XYZ":this._y=Math.asin(Rn(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(-d,g),this._z=Math.atan2(-o,a)):(this._x=Math.atan2(m,u),this._z=0);break;case"YXZ":this._x=Math.asin(-Rn(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(l,g),this._z=Math.atan2(c,u)):(this._y=Math.atan2(-f,a),this._z=0);break;case"ZXY":this._x=Math.asin(Rn(m,-1,1)),Math.abs(m)<.9999999?(this._y=Math.atan2(-f,g),this._z=Math.atan2(-o,u)):(this._y=0,this._z=Math.atan2(c,a));break;case"ZYX":this._y=Math.asin(-Rn(f,-1,1)),Math.abs(f)<.9999999?(this._x=Math.atan2(m,g),this._z=Math.atan2(c,a)):(this._x=0,this._z=Math.atan2(-o,u));break;case"YZX":this._z=Math.asin(Rn(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(-d,u),this._y=Math.atan2(-f,a)):(this._x=0,this._y=Math.atan2(l,g));break;case"XZY":this._z=Math.asin(-Rn(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(m,u),this._y=Math.atan2(l,a)):(this._x=Math.atan2(-d,g),this._y=0);break;default:mn("Euler: .setFromRotationMatrix() encountered an unknown order: "+n)}return this._order=n,r===!0&&this._onChangeCallback(),this}setFromQuaternion(e,n,r){return SH.makeRotationFromQuaternion(e),this.setFromRotationMatrix(SH,n,r)}setFromVector3(e,n=this._order){return this.set(e.x,e.y,e.z,n)}reorder(e){return NH.setFromEuler(this),this.setFromQuaternion(NH,e)}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order}fromArray(e){return this._x=e[0],this._y=e[1],this._z=e[2],e[3]!==void 0&&(this._order=e[3]),this._onChangeCallback(),this}toArray(e=[],n=0){return e[n]=this._x,e[n+1]=this._y,e[n+2]=this._z,e[n+3]=this._order,e}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}};Yd.DEFAULT_ORDER="XYZ";let tJ=class{constructor(){this.mask=1}set(e){this.mask=(1<>>0}enable(e){this.mask|=1<1){for(let n=0;n1){for(let r=0;r0&&(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(l=>({...l,boundingBox:l.boundingBox?l.boundingBox.toJSON():void 0,boundingSphere:l.boundingSphere?l.boundingSphere.toJSON():void 0})),i.instanceInfo=this._instanceInfo.map(l=>({...l})),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(e),i.indirectTexture=this._indirectTexture.toJSON(e),this._colorsTexture!==null&&(i.colorsTexture=this._colorsTexture.toJSON(e)),this.boundingSphere!==null&&(i.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(i.boundingBox=this.boundingBox.toJSON()));function a(l,c){return l[c.uuid]===void 0&&(l[c.uuid]=c.toJSON(e)),c.uuid}if(this.isScene)this.background&&(this.background.isColor?i.background=this.background.toJSON():this.background.isTexture&&(i.background=this.background.toJSON(e).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(i.environment=this.environment.toJSON(e).uuid);else if(this.isMesh||this.isLine||this.isPoints){i.geometry=a(e.geometries,this.geometry);const l=this.geometry.parameters;if(l!==void 0&&l.shapes!==void 0){const c=l.shapes;if(Array.isArray(c))for(let u=0,d=c.length;u0){i.children=[];for(let l=0;l0){i.animations=[];for(let l=0;l0&&(r.geometries=l),c.length>0&&(r.materials=c),u.length>0&&(r.textures=u),d.length>0&&(r.images=d),f.length>0&&(r.shapes=f),m.length>0&&(r.skeletons=m),g.length>0&&(r.animations=g),x.length>0&&(r.nodes=x)}return r.object=i,r;function o(l){const c=[];for(const u in l){const d=l[u];delete d.metadata,c.push(d)}return c}}clone(e){return new this.constructor().copy(this,e)}copy(e,n=!0){if(this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),this.rotation.order=e.rotation.order,this.quaternion.copy(e.quaternion),this.scale.copy(e.scale),this.matrix.copy(e.matrix),this.matrixWorld.copy(e.matrixWorld),this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrixWorldAutoUpdate=e.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=e.matrixWorldNeedsUpdate,this.layers.mask=e.layers.mask,this.visible=e.visible,this.castShadow=e.castShadow,this.receiveShadow=e.receiveShadow,this.frustumCulled=e.frustumCulled,this.renderOrder=e.renderOrder,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),n===!0)for(let r=0;r0?i.multiplyScalar(1/Math.sqrt(a)):i.set(0,0,0)}static getBarycoord(e,n,r,i,a){qo.subVectors(i,n),wc.subVectors(r,n),LC.subVectors(e,n);const o=qo.dot(qo),l=qo.dot(wc),c=qo.dot(LC),u=wc.dot(wc),d=wc.dot(LC),f=o*u-l*l;if(f===0)return a.set(0,0,0),null;const m=1/f,g=(u*c-l*d)*m,x=(o*d-l*c)*m;return a.set(1-g-x,x,g)}static containsPoint(e,n,r,i){return this.getBarycoord(e,n,r,i,Sc)===null?!1:Sc.x>=0&&Sc.y>=0&&Sc.x+Sc.y<=1}static getInterpolation(e,n,r,i,a,o,l,c){return this.getBarycoord(e,n,r,i,Sc)===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(a,Sc.x),c.addScaledVector(o,Sc.y),c.addScaledVector(l,Sc.z),c)}static getInterpolatedAttribute(e,n,r,i,a,o){return zC.setScalar(0),BC.setScalar(0),$C.setScalar(0),zC.fromBufferAttribute(e,n),BC.fromBufferAttribute(e,r),$C.fromBufferAttribute(e,i),o.setScalar(0),o.addScaledVector(zC,a.x),o.addScaledVector(BC,a.y),o.addScaledVector($C,a.z),o}static isFrontFacing(e,n,r,i){return qo.subVectors(r,n),wc.subVectors(e,n),qo.cross(wc).dot(i)<0}set(e,n,r){return this.a.copy(e),this.b.copy(n),this.c.copy(r),this}setFromPointsAndIndices(e,n,r,i){return this.a.copy(e[n]),this.b.copy(e[r]),this.c.copy(e[i]),this}setFromAttributeAndIndices(e,n,r,i){return this.a.fromBufferAttribute(e,n),this.b.fromBufferAttribute(e,r),this.c.fromBufferAttribute(e,i),this}clone(){return new this.constructor().copy(this)}copy(e){return this.a.copy(e.a),this.b.copy(e.b),this.c.copy(e.c),this}getArea(){return qo.subVectors(this.c,this.b),wc.subVectors(this.a,this.b),qo.cross(wc).length()*.5}getMidpoint(e){return e.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(e){return kp.getNormal(this.a,this.b,this.c,e)}getPlane(e){return e.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(e,n){return kp.getBarycoord(e,this.a,this.b,this.c,n)}getInterpolation(e,n,r,i,a){return kp.getInterpolation(e,this.a,this.b,this.c,n,r,i,a)}containsPoint(e){return kp.containsPoint(e,this.a,this.b,this.c)}isFrontFacing(e){return kp.isFrontFacing(this.a,this.b,this.c,e)}intersectsBox(e){return e.intersectsTriangle(this)}closestPointToPoint(e,n){const r=this.a,i=this.b,a=this.c;let o,l;Qm.subVectors(i,r),Zm.subVectors(a,r),IC.subVectors(e,r);const c=Qm.dot(IC),u=Zm.dot(IC);if(c<=0&&u<=0)return n.copy(r);FC.subVectors(e,i);const d=Qm.dot(FC),f=Zm.dot(FC);if(d>=0&&f<=d)return n.copy(i);const m=c*f-d*u;if(m<=0&&c>=0&&d<=0)return o=c/(c-d),n.copy(r).addScaledVector(Qm,o);UC.subVectors(e,a);const g=Qm.dot(UC),x=Zm.dot(UC);if(x>=0&&g<=x)return n.copy(a);const y=g*u-c*x;if(y<=0&&u>=0&&x<=0)return l=u/(u-x),n.copy(r).addScaledVector(Zm,l);const b=d*x-g*f;if(b<=0&&f-d>=0&&g-x>=0)return kH.subVectors(a,i),l=(f-d)/(f-d+(g-x)),n.copy(i).addScaledVector(kH,l);const v=1/(b+y+m);return o=y*v,l=m*v,n.copy(r).addScaledVector(Qm,o).addScaledVector(Zm,l)}equals(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}};const nJ={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},Yu={h:0,s:0,l:0},k_={h:0,s:0,l:0};function HC(t,e,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+(e-t)*6*n:n<1/2?e:n<2/3?t+(e-t)*6*(2/3-n):t}let Dn=class{constructor(e,n,r){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(e,n,r)}set(e,n,r){if(n===void 0&&r===void 0){const i=e;i&&i.isColor?this.copy(i):typeof i=="number"?this.setHex(i):typeof i=="string"&&this.setStyle(i)}else this.setRGB(e,n,r);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,n=bo){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,Kn.colorSpaceToWorking(this,n),this}setRGB(e,n,r,i=Kn.workingColorSpace){return this.r=e,this.g=n,this.b=r,Kn.colorSpaceToWorking(this,i),this}setHSL(e,n,r,i=Kn.workingColorSpace){if(e=r3e(e,1),n=Rn(n,0,1),r=Rn(r,0,1),n===0)this.r=this.g=this.b=r;else{const a=r<=.5?r*(1+n):r+n-r*n,o=2*r-a;this.r=HC(o,a,e+1/3),this.g=HC(o,a,e),this.b=HC(o,a,e-1/3)}return Kn.colorSpaceToWorking(this,i),this}setStyle(e,n=bo){function r(a){a!==void 0&&parseFloat(a)<1&&mn("Color: Alpha component of "+e+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(e)){let a;const o=i[1],l=i[2];switch(o){case"rgb":case"rgba":if(a=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(l))return r(a[4]),this.setRGB(Math.min(255,parseInt(a[1],10))/255,Math.min(255,parseInt(a[2],10))/255,Math.min(255,parseInt(a[3],10))/255,n);if(a=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(l))return r(a[4]),this.setRGB(Math.min(100,parseInt(a[1],10))/100,Math.min(100,parseInt(a[2],10))/100,Math.min(100,parseInt(a[3],10))/100,n);break;case"hsl":case"hsla":if(a=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(l))return r(a[4]),this.setHSL(parseFloat(a[1])/360,parseFloat(a[2])/100,parseFloat(a[3])/100,n);break;default:mn("Color: Unknown color model "+e)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(e)){const a=i[1],o=a.length;if(o===3)return this.setRGB(parseInt(a.charAt(0),16)/15,parseInt(a.charAt(1),16)/15,parseInt(a.charAt(2),16)/15,n);if(o===6)return this.setHex(parseInt(a,16),n);mn("Color: Invalid hex color "+e)}else if(e&&e.length>0)return this.setColorName(e,n);return this}setColorName(e,n=bo){const r=nJ[e.toLowerCase()];return r!==void 0?this.setHex(r,n):mn("Color: Unknown color "+e),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}copySRGBToLinear(e){return this.r=tu(e.r),this.g=tu(e.g),this.b=tu(e.b),this}copyLinearToSRGB(e){return this.r=Yp(e.r),this.g=Yp(e.g),this.b=Yp(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=bo){return Kn.workingToColorSpace(Ea.copy(this),e),Math.round(Rn(Ea.r*255,0,255))*65536+Math.round(Rn(Ea.g*255,0,255))*256+Math.round(Rn(Ea.b*255,0,255))}getHexString(e=bo){return("000000"+this.getHex(e).toString(16)).slice(-6)}getHSL(e,n=Kn.workingColorSpace){Kn.workingToColorSpace(Ea.copy(this),n);const r=Ea.r,i=Ea.g,a=Ea.b,o=Math.max(r,i,a),l=Math.min(r,i,a);let c,u;const d=(l+o)/2;if(l===o)c=0,u=0;else{const f=o-l;switch(u=d<=.5?f/(o+l):f/(2-o-l),o){case r:c=(i-a)/f+(i0!=e>0&&this.version++,this._alphaTest=e}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(e){if(e!==void 0)for(const n in e){const r=e[n];if(r===void 0){mn(`Material: parameter '${n}' has value of undefined.`);continue}const i=this[n];if(i===void 0){mn(`Material: '${n}' is not a property of THREE.${this.type}.`);continue}i&&i.isColor?i.set(r):i&&i.isVector3&&r&&r.isVector3?i.copy(r):this[n]=r}}toJSON(e){const n=e===void 0||typeof e=="string";n&&(e={textures:{},images:{}});const r={metadata:{version:4.7,type:"Material",generator:"Material.toJSON"}};r.uuid=this.uuid,r.type=this.type,this.name!==""&&(r.name=this.name),this.color&&this.color.isColor&&(r.color=this.color.getHex()),this.roughness!==void 0&&(r.roughness=this.roughness),this.metalness!==void 0&&(r.metalness=this.metalness),this.sheen!==void 0&&(r.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(r.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(r.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(r.emissive=this.emissive.getHex()),this.emissiveIntensity!==void 0&&this.emissiveIntensity!==1&&(r.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(r.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(r.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(r.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(r.shininess=this.shininess),this.clearcoat!==void 0&&(r.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(r.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(r.clearcoatMap=this.clearcoatMap.toJSON(e).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(r.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(e).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(r.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(e).uuid,r.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(r.sheenColorMap=this.sheenColorMap.toJSON(e).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(r.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(e).uuid),this.dispersion!==void 0&&(r.dispersion=this.dispersion),this.iridescence!==void 0&&(r.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(r.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(r.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(r.iridescenceMap=this.iridescenceMap.toJSON(e).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(r.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(e).uuid),this.anisotropy!==void 0&&(r.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(r.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(r.anisotropyMap=this.anisotropyMap.toJSON(e).uuid),this.map&&this.map.isTexture&&(r.map=this.map.toJSON(e).uuid),this.matcap&&this.matcap.isTexture&&(r.matcap=this.matcap.toJSON(e).uuid),this.alphaMap&&this.alphaMap.isTexture&&(r.alphaMap=this.alphaMap.toJSON(e).uuid),this.lightMap&&this.lightMap.isTexture&&(r.lightMap=this.lightMap.toJSON(e).uuid,r.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(r.aoMap=this.aoMap.toJSON(e).uuid,r.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(r.bumpMap=this.bumpMap.toJSON(e).uuid,r.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(r.normalMap=this.normalMap.toJSON(e).uuid,r.normalMapType=this.normalMapType,r.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(r.displacementMap=this.displacementMap.toJSON(e).uuid,r.displacementScale=this.displacementScale,r.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(r.roughnessMap=this.roughnessMap.toJSON(e).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(r.metalnessMap=this.metalnessMap.toJSON(e).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(r.emissiveMap=this.emissiveMap.toJSON(e).uuid),this.specularMap&&this.specularMap.isTexture&&(r.specularMap=this.specularMap.toJSON(e).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(r.specularIntensityMap=this.specularIntensityMap.toJSON(e).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(r.specularColorMap=this.specularColorMap.toJSON(e).uuid),this.envMap&&this.envMap.isTexture&&(r.envMap=this.envMap.toJSON(e).uuid,this.combine!==void 0&&(r.combine=this.combine)),this.envMapRotation!==void 0&&(r.envMapRotation=this.envMapRotation.toArray()),this.envMapIntensity!==void 0&&(r.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(r.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(r.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(r.gradientMap=this.gradientMap.toJSON(e).uuid),this.transmission!==void 0&&(r.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(r.transmissionMap=this.transmissionMap.toJSON(e).uuid),this.thickness!==void 0&&(r.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(r.thicknessMap=this.thicknessMap.toJSON(e).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(r.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(r.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(r.size=this.size),this.shadowSide!==null&&(r.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(r.sizeAttenuation=this.sizeAttenuation),this.blending!==Xp&&(r.blending=this.blending),this.side!==Xd&&(r.side=this.side),this.vertexColors===!0&&(r.vertexColors=!0),this.opacity<1&&(r.opacity=this.opacity),this.transparent===!0&&(r.transparent=!0),this.blendSrc!==iP&&(r.blendSrc=this.blendSrc),this.blendDst!==aP&&(r.blendDst=this.blendDst),this.blendEquation!==Gh&&(r.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(r.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(r.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(r.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(r.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(r.blendAlpha=this.blendAlpha),this.depthFunc!==gg&&(r.depthFunc=this.depthFunc),this.depthTest===!1&&(r.depthTest=this.depthTest),this.depthWrite===!1&&(r.depthWrite=this.depthWrite),this.colorWrite===!1&&(r.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(r.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==pH&&(r.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(r.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(r.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==Hm&&(r.stencilFail=this.stencilFail),this.stencilZFail!==Hm&&(r.stencilZFail=this.stencilZFail),this.stencilZPass!==Hm&&(r.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(r.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(r.rotation=this.rotation),this.polygonOffset===!0&&(r.polygonOffset=!0),this.polygonOffsetFactor!==0&&(r.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(r.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(r.linewidth=this.linewidth),this.dashSize!==void 0&&(r.dashSize=this.dashSize),this.gapSize!==void 0&&(r.gapSize=this.gapSize),this.scale!==void 0&&(r.scale=this.scale),this.dithering===!0&&(r.dithering=!0),this.alphaTest>0&&(r.alphaTest=this.alphaTest),this.alphaHash===!0&&(r.alphaHash=!0),this.alphaToCoverage===!0&&(r.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(r.premultipliedAlpha=!0),this.forceSinglePass===!0&&(r.forceSinglePass=!0),this.wireframe===!0&&(r.wireframe=!0),this.wireframeLinewidth>1&&(r.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!=="round"&&(r.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!=="round"&&(r.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(r.flatShading=!0),this.visible===!1&&(r.visible=!1),this.toneMapped===!1&&(r.toneMapped=!1),this.fog===!1&&(r.fog=!1),Object.keys(this.userData).length>0&&(r.userData=this.userData);function i(a){const o=[];for(const l in a){const c=a[l];delete c.metadata,o.push(c)}return o}if(n){const a=i(e.textures),o=i(e.images);a.length>0&&(r.textures=a),o.length>0&&(r.images=o)}return r}clone(){return new this.constructor().copy(this)}copy(e){this.name=e.name,this.blending=e.blending,this.side=e.side,this.vertexColors=e.vertexColors,this.opacity=e.opacity,this.transparent=e.transparent,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.blendColor.copy(e.blendColor),this.blendAlpha=e.blendAlpha,this.depthFunc=e.depthFunc,this.depthTest=e.depthTest,this.depthWrite=e.depthWrite,this.stencilWriteMask=e.stencilWriteMask,this.stencilFunc=e.stencilFunc,this.stencilRef=e.stencilRef,this.stencilFuncMask=e.stencilFuncMask,this.stencilFail=e.stencilFail,this.stencilZFail=e.stencilZFail,this.stencilZPass=e.stencilZPass,this.stencilWrite=e.stencilWrite;const n=e.clippingPlanes;let r=null;if(n!==null){const i=n.length;r=new Array(i);for(let a=0;a!==i;++a)r[a]=n[a].clone()}return this.clippingPlanes=r,this.clipIntersection=e.clipIntersection,this.clipShadows=e.clipShadows,this.shadowSide=e.shadowSide,this.colorWrite=e.colorWrite,this.precision=e.precision,this.polygonOffset=e.polygonOffset,this.polygonOffsetFactor=e.polygonOffsetFactor,this.polygonOffsetUnits=e.polygonOffsetUnits,this.dithering=e.dithering,this.alphaTest=e.alphaTest,this.alphaHash=e.alphaHash,this.alphaToCoverage=e.alphaToCoverage,this.premultipliedAlpha=e.premultipliedAlpha,this.forceSinglePass=e.forceSinglePass,this.visible=e.visible,this.toneMapped=e.toneMapped,this.userData=JSON.parse(JSON.stringify(e.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){e===!0&&this.version++}},jO=class extends Jg{constructor(e){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new Dn(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 Yd,this.combine=_O,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}};const bi=new ot,j_=new Tn;let y3e=0,Ao=class{constructor(e,n,r=!1){if(Array.isArray(e))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:y3e++}),this.name="",this.array=e,this.itemSize=n,this.count=e!==void 0?e.length/n:0,this.normalized=r,this.usage=gH,this.updateRanges=[],this.gpuType=qc,this.version=0}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,n){this.updateRanges.push({start:e,count:n})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.name=e.name,this.array=new e.array.constructor(e.array),this.itemSize=e.itemSize,this.count=e.count,this.normalized=e.normalized,this.usage=e.usage,this.gpuType=e.gpuType,this}copyAt(e,n,r){e*=this.itemSize,r*=n.itemSize;for(let i=0,a=this.itemSize;in.count&&mn("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),n.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new $f);const e=this.attributes.position,n=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){di("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new ot(-1/0,-1/0,-1/0),new ot(1/0,1/0,1/0));return}if(e!==void 0){if(this.boundingBox.setFromBufferAttribute(e),n)for(let r=0,i=n.length;r0&&(e.userData=this.userData),this.parameters!==void 0){const c=this.parameters;for(const u in c)c[u]!==void 0&&(e[u]=c[u]);return e}e.data={attributes:{}};const n=this.index;n!==null&&(e.data.index={type:n.array.constructor.name,array:Array.prototype.slice.call(n.array)});const r=this.attributes;for(const c in r){const u=r[c];e.data.attributes[c]=u.toJSON(e.data)}const i={};let a=!1;for(const c in this.morphAttributes){const u=this.morphAttributes[c],d=[];for(let f=0,m=u.length;f0&&(i[c]=d,a=!0)}a&&(e.data.morphAttributes=i,e.data.morphTargetsRelative=this.morphTargetsRelative);const o=this.groups;o.length>0&&(e.data.groups=JSON.parse(JSON.stringify(o)));const l=this.boundingSphere;return l!==null&&(e.data.boundingSphere=l.toJSON()),e}clone(){return new this.constructor().copy(this)}copy(e){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const n={};this.name=e.name;const r=e.index;r!==null&&this.setIndex(r.clone());const i=e.attributes;for(const u in i){const d=i[u];this.setAttribute(u,d.clone(n))}const a=e.morphAttributes;for(const u in a){const d=[],f=a[u];for(let m=0,g=f.length;m0){const i=n[r[0]];if(i!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let a=0,o=i.length;a(e.far-e.near)**2))&&(jH.copy(a).invert(),kh.copy(e.ray).applyMatrix4(jH),!(r.boundingBox!==null&&kh.intersectsBox(r.boundingBox)===!1)&&this._computeIntersections(e,n,kh)))}_computeIntersections(e,n,r){let i;const a=this.geometry,o=this.material,l=a.index,c=a.attributes.position,u=a.attributes.uv,d=a.attributes.uv1,f=a.attributes.normal,m=a.groups,g=a.drawRange;if(l!==null)if(Array.isArray(o))for(let x=0,y=m.length;xn.far?null:{distance:u,point:I_.clone(),object:t}}function F_(t,e,n,r,i,a,o,l,c,u){t.getVertexPosition(l,R_),t.getVertexPosition(c,D_),t.getVertexPosition(u,O_);const d=_3e(t,e,n,r,R_,D_,O_,RH);if(d){const f=new ot;ub.getBarycoord(RH,R_,D_,O_,f),i&&(d.uv=ub.getInterpolatedAttribute(i,l,c,u,f,new Tn)),a&&(d.uv1=ub.getInterpolatedAttribute(a,l,c,u,f,new Tn)),o&&(d.normal=ub.getInterpolatedAttribute(o,l,c,u,f,new ot),d.normal.dot(r.direction)>0&&d.normal.multiplyScalar(-1));const m={a:l,b:c,c:u,normal:new ot,materialIndex:0};ub.getNormal(R_,D_,O_,m.normal),d.face=m,d.barycoord=f}return d}let PO=class sJ extends tc{constructor(e=1,n=1,r=1,i=1,a=1,o=1){super(),this.type="BoxGeometry",this.parameters={width:e,height:n,depth:r,widthSegments:i,heightSegments:a,depthSegments:o};const l=this;i=Math.floor(i),a=Math.floor(a),o=Math.floor(o);const c=[],u=[],d=[],f=[];let m=0,g=0;x("z","y","x",-1,-1,r,n,e,o,a,0),x("z","y","x",1,-1,r,n,-e,o,a,1),x("x","z","y",1,1,e,r,n,i,o,2),x("x","z","y",1,-1,e,r,-n,i,o,3),x("x","y","z",1,-1,e,n,r,i,a,4),x("x","y","z",-1,-1,e,n,-r,i,a,5),this.setIndex(c),this.setAttribute("position",new ol(u,3)),this.setAttribute("normal",new ol(d,3)),this.setAttribute("uv",new ol(f,2));function x(y,b,v,N,S,E,T,C,A,D,k){const R=E/A,F=T/D,O=E/2,X=T/2,j=C/2,W=A+1,Y=D+1;let q=0,Z=0;const ee=new ot;for(let ne=0;ne0?1:-1,d.push(ee.x,ee.y,ee.z),f.push(G/A),f.push(1-ne/D),q+=1}}for(let ne=0;ne - +