|
| 1 | +import { StrictMode } from 'react'; |
| 2 | +import { createRoot } from 'react-dom/client'; |
| 3 | +import { Canvas } from '@react-three/fiber'; |
| 4 | +import { Environment, GizmoHelper, GizmoViewport } from '@react-three/drei'; |
| 5 | +import { TilesPlugin, TilesRenderer, EnvironmentControls, EastNorthUpFrame } from '3d-tiles-renderer/r3f'; |
| 6 | +import { TilesFadePlugin, GLTFExtensionsPlugin, ReorientationPlugin, CesiumIonAuthPlugin, UpdateOnChangePlugin } from '3d-tiles-renderer/plugins'; |
| 7 | +import { TileFlatteningPlugin, TileFlatteningShape } from './plugins/TileFlatteningPlugin.jsx'; |
| 8 | +import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js'; |
| 9 | +import { |
| 10 | + MathUtils, |
| 11 | +} from 'three'; |
| 12 | + |
| 13 | +const dracoLoader = new DRACOLoader().setDecoderPath( 'https://www.gstatic.com/draco/v1/decoders/' ); |
| 14 | + |
| 15 | +const LAT = 35.3606 * MathUtils.DEG2RAD; |
| 16 | +const LON = 138.7274 * MathUtils.DEG2RAD; |
| 17 | +function App() { |
| 18 | + |
| 19 | + return ( |
| 20 | + <Canvas |
| 21 | + camera={ { |
| 22 | + position: [ 1e4 * 0.7, 1e4 * 0.7, 1e4 * 0.7 ], |
| 23 | + far: 1600000 |
| 24 | + } } |
| 25 | + style={ { |
| 26 | + width: '100%', |
| 27 | + height: '100%', |
| 28 | + position: 'absolute', |
| 29 | + margin: 0, |
| 30 | + left: 0, |
| 31 | + top: 0, |
| 32 | + } } |
| 33 | + > |
| 34 | + {/* 3D Tiles renderer tileset */} |
| 35 | + <TilesRenderer group={ { rotation: [ - Math.PI / 2, 0, 0 ] } }> |
| 36 | + <TilesPlugin plugin={ CesiumIonAuthPlugin } args={ { apiToken: import.meta.env.VITE_ION_KEY, assetId: '2275207', autoRefreshToken: true } } /> |
| 37 | + <TilesPlugin plugin={ GLTFExtensionsPlugin } dracoLoader={ dracoLoader } /> |
| 38 | + <TilesPlugin plugin={ UpdateOnChangePlugin } /> |
| 39 | + <TilesPlugin plugin={ TilesFadePlugin } /> |
| 40 | + <TilesPlugin plugin={ ReorientationPlugin } args={ { lat: LAT, lon: LON } } /> |
| 41 | + <TileFlatteningPlugin> |
| 42 | + <TileFlatteningShape relativeToEllipsoid visible={ false }> |
| 43 | + <EastNorthUpFrame lat={ LAT } lon={ LON } height={ 1000 }> |
| 44 | + <mesh scale={ 5000 }> |
| 45 | + <circleGeometry /> |
| 46 | + </mesh> |
| 47 | + </EastNorthUpFrame> |
| 48 | + </TileFlatteningShape> |
| 49 | + </TileFlatteningPlugin> |
| 50 | + |
| 51 | + </TilesRenderer> |
| 52 | + |
| 53 | + {/* Controls */} |
| 54 | + <EnvironmentControls |
| 55 | + enableDamping={ true } |
| 56 | + maxDistance={ 1e4 * 2 } |
| 57 | + minDistance={ 500 } |
| 58 | + minPolarAngle={ 0 } |
| 59 | + maxPolarAngle={ 3 * Math.PI / 8 } |
| 60 | + /> |
| 61 | + |
| 62 | + {/* other r3f staging */} |
| 63 | + <Environment |
| 64 | + preset="sunset" background={ true } |
| 65 | + backgroundBlurriness={ 0.9 } |
| 66 | + environmentIntensity={ 1 } |
| 67 | + /> |
| 68 | + <GizmoHelper alignment="bottom-right"> |
| 69 | + <GizmoViewport /> |
| 70 | + </GizmoHelper> |
| 71 | + </Canvas> |
| 72 | + ); |
| 73 | + |
| 74 | +} |
| 75 | + |
| 76 | +createRoot( document.getElementById( 'root' ) ).render( |
| 77 | + <StrictMode> |
| 78 | + <App /> |
| 79 | + </StrictMode>, |
| 80 | +); |
| 81 | + |
0 commit comments