diff --git a/package-lock.json b/package-lock.json index 78b3bad..ebd0d26 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,8 @@ "@mui/icons-material": "^9.0.1", "@mui/lab": "^9.0.0-beta.3", "@mui/material": "^9.0.1", + "@react-three/drei": "^10.7.9", + "@react-three/fiber": "^9.8.2", "date-fns": "^4.2.1", "hamburger-react": "^2.4.0", "leaflet": "^1.9.4", @@ -30,13 +32,15 @@ "react-player": "^2.9.0", "react-responsive-carousel": "^3.2.22", "react-rotating-text": "^1.4.1", - "react-visibility-sensor": "^5.1.1" + "react-visibility-sensor": "^5.1.1", + "three": "^0.187.0" }, "devDependencies": { "@types/leaflet": "^1.9.21", "@types/node": "^25.9.1", "@types/react": "^19.2.15", "@types/react-dom": "^19.2.3", + "@types/three": "^0.187.0", "eslint": "^8.7.0", "eslint-config-airbnb": "^19.0.4", "eslint-config-prettier": "^8.3.0", @@ -191,6 +195,12 @@ "node": ">=6.9.0" } }, + "node_modules/@dimforge/rapier3d-compat": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@dimforge/rapier3d-compat/-/rapier3d-compat-0.12.0.tgz", + "integrity": "sha512-uekIGetywIgopfD97oDL5PfeezkFpNhwlzlaEYNOA0N6ghdsOvh/HYjSMek5Q2O1PYvRSDFcqFVJl4r4ZBwOow==", + "license": "Apache-2.0" + }, "node_modules/@emnapi/runtime": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.10.0.tgz", @@ -949,6 +959,24 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "node_modules/@mediapipe/tasks-vision": { + "version": "0.10.17", + "resolved": "https://registry.npmjs.org/@mediapipe/tasks-vision/-/tasks-vision-0.10.17.tgz", + "integrity": "sha512-CZWV/q6TTe8ta61cZXjfnnHsfWIdFhms03M9T7Cnd5y2mdpylJM0rF1qRq+wsQVRMLz1OYPVEBU9ph2Bx8cxrg==", + "license": "Apache-2.0" + }, + "node_modules/@monogrid/gainmap-js": { + "version": "3.7.3", + "resolved": "https://registry.npmjs.org/@monogrid/gainmap-js/-/gainmap-js-3.7.3.tgz", + "integrity": "sha512-YjgdH65wZ9lQnzkVWerrR9FJR0JYhn3ahV7DJqDZVtIvR/kWv7XzFbMSIOFS/47+nWbZ5zFTRxsFhq0OX//SuA==", + "license": "MIT", + "dependencies": { + "promise-worker-transferable": "^1.0.4" + }, + "peerDependencies": { + "three": ">= 0.159.0" + } + }, "node_modules/@mui/core-downloads-tracker": { "version": "9.0.1", "resolved": "https://registry.npmjs.org/@mui/core-downloads-tracker/-/core-downloads-tracker-9.0.1.tgz", @@ -1431,6 +1459,100 @@ "react-dom": "^19.0.0" } }, + "node_modules/@react-three/drei": { + "version": "10.7.9", + "resolved": "https://registry.npmjs.org/@react-three/drei/-/drei-10.7.9.tgz", + "integrity": "sha512-wP4Y6o58KFi+hT1zCfjJarRtPCT6WW/lo53WMiA/aCORuUvBzW916XsCtadnIB1KB+3IQNcDU5JeVh/gYb8MYw==", + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.26.0", + "@mediapipe/tasks-vision": "0.10.17", + "@monogrid/gainmap-js": "^3.0.6", + "@use-gesture/react": "^10.3.1", + "camera-controls": "^3.1.0", + "cross-env": "^7.0.3", + "detect-gpu": "^5.0.56", + "glsl-noise": "^0.0.0", + "hls.js": "^1.5.17", + "maath": "^0.10.8", + "meshline": "^3.3.1", + "stats-gl": "^2.2.8", + "stats.js": "^0.17.0", + "suspend-react": "^0.1.3", + "three-mesh-bvh": "^0.8.3", + "three-stdlib": "^2.35.6", + "troika-three-text": "^0.52.4", + "tunnel-rat": "^0.1.2", + "use-sync-external-store": "^1.4.0", + "utility-types": "^3.11.0", + "zustand": "^5.0.1" + }, + "peerDependencies": { + "@react-three/fiber": "^9.0.0", + "react": "^19", + "react-dom": "^19", + "three": ">=0.159" + }, + "peerDependenciesMeta": { + "react-dom": { + "optional": true + } + } + }, + "node_modules/@react-three/fiber": { + "version": "9.8.2", + "resolved": "https://registry.npmjs.org/@react-three/fiber/-/fiber-9.8.2.tgz", + "integrity": "sha512-6s0ejw0bT1myQ/aLLugcil8/zBmNnnHw/AISWF1yfDLOxfX3yYaTS+0IkpJITEnm/SSMLtxje6CJDt0i5Wu1Sw==", + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.17.8", + "@types/webxr": "*", + "base64-js": "^1.5.1", + "buffer": "^6.0.3", + "its-fine": "^2.1.1", + "react-use-measure": "^2.1.7", + "scheduler": "^0.28.0", + "suspend-react": "^0.1.3", + "use-sync-external-store": "^1.4.0", + "zustand": "^5.0.3" + }, + "peerDependencies": { + "expo": ">=43.0", + "expo-asset": ">=8.4", + "expo-file-system": ">=11.0", + "expo-gl": ">=11.0", + "react": ">=19 <19.4", + "react-dom": ">=19 <19.4", + "react-native": ">=0.78", + "three": ">=0.156" + }, + "peerDependenciesMeta": { + "expo": { + "optional": true + }, + "expo-asset": { + "optional": true + }, + "expo-file-system": { + "optional": true + }, + "expo-gl": { + "optional": true + }, + "react-dom": { + "optional": true + }, + "react-native": { + "optional": true + } + } + }, + "node_modules/@react-three/fiber/node_modules/scheduler": { + "version": "0.28.0", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.28.0.tgz", + "integrity": "sha512-juorfCmIkIw8tT+p5BXSm6PJjQF/ycEYmKyzURCIt/RaZIhL+PulbQ9Yu2z1HdOJDdqDTlxA1+xKBmHXJsczAw==", + "license": "MIT" + }, "node_modules/@rtsao/scc": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@rtsao/scc/-/scc-1.1.0.tgz", @@ -1447,6 +1569,18 @@ "tslib": "^2.8.0" } }, + "node_modules/@tweenjs/tween.js": { + "version": "23.1.3", + "resolved": "https://registry.npmjs.org/@tweenjs/tween.js/-/tween.js-23.1.3.tgz", + "integrity": "sha512-vJmvvwFxYuGnF2axRtPYocag6Clbb5YS7kLL+SO/TeVFzHqDIWrNKYtcsPMibjDx9O+bu+psAy9NKfWklassUA==", + "license": "MIT" + }, + "node_modules/@types/draco3d": { + "version": "1.4.10", + "resolved": "https://registry.npmjs.org/@types/draco3d/-/draco3d-1.4.10.tgz", + "integrity": "sha512-AX22jp8Y7wwaBgAixaSvkoG4M/+PlAcm3Qs4OW8yT9DM4xUpWKeFhLueTAyZF39pviAdcDdeJoACapiAceqNcw==", + "license": "MIT" + }, "node_modules/@types/geojson": { "version": "7946.0.16", "resolved": "https://registry.npmjs.org/@types/geojson/-/geojson-7946.0.16.tgz", @@ -1481,6 +1615,12 @@ "undici-types": ">=7.24.0 <7.24.7" } }, + "node_modules/@types/offscreencanvas": { + "version": "2019.7.3", + "resolved": "https://registry.npmjs.org/@types/offscreencanvas/-/offscreencanvas-2019.7.3.tgz", + "integrity": "sha512-ieXiYmgSRXUDeOntE1InxjWyvEelZGP63M+cGuquuRLuIKKT1osnkXjxev9B7d1nXSug5vpunx+gNlbVxMlC9A==", + "license": "MIT" + }, "node_modules/@types/parse-json": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.2.tgz", @@ -1512,6 +1652,15 @@ "@types/react": "^19.2.0" } }, + "node_modules/@types/react-reconciler": { + "version": "0.28.9", + "resolved": "https://registry.npmjs.org/@types/react-reconciler/-/react-reconciler-0.28.9.tgz", + "integrity": "sha512-HHM3nxyUZ3zAylX8ZEyrDNd2XZOnQ0D5XfunJF5FLQnZbHHYq4UWvW1QfelQNXv1ICNkwYhfxjwfnqivYB6bFg==", + "license": "MIT", + "peerDependencies": { + "@types/react": "*" + } + }, "node_modules/@types/react-transition-group": { "version": "4.4.12", "resolved": "https://registry.npmjs.org/@types/react-transition-group/-/react-transition-group-4.4.12.tgz", @@ -1521,6 +1670,32 @@ "@types/react": "*" } }, + "node_modules/@types/stats.js": { + "version": "0.17.4", + "resolved": "https://registry.npmjs.org/@types/stats.js/-/stats.js-0.17.4.tgz", + "integrity": "sha512-jIBvWWShCvlBqBNIZt0KAshWpvSjhkwkEu4ZUcASoAvhmrgAUI2t1dXrjSL4xXVLB4FznPrIsX3nKXFl/Dt4vA==", + "license": "MIT" + }, + "node_modules/@types/three": { + "version": "0.187.0", + "resolved": "https://registry.npmjs.org/@types/three/-/three-0.187.0.tgz", + "integrity": "sha512-v+vKNarUtk4n2QRZ4+CN5ygMM0ARUjXjIQl0R/unMUfmStFeVqGbgqarbrpoGTXRZoulSH16ePrVJVxPJEbMUA==", + "license": "MIT", + "dependencies": { + "@dimforge/rapier3d-compat": "~0.12.0", + "@tweenjs/tween.js": "~23.1.3", + "@types/stats.js": "*", + "@types/webxr": ">=0.5.17", + "fflate": "~0.8.3", + "meshoptimizer": "~1.1.1" + } + }, + "node_modules/@types/webxr": { + "version": "0.5.24", + "resolved": "https://registry.npmjs.org/@types/webxr/-/webxr-0.5.24.tgz", + "integrity": "sha512-h8fgEd/DpoS9CBrjEQXR+dIDraopAEfu4wYVNY2tEPwk60stPWhvZMf4Foo5FakuQ7HFZoa8WceaWFervK2Ovg==", + "license": "MIT" + }, "node_modules/@ungap/structured-clone": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.3.1.tgz", @@ -1528,6 +1703,24 @@ "dev": true, "license": "ISC" }, + "node_modules/@use-gesture/core": { + "version": "10.3.1", + "resolved": "https://registry.npmjs.org/@use-gesture/core/-/core-10.3.1.tgz", + "integrity": "sha512-WcINiDt8WjqBdUXye25anHiNxPc0VOrlT8F6LLkU6cycrOGUDyY/yyFmsg3k8i5OLvv25llc0QC45GhR/C8llw==", + "license": "MIT" + }, + "node_modules/@use-gesture/react": { + "version": "10.3.1", + "resolved": "https://registry.npmjs.org/@use-gesture/react/-/react-10.3.1.tgz", + "integrity": "sha512-Yy19y6O2GJq8f7CHf7L0nxL8bf4PZCPaVOCgJrusOeFHY1LvHgYXnmnXg6N5iwAnbgbZCDjo60SiM6IPJi9C5g==", + "license": "MIT", + "dependencies": { + "@use-gesture/core": "10.3.1" + }, + "peerDependencies": { + "react": ">= 16.8.0" + } + }, "node_modules/acorn": { "version": "8.16.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz", @@ -1867,6 +2060,26 @@ "dev": true, "license": "MIT" }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, "node_modules/baseline-browser-mapping": { "version": "2.10.31", "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.10.31.tgz", @@ -1879,6 +2092,15 @@ "node": ">=6.0.0" } }, + "node_modules/bidi-js": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/bidi-js/-/bidi-js-1.1.0.tgz", + "integrity": "sha512-fX1Onk0tdVPC7obPWB5EbJ1z7NVhLq4m2xZLq2YXBkxzMXIGRpNMU88n0EPgWseKl12J7zXs7qrDxPK4sRs2fg==", + "license": "MIT", + "dependencies": { + "require-from-string": "^2.0.2" + } + }, "node_modules/brace-expansion": { "version": "1.1.14", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.14.tgz", @@ -1890,6 +2112,30 @@ "concat-map": "0.0.1" } }, + "node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT", + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, "node_modules/call-bind": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.9.tgz", @@ -1949,6 +2195,19 @@ "node": ">=6" } }, + "node_modules/camera-controls": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/camera-controls/-/camera-controls-3.1.2.tgz", + "integrity": "sha512-xkxfpG2ECZ6Ww5/9+kf4mfg1VEYAoe9aDSY+IwF0UEs7qEzwy0aVRfs2grImIECs/PoBtWFrh7RXsQkwG922JA==", + "license": "MIT", + "engines": { + "node": ">=22.0.0", + "npm": ">=10.5.1" + }, + "peerDependencies": { + "three": ">=0.126.1" + } + }, "node_modules/caniuse-lite": { "version": "1.0.30001793", "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001793.tgz", @@ -2069,11 +2328,28 @@ "integrity": "sha512-QQpZx7oYxsR+OeITlZe46fY/OQjV11oBqjY8wgIXzLU2jIz8GzOrbMhqKLysGY8bWI3T1ZNrYkwGzKb4JNgyzg==", "license": "MIT" }, + "node_modules/cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "license": "MIT", + "dependencies": { + "cross-spawn": "^7.0.1" + }, + "bin": { + "cross-env": "src/bin/cross-env.js", + "cross-env-shell": "src/bin/cross-env-shell.js" + }, + "engines": { + "node": ">=10.14", + "npm": ">=6", + "yarn": ">=1" + } + }, "node_modules/cross-spawn": { "version": "7.0.6", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", - "dev": true, "license": "MIT", "dependencies": { "path-key": "^3.1.0", @@ -2230,6 +2506,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/detect-gpu": { + "version": "5.0.70", + "resolved": "https://registry.npmjs.org/detect-gpu/-/detect-gpu-5.0.70.tgz", + "integrity": "sha512-bqerEP1Ese6nt3rFkwPnGbsUF9a4q+gMmpTVVOEzoCyeCc+y7/RvJnQZJx1JwhgQI5Ntg0Kgat8Uu7XpBqnz1w==", + "license": "MIT", + "dependencies": { + "webgl-constants": "^1.1.1" + } + }, "node_modules/detect-libc": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", @@ -2263,6 +2548,12 @@ "csstype": "^3.0.2" } }, + "node_modules/draco3d": { + "version": "1.5.9", + "resolved": "https://registry.npmjs.org/draco3d/-/draco3d-1.5.9.tgz", + "integrity": "sha512-MqC0eAfW5gPATGY3GABIyFWpHwdDGAyewTdek5R/e+mhI9ZDUMKb2mTDkTMUW0+Vm7an+ThEMUop3+svS72Uug==", + "license": "Apache-2.0" + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", @@ -2944,6 +3235,12 @@ "reusify": "^1.0.4" } }, + "node_modules/fflate": { + "version": "0.8.3", + "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.3.tgz", + "integrity": "sha512-tbZNuJrLwGUp3zshBtdy4W+ORxZuIh8a5ilyIEQDC5rY1f3U20JMry0Ll3WBzU58EZKsEuJFXhb5gwv8CsPvgA==", + "license": "MIT" + }, "node_modules/file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", @@ -3200,6 +3497,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/glsl-noise": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/glsl-noise/-/glsl-noise-0.0.0.tgz", + "integrity": "sha512-b/ZCF6amfAUb7dJM/MxRs7AetQEahYzJ8PtgfrmEdtw6uyGOr+ZSGtgjFm6mfsBkxJ4d2W7kg+Nlqzqvn3Bc0w==", + "license": "MIT" + }, "node_modules/gopd": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", @@ -3322,6 +3625,12 @@ "node": ">= 0.4" } }, + "node_modules/hls.js": { + "version": "1.7.4", + "resolved": "https://registry.npmjs.org/hls.js/-/hls.js-1.7.4.tgz", + "integrity": "sha512-3GlxGdPvT2YHvQYOt+yOzT/DEior/qJVNIylHA77kgeoBTdQQqi70GwefNEUmHQeNGyjC8U62+bruqW/Tpm+tg==", + "license": "Apache-2.0" + }, "node_modules/hoist-non-react-statics": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz", @@ -3331,6 +3640,26 @@ "react-is": "^16.7.0" } }, + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "BSD-3-Clause" + }, "node_modules/ignore": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", @@ -3341,6 +3670,12 @@ "node": ">= 4" } }, + "node_modules/immediate": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz", + "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==", + "license": "MIT" + }, "node_modules/import-fresh": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.1.tgz", @@ -3653,6 +3988,12 @@ "node": ">=8" } }, + "node_modules/is-promise": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.2.2.tgz", + "integrity": "sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==", + "license": "MIT" + }, "node_modules/is-regex": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.2.1.tgz", @@ -3809,7 +4150,6 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", - "dev": true, "license": "ISC" }, "node_modules/iterator.prototype": { @@ -3830,6 +4170,18 @@ "node": ">= 0.4" } }, + "node_modules/its-fine": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/its-fine/-/its-fine-2.1.1.tgz", + "integrity": "sha512-C5ZoVkeqSt0Aje0tzESO+iT/EQpNFNL39GkP7mCACtoZUFD6GcyerFCr6kp0ZtiII4W9HoYkY48Soy5xE/uHKw==", + "license": "MIT", + "dependencies": { + "@types/react-reconciler": "^0.28.9" + }, + "peerDependencies": { + "react": "^19.0.0" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -3973,6 +4325,15 @@ "node": ">= 0.8.0" } }, + "node_modules/lie": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz", + "integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==", + "license": "MIT", + "dependencies": { + "immediate": "~3.0.5" + } + }, "node_modules/lines-and-columns": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz", @@ -4026,6 +4387,16 @@ "loose-envify": "cli.js" } }, + "node_modules/maath": { + "version": "0.10.8", + "resolved": "https://registry.npmjs.org/maath/-/maath-0.10.8.tgz", + "integrity": "sha512-tRvbDF0Pgqz+9XUa4jjfgAQ8/aPKmQdWXilFu2tMy4GWj4NOsx99HlULO4IeREfbO3a0sA145DZYyvXPkybm0g==", + "license": "MIT", + "peerDependencies": { + "@types/three": ">=0.134.0", + "three": ">=0.134.0" + } + }, "node_modules/math-intrinsics": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", @@ -4042,6 +4413,21 @@ "integrity": "sha512-zYiwtZUcYyXKo/np96AGZAckk+FWWsUdJ3cHGGmld7+AhvcWmQyGCYUh1hc4Q/pkOhb65dQR/pqCyK0cOaHz4Q==", "license": "MIT" }, + "node_modules/meshline": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/meshline/-/meshline-3.3.1.tgz", + "integrity": "sha512-/TQj+JdZkeSUOl5Mk2J7eLcYTLiQm2IDzmlSvYm7ov15anEcDJ92GHqqazxTSreeNgfnYu24kiEvvv0WlbCdFQ==", + "license": "MIT", + "peerDependencies": { + "three": ">=0.137" + } + }, + "node_modules/meshoptimizer": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/meshoptimizer/-/meshoptimizer-1.1.1.tgz", + "integrity": "sha512-oRFNWJRDA/WTrVj7NWvqa5HqE1t9MYDj2VaWirQCzCCrAd2GHrqR/sQezCxiWATPNlKTcRaPRHPJwIRoPBAp5g==", + "license": "MIT" + }, "node_modules/minimatch": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.5.tgz", @@ -4449,7 +4835,6 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -4514,6 +4899,12 @@ "node": "^10 || ^12 || >=14" } }, + "node_modules/potpack": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/potpack/-/potpack-1.0.2.tgz", + "integrity": "sha512-choctRBIV9EMT9WGAZHn3V7t0Z2pMQyl0EZE6pFc/6ml3ssw7Dlf/oAOvFwjm1HVsqfQN8GfeFyJ+d8tRzqueQ==", + "license": "ISC" + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", @@ -4553,6 +4944,16 @@ "node": ">=6.0.0" } }, + "node_modules/promise-worker-transferable": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/promise-worker-transferable/-/promise-worker-transferable-1.0.4.tgz", + "integrity": "sha512-bN+0ehEnrXfxV2ZQvU2PetO0n4gqBD4ulq3MI1WOPLgr7/Mg9yRQkX5+0v1vagr74ZTsl7XtzlaYDo2EuCeYJw==", + "license": "Apache-2.0", + "dependencies": { + "is-promise": "^2.1.0", + "lie": "^3.0.2" + } + }, "node_modules/prop-types": { "version": "15.8.1", "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz", @@ -4732,6 +5133,21 @@ "react-dom": ">=16.6.0" } }, + "node_modules/react-use-measure": { + "version": "2.1.7", + "resolved": "https://registry.npmjs.org/react-use-measure/-/react-use-measure-2.1.7.tgz", + "integrity": "sha512-KrvcAo13I/60HpwGO5jpW7E9DfusKyLPLvuHlUyP5zqnmAPhNc6qTRjUQrdTADl0lpPpDVU2/Gg51UlOGHXbdg==", + "license": "MIT", + "peerDependencies": { + "react": ">=16.13", + "react-dom": ">=16.13" + }, + "peerDependenciesMeta": { + "react-dom": { + "optional": true + } + } + }, "node_modules/react-visibility-sensor": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/react-visibility-sensor/-/react-visibility-sensor-5.1.1.tgz", @@ -4789,6 +5205,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/resolve": { "version": "2.0.0-next.7", "resolved": "https://registry.npmjs.org/resolve/-/resolve-2.0.0-next.7.tgz", @@ -5056,7 +5481,6 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", - "dev": true, "license": "MIT", "dependencies": { "shebang-regex": "^3.0.0" @@ -5069,7 +5493,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -5169,6 +5592,32 @@ "node": ">=0.10.0" } }, + "node_modules/stats-gl": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/stats-gl/-/stats-gl-2.4.2.tgz", + "integrity": "sha512-g5O9B0hm9CvnM36+v7SFl39T7hmAlv541tU81ME8YeSb3i1CIP5/QdDeSB3A0la0bKNHpxpwxOVRo2wFTYEosQ==", + "license": "MIT", + "dependencies": { + "@types/three": "*", + "three": "^0.170.0" + }, + "peerDependencies": { + "@types/three": "*", + "three": "*" + } + }, + "node_modules/stats-gl/node_modules/three": { + "version": "0.170.0", + "resolved": "https://registry.npmjs.org/three/-/three-0.170.0.tgz", + "integrity": "sha512-FQK+LEpYc0fBD+J8g6oSEyyNzjp+Q7Ks1C568WWaoMRLW+TkNNWmenWeGgJjV105Gd+p/2ql1ZcjYvNiPZBhuQ==", + "license": "MIT" + }, + "node_modules/stats.js": { + "version": "0.17.0", + "resolved": "https://registry.npmjs.org/stats.js/-/stats.js-0.17.0.tgz", + "integrity": "sha512-hNKz8phvYLPEcRkeG1rsGmV5ChMjKDAWU7/OJJdDErPBNChQXxCo3WZurGpnWc6gZhAzEPFad1aVgyOANH1sMw==", + "license": "MIT" + }, "node_modules/stop-iteration-iterator": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/stop-iteration-iterator/-/stop-iteration-iterator-1.1.0.tgz", @@ -5386,6 +5835,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/suspend-react": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/suspend-react/-/suspend-react-0.1.3.tgz", + "integrity": "sha512-aqldKgX9aZqpoDp3e8/BZ8Dm7x1pJl+qI3ZKxDN0i/IQTWUwBx/ManmlVJ3wowqbno6c2bmiIfs+Um6LbsjJyQ==", + "license": "MIT", + "peerDependencies": { + "react": ">=17.0" + } + }, "node_modules/text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", @@ -5393,6 +5851,74 @@ "dev": true, "license": "MIT" }, + "node_modules/three": { + "version": "0.187.0", + "resolved": "https://registry.npmjs.org/three/-/three-0.187.0.tgz", + "integrity": "sha512-Qiu7R+Cmh8CstZsY1uJOSWnVlfo7ZtNLV7mF8Jltk3LB3AtDu9cRZlcnRKkAk8Y4z6KKw35z7Y7Urd7jWY8etA==", + "license": "MIT" + }, + "node_modules/three-mesh-bvh": { + "version": "0.8.3", + "resolved": "https://registry.npmjs.org/three-mesh-bvh/-/three-mesh-bvh-0.8.3.tgz", + "integrity": "sha512-4G5lBaF+g2auKX3P0yqx+MJC6oVt6sB5k+CchS6Ob0qvH0YIhuUk1eYr7ktsIpY+albCqE80/FVQGV190PmiAg==", + "license": "MIT", + "peerDependencies": { + "three": ">= 0.159.0" + } + }, + "node_modules/three-stdlib": { + "version": "2.36.1", + "resolved": "https://registry.npmjs.org/three-stdlib/-/three-stdlib-2.36.1.tgz", + "integrity": "sha512-XyGQrFmNQ5O/IoKm556ftwKsBg11TIb301MB5dWNicziQBEs2g3gtOYIf7pFiLa0zI2gUwhtCjv9fmjnxKZ1Cg==", + "license": "MIT", + "dependencies": { + "@types/draco3d": "^1.4.0", + "@types/offscreencanvas": "^2019.6.4", + "@types/webxr": "^0.5.2", + "draco3d": "^1.4.1", + "fflate": "^0.6.9", + "potpack": "^1.0.1" + }, + "peerDependencies": { + "three": ">=0.128.0" + } + }, + "node_modules/three-stdlib/node_modules/fflate": { + "version": "0.6.11", + "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.6.11.tgz", + "integrity": "sha512-3JyEFWGjFn7zHmoa9+zG1BmW7X2okcmAB+0Cnu9UFbVs/jCBnl2A8o065ZlXiw145K3eBM3uLuzrYXC0RK7eDg==", + "license": "MIT" + }, + "node_modules/troika-three-text": { + "version": "0.52.5", + "resolved": "https://registry.npmjs.org/troika-three-text/-/troika-three-text-0.52.5.tgz", + "integrity": "sha512-Ry3jRhic9pzcY4JduSvRRyDmVOSqEW19gT4vtK+aCiPNVcDlmkxvGG0YbFd36RTDq1wExOupXnvNF/j1oiHHDA==", + "license": "MIT", + "dependencies": { + "bidi-js": "^1.0.2", + "troika-three-utils": "^0.52.5", + "troika-worker-utils": "^0.52.0", + "webgl-sdf-generator": "1.1.1" + }, + "peerDependencies": { + "three": ">=0.125.0" + } + }, + "node_modules/troika-three-utils": { + "version": "0.52.5", + "resolved": "https://registry.npmjs.org/troika-three-utils/-/troika-three-utils-0.52.5.tgz", + "integrity": "sha512-WsePbcX8RtfidRfsxK1eCZCjF81ZDzAKHH/evLs0hdV2wpoCb0vArGZHdzdOJrSS3k4zfdtbKDaBh8+phkrYnw==", + "license": "MIT", + "peerDependencies": { + "three": ">=0.125.0" + } + }, + "node_modules/troika-worker-utils": { + "version": "0.52.0", + "resolved": "https://registry.npmjs.org/troika-worker-utils/-/troika-worker-utils-0.52.0.tgz", + "integrity": "sha512-W1CpvTHykaPH5brv5VHLfQo9D1OYuo0cSBEUQFFT/nBUzM8iD6Lq2/tgG/f1OelbAS1WtaTPQzE5uM49egnngw==", + "license": "MIT" + }, "node_modules/tsconfig-paths": { "version": "3.15.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.15.0.tgz", @@ -5412,6 +5938,43 @@ "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", "license": "0BSD" }, + "node_modules/tunnel-rat": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/tunnel-rat/-/tunnel-rat-0.1.2.tgz", + "integrity": "sha512-lR5VHmkPhzdhrM092lI2nACsLO4QubF0/yoOhzX7c+wIpbN1GjHNzCc91QlpxBi+cnx8vVJ+Ur6vL5cEoQPFpQ==", + "license": "MIT", + "dependencies": { + "zustand": "^4.3.2" + } + }, + "node_modules/tunnel-rat/node_modules/zustand": { + "version": "4.5.7", + "resolved": "https://registry.npmjs.org/zustand/-/zustand-4.5.7.tgz", + "integrity": "sha512-CHOUy7mu3lbD6o6LJLfllpjkzhHXSBlX8B9+qPddUsIfeF5S/UZ5q0kmCsnRqT1UHFQZchNFDDzMbQsuesHWlw==", + "license": "MIT", + "dependencies": { + "use-sync-external-store": "^1.2.2" + }, + "engines": { + "node": ">=12.7.0" + }, + "peerDependencies": { + "@types/react": ">=16.8", + "immer": ">=9.0.6", + "react": ">=16.8" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "immer": { + "optional": true + }, + "react": { + "optional": true + } + } + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -5566,11 +6129,39 @@ "punycode": "^2.1.0" } }, + "node_modules/use-sync-external-store": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.7.0.tgz", + "integrity": "sha512-6L+EeigHMQhdaIPNIFUKwfWJSwWFQ8gJbJ2DLOs5sDIegTwR9fRxvnM3uciHKjIZhFz+KAv2emhWMRvDmMcY8A==", + "license": "MIT", + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" + } + }, + "node_modules/utility-types": { + "version": "3.11.0", + "resolved": "https://registry.npmjs.org/utility-types/-/utility-types-3.11.0.tgz", + "integrity": "sha512-6Z7Ma2aVEWisaL6TvBCy7P8rm2LQoPv6dJ7ecIaIixHcwfbJ0x7mWdbcwlIM5IGQxPZSFYeqRCqlOOeKoJYMkw==", + "license": "MIT", + "engines": { + "node": ">= 4" + } + }, + "node_modules/webgl-constants": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/webgl-constants/-/webgl-constants-1.1.1.tgz", + "integrity": "sha512-LkBXKjU5r9vAW7Gcu3T5u+5cvSvh5WwINdr0C+9jpzVB41cjQAP5ePArDtk/WHYdVj0GefCgM73BA7FlIiNtdg==" + }, + "node_modules/webgl-sdf-generator": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/webgl-sdf-generator/-/webgl-sdf-generator-1.1.1.tgz", + "integrity": "sha512-9Z0JcMTFxeE+b2x1LJTdnaT8rT8aEp7MVxkNwoycNmJWwPdzoXzMh0BjJSh/AEFP+KPYZUli814h8bJZFIZ2jA==", + "license": "MIT" + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", - "dev": true, "license": "ISC", "dependencies": { "isexe": "^2.0.0" @@ -5709,6 +6300,35 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "node_modules/zustand": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/zustand/-/zustand-5.1.0.tgz", + "integrity": "sha512-ciJZlP48M1PTQbVQq81CGVFxHTLpZNrFjKqwjtCU34AWuXTZT/jrF3p9+fI84Cf1eSCMLapxqBy/SNTfwOBuqA==", + "license": "MIT", + "engines": { + "node": ">=12.20.0" + }, + "peerDependencies": { + "@types/react": ">=18.0.0", + "immer": ">=9.0.6", + "react": ">=18.0.0", + "use-sync-external-store": ">=1.2.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "immer": { + "optional": true + }, + "react": { + "optional": true + }, + "use-sync-external-store": { + "optional": true + } + } } } } diff --git a/package.json b/package.json index 0d57f7a..3fd1072 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,8 @@ "@mui/icons-material": "^9.0.1", "@mui/lab": "^9.0.0-beta.3", "@mui/material": "^9.0.1", + "@react-three/drei": "^10.7.9", + "@react-three/fiber": "^9.8.2", "date-fns": "^4.2.1", "hamburger-react": "^2.4.0", "leaflet": "^1.9.4", @@ -72,13 +74,15 @@ "react-player": "^2.9.0", "react-responsive-carousel": "^3.2.22", "react-rotating-text": "^1.4.1", - "react-visibility-sensor": "^5.1.1" + "react-visibility-sensor": "^5.1.1", + "three": "^0.187.0" }, "devDependencies": { "@types/leaflet": "^1.9.21", "@types/node": "^25.9.1", "@types/react": "^19.2.15", "@types/react-dom": "^19.2.3", + "@types/three": "^0.187.0", "eslint": "^8.7.0", "eslint-config-airbnb": "^19.0.4", "eslint-config-prettier": "^8.3.0", diff --git a/pages/launches/[launchName].tsx b/pages/launches/[launchName].tsx index 266dc1e..7cf8022 100644 --- a/pages/launches/[launchName].tsx +++ b/pages/launches/[launchName].tsx @@ -1,7 +1,8 @@ import React, { useEffect, useMemo, useState } from 'react'; import { useRouter } from 'next/router'; import ArrowBackIcon from '@mui/icons-material/ArrowBack'; -import { Alert, Box, Button, Card, CardContent, CircularProgress, Container, Stack, Typography } from '@mui/material'; +import { Alert, Box, Button, Card, CardContent, CircularProgress } from '@mui/material'; +import { Container, Stack, ToggleButton, ToggleButtonGroup, Typography } from '@mui/material'; import HeightIcon from '@mui/icons-material/Height'; import ScheduleIcon from '@mui/icons-material/Schedule'; import RouteIcon from '@mui/icons-material/Route'; @@ -38,6 +39,7 @@ export default function LaunchDetailsPage() { const [launch, setLaunch] = useState(null); const [launchResolved, setLaunchResolved] = useState(false); const [launchNotFound, setLaunchNotFound] = useState(false); + const [mapViewMode, setMapViewMode] = useState<'2d' | '3d'>('3d'); const { records, isLoadingRecords, recordsError } = useGetLaunchContent(launch?.download_url ?? '', Boolean(launch)); @@ -50,6 +52,15 @@ export default function LaunchDetailsPage() { [] ); + const MapTrajectory3D = useMemo( + () => + dynamic(() => import('@/src/components/Map/MapTrajectory3D'), { + loading: () =>

A map is loading

, + ssr: false + }), + [] + ); + useEffect(() => { router.prefetch('/launches'); }, [router]); @@ -189,9 +200,25 @@ export default function LaunchDetailsPage() { - - Trajetória do lançamento - + + + Trajetória do lançamento + + value && setMapViewMode(value)} + aria-label="Modo de visualização do mapa" + > + 2D + 3D + + )} @@ -199,16 +226,20 @@ export default function LaunchDetailsPage() { {launch && records.length > 0 && ( - [r.lat, r.lon])} - trajectoryRecords={records} - landingCity={launch.landing_city} - lineColor="#f44336" - lineWeight={4} - mapHeight="600px" - /> + {mapViewMode === '2d' ? ( + [r.lat, r.lon])} + trajectoryRecords={records} + landingCity={launch.landing_city} + lineColor="#f44336" + lineWeight={4} + mapHeight="600px" + /> + ) : ( + + )} )} diff --git a/src/components/LaunchCard/LaunchSummaryCard.tsx b/src/components/LaunchCard/LaunchSummaryCard.tsx index e6ee40f..3ad337a 100644 --- a/src/components/LaunchCard/LaunchSummaryCard.tsx +++ b/src/components/LaunchCard/LaunchSummaryCard.tsx @@ -1,3 +1,4 @@ +import { Fragment } from 'react'; import { Card, CardActions, CardContent, CardHeader, Button, Chip, Stack, Typography, Box } from '@mui/material'; import ChevronRightIcon from '@mui/icons-material/ChevronRight'; import HeightIcon from '@mui/icons-material/Height'; @@ -7,6 +8,18 @@ import { LaunchSummaryCardProps } from '@/src/shared/props/components/launch-sum import MapIcon from '@mui/icons-material/Map'; import { colors } from '@/src/shared/styles/colors'; +/** Permite quebra de linha depois de "_" e "-", para nomes como "014_J4840095_day_2" não estourarem o card. */ +const withSeparatorBreaks = (text: string) => + text + .replace(/[_-]/g, '$&\n') + .split('\n') + .map((part, index) => ( + + {index > 0 && } + {part} + + )); + export default function LaunchSummaryCard({ launch, index, onDetailsClick }: LaunchSummaryCardProps) { return ( @@ -19,7 +32,7 @@ export default function LaunchSummaryCard({ launch, index, onDetailsClick }: Lau {`#${index + 1}`} - {formatLaunchName(launch.name)} + {withSeparatorBreaks(formatLaunchName(launch.name))} { + const totalSeconds = Math.floor(ms / 1000); + const hours = Math.floor(totalSeconds / 3600); + const minutes = Math.floor((totalSeconds % 3600) / 60); + const seconds = totalSeconds % 60; + const pad = (value: number) => String(value).padStart(2, '0'); + return `T+${pad(hours)}:${pad(minutes)}:${pad(seconds)}`; +}; + +export default function MapTrajectory3D({ + records, + lineColor = '#f44336', + descentColor = '#29b6f6', + lineWeight = 4, + mapHeight = '600px', + altitudeExaggeration = 1 +}: MapTrajectory3DProps) { + const model = useMemo(() => (records.length > 1 ? buildTrajectoryModel(records) : null), [records]); + const { status: groundStatus, ground } = useSatelliteGround(model); + const labels = useMemo(() => (model ? buildSceneLabels(model) : []), [model]); + const labelElementsRef = useRef<(HTMLDivElement | null)[]>([]); + + const [isFullscreen, setIsFullscreen] = useState(false); + const [resetViewKey, setResetViewKey] = useState(0); + const [isPlaying, setIsPlaying] = useState(false); + const [playbackSpeed, setPlaybackSpeed] = useState(DEFAULT_PLAYBACK_SPEED); + const [playbackTime, setPlaybackTime] = useState(0); + const playbackTimeRef = useRef(0); + + useEffect(() => { + playbackTimeRef.current = 0; + setPlaybackTime(0); + setIsPlaying(false); + }, [model]); + + useEffect(() => { + if (!isFullscreen) return undefined; + + const handleKeyDown = (event: KeyboardEvent) => { + if (event.key === 'Escape') setIsFullscreen(false); + }; + + document.body.style.overflow = 'hidden'; + window.addEventListener('keydown', handleKeyDown); + + return () => { + document.body.style.overflow = ''; + window.removeEventListener('keydown', handleKeyDown); + }; + }, [isFullscreen]); + + const handlePlaybackEnd = useCallback(() => setIsPlaying(false), []); + + const handleTogglePlay = () => { + if (!model) return; + if (!isPlaying && playbackTimeRef.current >= model.durationMs) { + playbackTimeRef.current = 0; + setPlaybackTime(0); + } + setIsPlaying((current) => !current); + }; + + const handleSeek = (_event: Event, value: number | number[]) => { + const time = Array.isArray(value) ? value[0] : value; + playbackTimeRef.current = time; + setPlaybackTime(time); + }; + + if (!model) return null; + + const initialCamera = getInitialCamera(model, altitudeExaggeration); + const currentRecord = records[findIndexAtTime(model.timesMs, playbackTime)]; + const isAscending = findIndexAtTime(model.timesMs, playbackTime) <= model.burstIndex; + const hasEnded = playbackTime >= model.durationMs; + + return ( + + + + + + {labels.map((label, index) => ( + { + labelElementsRef.current[index] = element; + }} + sx={sceneLabelSx} + > + {label.text} + + ))} + + {groundStatus === 'loading' && ( + + + Carregando imagem de satélite e relevo… + + )} + + + + setIsFullscreen((current) => !current)} sx={toolbarButtonSx}> + {isFullscreen ? : } + + + + setResetViewKey((current) => current + 1)} sx={toolbarButtonSx}> + + + + + + + + + + + + + Arraste para girar · botão direito para mover · role para zoom + + + + {formatElapsed(playbackTime)} + Altitude: {formatAltitudeInKm(currentRecord.alt)} + Vel. vertical: {currentRecord.vel_v.toFixed(1)} m/s + Vel. horizontal: {currentRecord.vel_h.toFixed(1)} m/s + {isAscending ? 'Subindo' : 'Descendo'} + + + + + + {isPlaying ? : hasEnded ? : } + + + + value && setPlaybackSpeed(value)} + aria-label="Velocidade da reprodução" + sx={speedToggleSx} + > + {PLAYBACK_SPEEDS.map((speed) => ( + + {speed}x + + ))} + + + + + Imagens © Esri, Maxar, Earthstar Geographics · Relevo: Mapzen Terrain Tiles (AWS) + + ); +} + +function LegendItem({ color, label, round = false }: { color: string; label: string; round?: boolean }) { + return ( + + + {label} + + ); +} + +const overlayBaseSx = { + position: 'absolute', + color: '#fff', + backgroundColor: 'rgba(15, 23, 42, 0.72)', + borderRadius: 1, + fontSize: 12, + zIndex: 30 +} as const; + +const containerSx = { + width: '100%', + overflow: 'hidden', + background: 'linear-gradient(180deg, #0b1d3a 0%, #3d6ea3 55%, #a9c8e8 100%)' +} as const; + +const sceneLabelSx = { + position: 'absolute', + top: 0, + left: 0, + display: 'none', + px: 1, + py: 0.25, + borderRadius: 1, + backgroundColor: 'rgba(15, 23, 42, 0.78)', + color: '#fff', + fontSize: 12, + fontWeight: 600, + whiteSpace: 'nowrap', + userSelect: 'none', + pointerEvents: 'none', + zIndex: 20 +} as const; + +const loadingOverlaySx = { + ...overlayBaseSx, + top: '50%', + left: '50%', + transform: 'translate(-50%, -50%)', + display: 'flex', + alignItems: 'center', + gap: 1.5, + px: 2, + py: 1.5, + fontSize: 14 +} as const; + +const topLeftToolbarSx = { + position: 'absolute', + top: 8, + left: 8, + display: 'flex', + flexDirection: 'column', + gap: 1, + zIndex: 30 +} as const; + +const toolbarButtonSx = { + width: 40, + height: 40, + backgroundColor: 'background.paper', + boxShadow: 1, + '&:hover': { backgroundColor: 'background.paper' } +} as const; + +const legendSx = { + ...overlayBaseSx, + top: 8, + right: 8, + display: 'grid', + gap: 0.5, + px: 1.5, + py: 1 +} as const; + +const hintSx = { + ...overlayBaseSx, + top: 8, + left: '50%', + transform: 'translateX(-50%)', + px: 1.5, + py: 0.5, + display: { xs: 'none', md: 'block' } +} as const; + +const bottomPanelSx = { + ...overlayBaseSx, + left: 8, + right: 8, + bottom: 24, + px: 1.5, + py: 1 +} as const; + +const telemetrySx = { + display: 'flex', + flexWrap: 'wrap', + columnGap: 2, + rowGap: 0.5, + fontVariantNumeric: 'tabular-nums', + fontWeight: 600 +} as const; + +const playbackRowSx = { display: 'flex', alignItems: 'center' } as const; + +const speedToggleSx = { + '& .MuiToggleButton-root': { + color: 'rgba(255,255,255,0.7)', + borderColor: 'rgba(255,255,255,0.3)', + px: 1, + py: 0.25, + fontSize: 11 + }, + '& .MuiToggleButton-root.Mui-selected': { color: '#fff', backgroundColor: 'rgba(255,255,255,0.2)' } +} as const; + +const attributionSx = { + position: 'absolute', + right: 8, + bottom: 4, + color: 'rgba(255,255,255,0.85)', + fontSize: 10, + textShadow: '0 0 2px rgba(0,0,0,0.8)', + zIndex: 30 +} as const; diff --git a/src/components/Map/trajectory3d/TrajectoryScene.tsx b/src/components/Map/trajectory3d/TrajectoryScene.tsx new file mode 100644 index 0000000..7e84cf2 --- /dev/null +++ b/src/components/Map/trajectory3d/TrajectoryScene.tsx @@ -0,0 +1,379 @@ +import { MutableRefObject, useEffect, useMemo, useRef } from 'react'; +import { useFrame, useThree } from '@react-three/fiber'; +import { Line, OrbitControls } from '@react-three/drei'; +import type { OrbitControls as OrbitControlsImpl } from 'three-stdlib'; +import { BufferAttribute, BufferGeometry, Color, DoubleSide, Mesh, Vector3 } from 'three'; +import { formatAltitudeInKm } from '@/src/shared/utils/formatters.utils'; +import { SatelliteGround } from './useSatelliteGround'; +import { downsampleIndices, interpolatePosition, TrajectoryModel } from './trajectory.utils'; + +const MAX_LINE_POINTS = 4000; +const MAX_CURTAIN_POINTS = 800; +const TICK_INTERVAL_MS = 100; + +export const START_COLOR = '#43a047'; +export const BURST_COLOR = '#ffffff'; +export const END_COLOR = '#ffb300'; + +type TrajectorySceneProps = { + model: TrajectoryModel; + ground: SatelliteGround | null; + ascentColor: string; + descentColor: string; + lineWeight: number; + verticalScale: number; + playbackTimeRef: MutableRefObject; + isPlaying: boolean; + playbackSpeed: number; + onPlaybackTick: (timeMs: number) => void; + onPlaybackEnd: () => void; + resetViewKey: number; + labels: SceneLabelData[]; + labelElementsRef: MutableRefObject<(HTMLDivElement | null)[]>; +}; + +export type SceneLabelData = { key: string; text: string; position: Vector3 }; + +const getAltitudeAxis = (model: TrajectoryModel) => { + const step = model.maxAltitudeKm > 40 ? 10 : 5; + const topKm = Math.max(step, Math.ceil(model.maxAltitudeKm / step) * step); + return { + origin: model.points[0], + topKm, + tickSize: model.spanKm * 0.012, + ticks: Array.from({ length: topKm / step }, (_, i) => (i + 1) * step) + }; +}; + +const getMarkerRadius = (model: TrajectoryModel) => model.spanKm * 0.006; + +/** + * Rótulos da cena (eixo de altitude e marcadores), em coordenadas locais. + * São renderizados como divs comuns fora do Canvas e posicionados a cada frame pelo LabelProjector. + */ +export const buildSceneLabels = (model: TrajectoryModel): SceneLabelData[] => { + const { origin, tickSize, ticks } = getAltitudeAxis(model); + const labelOffset = getMarkerRadius(model) * 4; + const burst = model.points[model.burstIndex]; + const end = model.points[model.points.length - 1]; + + return [ + ...ticks.map((km) => ({ + key: `tick-${km}`, + text: `${km} km`, + position: new Vector3(origin.x - tickSize * 4, km, origin.z) + })), + { key: 'start', text: 'Lançamento', position: new Vector3(origin.x, origin.y + labelOffset, origin.z) }, + { + key: 'burst', + text: `Altitude máx. · ${formatAltitudeInKm(model.records[model.burstIndex].alt)}`, + position: new Vector3(burst.x, burst.y + labelOffset, burst.z) + }, + { key: 'end', text: 'Fim da trajetória', position: new Vector3(end.x, end.y + labelOffset, end.z) } + ]; +}; + +export const getInitialCamera = (model: TrajectoryModel, verticalScale: number) => { + const target = new Vector3(model.center.x, model.center.y * verticalScale, model.center.z); + const distance = model.spanKm * 1.6; + const position = target.clone().add(new Vector3(distance * 0.55, distance * 0.55, distance * 0.75)); + return { target, position }; +}; + +function CameraRig({ + model, + verticalScale, + resetViewKey +}: { + model: TrajectoryModel; + verticalScale: number; + resetViewKey: number; +}) { + const controlsRef = useRef(null); + const camera = useThree((state) => state.camera); + const initial = useMemo(() => getInitialCamera(model, verticalScale), [model, verticalScale]); + + useEffect(() => { + camera.position.copy(initial.position); + controlsRef.current?.target.copy(initial.target); + controlsRef.current?.update(); + }, [camera, initial, resetViewKey]); + + return ( + + ); +} + +/** Projeta os rótulos 3D na tela e move as divs correspondentes, sem re-renderizar o React. */ +function LabelProjector({ + labels, + labelElementsRef, + verticalScale +}: Pick) { + const projected = useMemo(() => new Vector3(), []); + + useFrame(({ camera, size }) => { + labels.forEach((label, index) => { + const element = labelElementsRef.current[index]; + if (!element) return; + + projected.set(label.position.x, label.position.y * verticalScale, label.position.z).project(camera); + const isVisible = projected.z < 1 && Math.abs(projected.x) <= 1.1 && Math.abs(projected.y) <= 1.1; + + element.style.display = isVisible ? 'block' : 'none'; + if (isVisible) { + const x = ((projected.x + 1) / 2) * size.width; + const y = ((1 - projected.y) / 2) * size.height; + element.style.transform = `translate(-50%, -50%) translate(${x}px, ${y}px)`; + } + }); + }); + + return null; +} + +function Ground({ ground }: { ground: SatelliteGround }) { + return ( + + {ground.texture ? ( + + ) : ( + + )} + + ); +} + +function TrajectoryLine({ + model, + ascentColor, + descentColor, + lineWeight +}: { + model: TrajectoryModel; + ascentColor: string; + descentColor: string; + lineWeight: number; +}) { + const { points, colors } = useMemo(() => { + const ascent = new Color(ascentColor); + const descent = new Color(descentColor); + const indices = downsampleIndices(model.points.length, MAX_LINE_POINTS, [model.burstIndex]); + return { + points: indices.map((index) => model.points[index]), + colors: indices.map((index) => (index <= model.burstIndex ? ascent : descent)) + }; + }, [model, ascentColor, descentColor]); + + return ; +} + +/** Faixa semitransparente ligando a trajetória ao chão, para facilitar a leitura da altura. */ +function TrajectoryCurtain({ + model, + ground, + ascentColor, + descentColor +}: { + model: TrajectoryModel; + ground: SatelliteGround | null; + ascentColor: string; + descentColor: string; +}) { + const geometry = useMemo(() => { + const ascent = new Color(ascentColor); + const descent = new Color(descentColor); + const indices = downsampleIndices(model.points.length, MAX_CURTAIN_POINTS, [model.burstIndex]); + const positions = new Float32Array(indices.length * 6); + const colors = new Float32Array(indices.length * 6); + const triangles: number[] = []; + + indices.forEach((pointIndex, i) => { + const point = model.points[pointIndex]; + const groundY = ground ? ground.groundHeightAt(point.x, point.z) : 0; + const color = pointIndex <= model.burstIndex ? ascent : descent; + + positions.set([point.x, point.y, point.z, point.x, Math.min(groundY, point.y), point.z], i * 6); + colors.set([color.r, color.g, color.b, color.r, color.g, color.b], i * 6); + + if (i > 0) { + const top = i * 2; + const previousTop = top - 2; + triangles.push(previousTop, previousTop + 1, top, top, previousTop + 1, top + 1); + } + }); + + const built = new BufferGeometry(); + built.setAttribute('position', new BufferAttribute(positions, 3)); + built.setAttribute('color', new BufferAttribute(colors, 3)); + built.setIndex(triangles); + return built; + }, [model, ground, ascentColor, descentColor]); + + useEffect(() => () => geometry.dispose(), [geometry]); + + return ( + + + + ); +} + +/** Eixo vertical no ponto de lançamento com marcações em km. */ +function AltitudeAxis({ model, ground }: { model: TrajectoryModel; ground: SatelliteGround | null }) { + const { origin, topKm, tickSize, ticks } = getAltitudeAxis(model); + const baseY = ground ? ground.groundHeightAt(origin.x, origin.z) : 0; + + return ( + + + {ticks.map((km) => ( + + ))} + + ); +} + +function Markers({ model, ground }: { model: TrajectoryModel; ground: SatelliteGround | null }) { + const radius = getMarkerRadius(model); + const burst = model.points[model.burstIndex]; + + const markers = [ + { key: 'start', point: model.points[0], color: START_COLOR }, + { key: 'burst', point: burst, color: BURST_COLOR }, + { key: 'end', point: model.points[model.points.length - 1], color: END_COLOR } + ]; + + return ( + + {markers.map(({ key, point, color }) => ( + + + + + ))} + {ground && ( + + + + + )} + + ); +} + +/** Sonda animada percorrendo a trajetória, com uma linha vertical até o chão. */ +function Payload({ + model, + ground, + playbackTimeRef, + isPlaying, + playbackSpeed, + onPlaybackTick, + onPlaybackEnd +}: Pick< + TrajectorySceneProps, + 'model' | 'ground' | 'playbackTimeRef' | 'isPlaying' | 'playbackSpeed' | 'onPlaybackTick' | 'onPlaybackEnd' +>) { + const payloadRef = useRef(null); + const dropLineRef = useRef(null); + const lastTickRef = useRef(0); + const position = useMemo(() => new Vector3(), []); + const radius = model.spanKm * 0.009; + + useFrame((state, delta) => { + if (isPlaying) { + const nextTime = playbackTimeRef.current + delta * 1000 * playbackSpeed; + playbackTimeRef.current = Math.min(nextTime, model.durationMs); + + if (state.clock.elapsedTime * 1000 - lastTickRef.current > TICK_INTERVAL_MS) { + lastTickRef.current = state.clock.elapsedTime * 1000; + onPlaybackTick(playbackTimeRef.current); + } + + if (nextTime >= model.durationMs) { + onPlaybackTick(model.durationMs); + onPlaybackEnd(); + } + } + + interpolatePosition(model, playbackTimeRef.current, position); + payloadRef.current?.position.copy(position); + + if (dropLineRef.current) { + const groundY = ground ? ground.groundHeightAt(position.x, position.z) : 0; + const height = Math.max(position.y - groundY, 0.001); + dropLineRef.current.position.set(position.x, groundY + height / 2, position.z); + dropLineRef.current.scale.set(1, height, 1); + } + }); + + return ( + + + + + + + + + + + ); +} + +export default function TrajectoryScene(props: TrajectorySceneProps) { + const { model, ground, ascentColor, descentColor, lineWeight, verticalScale, resetViewKey, labels, labelElementsRef } = props; + const { spanKm } = model; + + return ( + <> + + + + + + + + + + {ground && } + + + + + + + + ); +} diff --git a/src/components/Map/trajectory3d/geo.utils.ts b/src/components/Map/trajectory3d/geo.utils.ts new file mode 100644 index 0000000..dae2402 --- /dev/null +++ b/src/components/Map/trajectory3d/geo.utils.ts @@ -0,0 +1,221 @@ +import { LaunchRecord } from '@/src/shared/types/api/launches-api.types'; + +/** + * Utilitários geográficos da cena 3D. + * + * Tudo é projetado em Web Mercator (a mesma projeção dos tiles), e depois convertido para + * quilômetros locais a partir do ponto de lançamento. 1 unidade da cena = 1 km. + */ + +const EARTH_RADIUS_M = 6378137; +const WORLD_SIZE_M = 2 * Math.PI * EARTH_RADIUS_M; +const TILE_SIZE_PX = 256; + +export const SATELLITE_TILE_URL = 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}'; +export const TERRAIN_TILE_URL = 'https://elevation-tiles-prod.s3.amazonaws.com/terrarium/{z}/{x}/{y}.png'; + +// Limite por lado: 16 tiles x 256 px = textura de 4096 px, suportada inclusive em celulares. +const MAX_SATELLITE_TILES_PER_SIDE = 16; +const MAX_TERRAIN_TILES_PER_SIDE = 8; +const MAX_SATELLITE_ZOOM = 17; +const MAX_TERRAIN_ZOOM = 14; + +export type MercatorPoint = { x: number; y: number }; +export type MercatorBounds = { minX: number; minY: number; maxX: number; maxY: number }; + +export const toMercator = (lat: number, lon: number): MercatorPoint => { + const latRad = (Math.max(Math.min(lat, 85.0511), -85.0511) * Math.PI) / 180; + return { + x: (EARTH_RADIUS_M * lon * Math.PI) / 180, + y: EARTH_RADIUS_M * Math.log(Math.tan(Math.PI / 4 + latRad / 2)) + }; +}; + +/** Converte coordenadas Mercator para km locais (x = leste, z = sul), corrigindo a escala pela latitude. */ +export const createLocalProjection = (originLat: number, originLon: number) => { + const origin = toMercator(originLat, originLon); + const scale = Math.cos((originLat * Math.PI) / 180) / 1000; + + return { + mercatorToLocal: (point: MercatorPoint) => ({ + x: (point.x - origin.x) * scale, + z: -(point.y - origin.y) * scale + }), + localToMercator: (x: number, z: number): MercatorPoint => ({ + x: x / scale + origin.x, + y: -z / scale + origin.y + }), + project: (lat: number, lon: number) => { + const point = toMercator(lat, lon); + return { x: (point.x - origin.x) * scale, z: -(point.y - origin.y) * scale }; + } + }; +}; + +/** Área em volta da trajetória, com folga para o voo não ficar colado na borda do chão. */ +export const getPaddedBounds = (records: LaunchRecord[]): MercatorBounds => { + const points = records.map((record) => toMercator(record.lat, record.lon)); + let minX = Math.min(...points.map((p) => p.x)); + let maxX = Math.max(...points.map((p) => p.x)); + let minY = Math.min(...points.map((p) => p.y)); + let maxY = Math.max(...points.map((p) => p.y)); + + const minSpan = 40000; + const span = Math.max(maxX - minX, maxY - minY, minSpan); + const padding = span * 0.35; + const centerX = (minX + maxX) / 2; + const centerY = (minY + maxY) / 2; + const halfSize = span / 2 + padding; + + minX = centerX - halfSize; + maxX = centerX + halfSize; + minY = centerY - halfSize; + maxY = centerY + halfSize; + + return { minX, minY, maxX, maxY }; +}; + +type TileRange = { zoom: number; minTileX: number; maxTileX: number; minTileY: number; maxTileY: number }; + +const mercatorToTile = (value: number, zoom: number, axis: 'x' | 'y') => { + const tiles = 2 ** zoom; + const normalized = axis === 'x' ? (value + WORLD_SIZE_M / 2) / WORLD_SIZE_M : (WORLD_SIZE_M / 2 - value) / WORLD_SIZE_M; + return Math.floor(normalized * tiles); +}; + +const getTileRange = (bounds: MercatorBounds, zoom: number): TileRange => ({ + zoom, + minTileX: mercatorToTile(bounds.minX, zoom, 'x'), + maxTileX: mercatorToTile(bounds.maxX, zoom, 'x'), + minTileY: mercatorToTile(bounds.maxY, zoom, 'y'), + maxTileY: mercatorToTile(bounds.minY, zoom, 'y') +}); + +/** Maior zoom em que a área cabe no limite de tiles por lado. */ +const pickTileRange = (bounds: MercatorBounds, maxTilesPerSide: number, maxZoom: number): TileRange => { + for (let zoom = maxZoom; zoom > 0; zoom -= 1) { + const range = getTileRange(bounds, zoom); + const columns = range.maxTileX - range.minTileX + 1; + const rows = range.maxTileY - range.minTileY + 1; + if (Math.max(columns, rows) <= maxTilesPerSide) return range; + } + return getTileRange(bounds, 1); +}; + +const getTileRangeBounds = (range: TileRange): MercatorBounds => { + const tileSize = WORLD_SIZE_M / 2 ** range.zoom; + return { + minX: range.minTileX * tileSize - WORLD_SIZE_M / 2, + maxX: (range.maxTileX + 1) * tileSize - WORLD_SIZE_M / 2, + maxY: WORLD_SIZE_M / 2 - range.minTileY * tileSize, + minY: WORLD_SIZE_M / 2 - (range.maxTileY + 1) * tileSize + }; +}; + +const loadImage = (url: string, signal: AbortSignal) => + new Promise((resolve) => { + const image = new Image(); + image.crossOrigin = 'anonymous'; + image.onload = () => resolve(image); + image.onerror = () => resolve(null); + signal.addEventListener('abort', () => { + image.src = ''; + resolve(null); + }); + image.src = url; + }); + +export type StitchedTiles = { + canvas: HTMLCanvasElement; + bounds: MercatorBounds; + loadedTiles: number; +}; + +/** Baixa todos os tiles da área e junta numa única imagem. */ +const loadStitchedTiles = async (urlTemplate: string, range: TileRange, signal: AbortSignal): Promise => { + const columns = range.maxTileX - range.minTileX + 1; + const rows = range.maxTileY - range.minTileY + 1; + const canvas = document.createElement('canvas'); + canvas.width = columns * TILE_SIZE_PX; + canvas.height = rows * TILE_SIZE_PX; + const context = canvas.getContext('2d', { willReadFrequently: true }); + + const jobs: Promise[] = []; + for (let tileX = range.minTileX; tileX <= range.maxTileX; tileX += 1) { + for (let tileY = range.minTileY; tileY <= range.maxTileY; tileY += 1) { + const url = urlTemplate.replace('{z}', String(range.zoom)).replace('{x}', String(tileX)).replace('{y}', String(tileY)); + + jobs.push( + loadImage(url, signal).then((image) => { + if (!image || !context) return false; + context.drawImage( + image, + (tileX - range.minTileX) * TILE_SIZE_PX, + (tileY - range.minTileY) * TILE_SIZE_PX, + TILE_SIZE_PX, + TILE_SIZE_PX + ); + return true; + }) + ); + } + } + + const results = await Promise.all(jobs); + return { canvas, bounds: getTileRangeBounds(range), loadedTiles: results.filter(Boolean).length }; +}; + +export const loadSatelliteImagery = (bounds: MercatorBounds, signal: AbortSignal) => + loadStitchedTiles(SATELLITE_TILE_URL, pickTileRange(bounds, MAX_SATELLITE_TILES_PER_SIDE, MAX_SATELLITE_ZOOM), signal); + +export type ElevationSampler = (point: MercatorPoint) => number | null; + +/** Baixa os tiles de elevação (formato Terrarium) e devolve uma função que lê a altitude em metros. */ +export const loadElevationSampler = async (bounds: MercatorBounds, signal: AbortSignal): Promise => { + const stitched = await loadStitchedTiles( + TERRAIN_TILE_URL, + pickTileRange(bounds, MAX_TERRAIN_TILES_PER_SIDE, MAX_TERRAIN_ZOOM), + signal + ); + if (stitched.loadedTiles === 0) return null; + + const { canvas } = stitched; + const context = canvas.getContext('2d', { willReadFrequently: true }); + if (!context) return null; + + let pixels: Uint8ClampedArray; + try { + pixels = context.getImageData(0, 0, canvas.width, canvas.height).data; + } catch { + return null; + } + + const { width, height } = canvas; + const readElevation = (px: number, py: number) => { + const index = (py * width + px) * 4; + if (pixels[index + 3] === 0) return null; + return pixels[index] * 256 + pixels[index + 1] + pixels[index + 2] / 256 - 32768; + }; + + return ({ x, y }) => { + const { minX, maxX, minY, maxY } = stitched.bounds; + const u = ((x - minX) / (maxX - minX)) * (width - 1); + const v = ((maxY - y) / (maxY - minY)) * (height - 1); + if (u < 0 || v < 0 || u > width - 1 || v > height - 1) return null; + + const x0 = Math.floor(u); + const y0 = Math.floor(v); + const x1 = Math.min(x0 + 1, width - 1); + const y1 = Math.min(y0 + 1, height - 1); + const fx = u - x0; + const fy = v - y0; + + const e00 = readElevation(x0, y0); + const e10 = readElevation(x1, y0); + const e01 = readElevation(x0, y1); + const e11 = readElevation(x1, y1); + if (e00 === null || e10 === null || e01 === null || e11 === null) return e00 ?? e10 ?? e01 ?? e11; + + return (e00 * (1 - fx) + e10 * fx) * (1 - fy) + (e01 * (1 - fx) + e11 * fx) * fy; + }; +}; diff --git a/src/components/Map/trajectory3d/trajectory.utils.ts b/src/components/Map/trajectory3d/trajectory.utils.ts new file mode 100644 index 0000000..239ebd2 --- /dev/null +++ b/src/components/Map/trajectory3d/trajectory.utils.ts @@ -0,0 +1,89 @@ +import { Vector3 } from 'three'; +import { LaunchRecord } from '@/src/shared/types/api/launches-api.types'; +import { createLocalProjection, getPaddedBounds, MercatorBounds } from './geo.utils'; + +export type LocalProjection = ReturnType; + +export type TrajectoryModel = { + records: LaunchRecord[]; + /** Pontos em km: x = leste, y = altitude acima do nível do mar, z = sul. */ + points: Vector3[]; + /** Tempo de cada ponto em ms a partir do primeiro registro. */ + timesMs: number[]; + durationMs: number; + burstIndex: number; + maxAltitudeKm: number; + /** Maior dimensão horizontal da cena, em km. */ + spanKm: number; + center: Vector3; + groundBounds: MercatorBounds; + projection: LocalProjection; +}; + +export const buildTrajectoryModel = (records: LaunchRecord[]): TrajectoryModel => { + const projection = createLocalProjection(records[0].lat, records[0].lon); + const startTime = new Date(records[0].datetime).getTime(); + + const points = records.map((record) => { + const { x, z } = projection.project(record.lat, record.lon); + return new Vector3(x, record.alt / 1000, z); + }); + + const timesMs = records.map((record) => Math.max(0, new Date(record.datetime).getTime() - startTime)); + + const burstIndex = records.reduce((best, record, index) => (record.alt > records[best].alt ? index : best), 0); + + const xs = points.map((p) => p.x); + const zs = points.map((p) => p.z); + const minX = Math.min(...xs); + const maxX = Math.max(...xs); + const minZ = Math.min(...zs); + const maxZ = Math.max(...zs); + const maxAltitudeKm = records[burstIndex].alt / 1000; + const spanKm = Math.max(maxX - minX, maxZ - minZ, maxAltitudeKm, 10); + + return { + records, + points, + timesMs, + durationMs: timesMs[timesMs.length - 1] ?? 0, + burstIndex, + maxAltitudeKm, + spanKm, + center: new Vector3((minX + maxX) / 2, maxAltitudeKm / 3, (minZ + maxZ) / 2), + groundBounds: getPaddedBounds(records), + projection + }; +}; + +/** Reduz a quantidade de pontos mantendo o primeiro, o último e o ponto de estouro. */ +export const downsampleIndices = (length: number, maxPoints: number, keep: number[] = []) => { + if (length <= maxPoints) return Array.from({ length }, (_, index) => index); + + const step = (length - 1) / (maxPoints - 1); + const indices = new Set(keep); + for (let i = 0; i < maxPoints; i += 1) { + indices.add(Math.round(i * step)); + } + return Array.from(indices).sort((a, b) => a - b); +}; + +/** Índice do último ponto com tempo <= timeMs (busca binária). */ +export const findIndexAtTime = (timesMs: number[], timeMs: number) => { + let low = 0; + let high = timesMs.length - 1; + while (low < high) { + const mid = Math.ceil((low + high) / 2); + if (timesMs[mid] <= timeMs) low = mid; + else high = mid - 1; + } + return low; +}; + +export const interpolatePosition = (model: TrajectoryModel, timeMs: number, target: Vector3) => { + const index = findIndexAtTime(model.timesMs, timeMs); + const next = Math.min(index + 1, model.points.length - 1); + const segment = model.timesMs[next] - model.timesMs[index]; + const fraction = segment > 0 ? Math.min(Math.max((timeMs - model.timesMs[index]) / segment, 0), 1) : 0; + return target.copy(model.points[index]).lerp(model.points[next], fraction); +}; diff --git a/src/components/Map/trajectory3d/useSatelliteGround.ts b/src/components/Map/trajectory3d/useSatelliteGround.ts new file mode 100644 index 0000000..d3ec7ce --- /dev/null +++ b/src/components/Map/trajectory3d/useSatelliteGround.ts @@ -0,0 +1,80 @@ +import { useEffect, useState } from 'react'; +import { BufferGeometry, CanvasTexture, PlaneGeometry, SRGBColorSpace } from 'three'; +import { ElevationSampler, loadElevationSampler, loadSatelliteImagery } from './geo.utils'; +import { TrajectoryModel } from './trajectory.utils'; + +const GROUND_SEGMENTS = 192; + +export type SatelliteGround = { + geometry: BufferGeometry; + texture: CanvasTexture | null; + /** Altitude do chão em km num ponto local da cena. */ + groundHeightAt: (x: number, z: number) => number; +}; + +type GroundState = { status: 'loading' | 'ready'; ground: SatelliteGround | null }; + +export const useSatelliteGround = (model: TrajectoryModel | null): GroundState => { + const [state, setState] = useState({ status: 'loading', ground: null }); + + useEffect(() => { + if (!model) return undefined; + + const controller = new AbortController(); + let builtGround: SatelliteGround | null = null; + setState({ status: 'loading', ground: null }); + + const build = async () => { + const [imagery, sampler] = await Promise.all([ + loadSatelliteImagery(model.groundBounds, controller.signal), + loadElevationSampler(model.groundBounds, controller.signal).catch((): ElevationSampler | null => null) + ]); + if (controller.signal.aborted) return; + + const { records, projection } = model; + const fallbackHeightKm = Math.min(records[0].alt, records[records.length - 1].alt) / 1000; + + const groundHeightAt = (x: number, z: number) => { + const elevation = sampler?.(projection.localToMercator(x, z)); + return elevation === null || elevation === undefined ? fallbackHeightKm : elevation / 1000; + }; + + // O plano usa exatamente a área dos tiles de satélite, para a imagem não ficar distorcida. + const topLeft = projection.mercatorToLocal({ x: imagery.bounds.minX, y: imagery.bounds.maxY }); + const bottomRight = projection.mercatorToLocal({ x: imagery.bounds.maxX, y: imagery.bounds.minY }); + const width = bottomRight.x - topLeft.x; + const depth = bottomRight.z - topLeft.z; + + const geometry = new PlaneGeometry(width, depth, GROUND_SEGMENTS, GROUND_SEGMENTS); + geometry.rotateX(-Math.PI / 2); + geometry.translate(topLeft.x + width / 2, 0, topLeft.z + depth / 2); + + const positions = geometry.attributes.position; + for (let i = 0; i < positions.count; i += 1) { + positions.setY(i, groundHeightAt(positions.getX(i), positions.getZ(i))); + } + positions.needsUpdate = true; + geometry.computeVertexNormals(); + + let texture: CanvasTexture | null = null; + if (imagery.loadedTiles > 0) { + texture = new CanvasTexture(imagery.canvas); + texture.colorSpace = SRGBColorSpace; + texture.anisotropy = 8; + } + + builtGround = { geometry, texture, groundHeightAt }; + setState({ status: 'ready', ground: builtGround }); + }; + + build(); + + return () => { + controller.abort(); + builtGround?.geometry.dispose(); + builtGround?.texture?.dispose(); + }; + }, [model]); + + return state; +};