@navaramap/three 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +8 -0
- package/dist/assets/atmosphere/README.md +1 -0
- package/dist/assets/atmosphere/higher_order_scattering.bin +0 -0
- package/dist/assets/atmosphere/higher_order_scattering.exr +0 -0
- package/dist/assets/atmosphere/irradiance.bin +0 -0
- package/dist/assets/atmosphere/irradiance.exr +0 -0
- package/dist/assets/atmosphere/scattering.bin +0 -0
- package/dist/assets/atmosphere/scattering.exr +0 -0
- package/dist/assets/atmosphere/single_mie_scattering.bin +0 -0
- package/dist/assets/atmosphere/single_mie_scattering.exr +0 -0
- package/dist/assets/atmosphere/stars.bin +0 -0
- package/dist/assets/atmosphere/transmittance.bin +0 -0
- package/dist/assets/atmosphere/transmittance.exr +0 -0
- package/dist/assets/cloud/README.md +1 -0
- package/dist/assets/cloud/local_weather.png +0 -0
- package/dist/assets/cloud/shape.bin +1 -0
- package/dist/assets/cloud/shape_detail.bin +1 -0
- package/dist/assets/cloud/turbulence.png +0 -0
- package/dist/assets/fontWorker-CEJEfRpb.js +2 -0
- package/dist/assets/fontWorker-CEJEfRpb.js.map +1 -0
- package/dist/assets/index-BUB-ijMO.js +12 -0
- package/dist/assets/index-BUB-ijMO.js.map +1 -0
- package/dist/assets/navara_wasm_font_worker_bg-665OLxjy.wasm +0 -0
- package/dist/assets/navara_wasm_worker_bg-BXhKC5bE.wasm +0 -0
- package/dist/assets/noise/README.md +1 -0
- package/dist/assets/noise/stbn.bin +0 -0
- package/dist/assets/water/README.md +3 -0
- package/dist/assets/water/waternormals.jpg +0 -0
- package/dist/index.d.ts +10114 -0
- package/dist/index.js +34481 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.cjs +6345 -0
- package/dist/index.umd.cjs.map +1 -0
- package/package.json +95 -0
- package/src/Color.ts +111 -0
- package/src/ShadowMapViewers.ts +49 -0
- package/src/atmosphere.test.ts +76 -0
- package/src/atmosphere.ts +364 -0
- package/src/bufferView.ts +90 -0
- package/src/camera.ts +182 -0
- package/src/concurrency.ts +15 -0
- package/src/constants/assets.ts +30 -0
- package/src/constants/decoder.ts +7 -0
- package/src/constants/index.ts +2 -0
- package/src/core/BaseDesc.ts +142 -0
- package/src/core/BaseHandle.ts +126 -0
- package/src/core/DescRegistry.ts +88 -0
- package/src/core/EffectDesc.ts +343 -0
- package/src/core/EffectDescRegistry.ts +31 -0
- package/src/core/InstancedMeshDesc.ts +413 -0
- package/src/core/LightDesc.ts +216 -0
- package/src/core/LightDescRegistry.ts +32 -0
- package/src/core/MeshDesc.ts +457 -0
- package/src/core/MeshDescRegistry.ts +32 -0
- package/src/core/MeshDescWithSelectiveEffect.ts +129 -0
- package/src/core/Registries.ts +59 -0
- package/src/core/SelectiveEffectRegistry.ts +90 -0
- package/src/core/ViewContext.ts +235 -0
- package/src/core/errors.ts +16 -0
- package/src/core/index.ts +50 -0
- package/src/device.ts +414 -0
- package/src/effects/CustomEffectPass.ts +28 -0
- package/src/effects/copy.ts +10 -0
- package/src/effects/effect.ts +87 -0
- package/src/effects/index.ts +4 -0
- package/src/effects/render.ts +10 -0
- package/src/evaluations/FeatureEvaluator.ts +529 -0
- package/src/evaluations/index.ts +1 -0
- package/src/event/HillshadeContext.test.ts +232 -0
- package/src/event/HillshadeContext.ts +299 -0
- package/src/event/context.ts +279 -0
- package/src/event/feature.ts +357 -0
- package/src/event/featureEvent.ts +81 -0
- package/src/event/features/billboard.ts +30 -0
- package/src/event/features/model.ts +192 -0
- package/src/event/features/modelGpuBytes.test.ts +69 -0
- package/src/event/features/modelGpuBytes.ts +87 -0
- package/src/event/features/point.ts +25 -0
- package/src/event/features/polygon.ts +23 -0
- package/src/event/features/polygonOutline.ts +19 -0
- package/src/event/features/polyline.ts +19 -0
- package/src/event/features/text.ts +71 -0
- package/src/event/hillshade.test.ts +842 -0
- package/src/event/hillshade.ts +588 -0
- package/src/event/index.ts +700 -0
- package/src/event/loaders.ts +53 -0
- package/src/event/tile.ts +19 -0
- package/src/event/worker.ts +999 -0
- package/src/event/workerTaskSettlement.test.ts +243 -0
- package/src/event/workerTaskSettlement.ts +128 -0
- package/src/inMemoryBufferStore.test.ts +60 -0
- package/src/inMemoryBufferStore.ts +67 -0
- package/src/index.iife.ts +11 -0
- package/src/index.ts +2556 -0
- package/src/input.ts +144 -0
- package/src/layer.ts +183 -0
- package/src/layers/effect/FinalCopyEffectDesc.ts +29 -0
- package/src/layers/effect/MRTPassEffectDesc.ts +105 -0
- package/src/layers/effect/README.md +9 -0
- package/src/layers/effect/SelectiveEffectDesc.ts +113 -0
- package/src/layers/effect/SkyEnvMapEffectDesc.ts +58 -0
- package/src/layers/effect/TransparentPassEffectDesc.ts +62 -0
- package/src/layers/effect/index.ts +5 -0
- package/src/layers/index.ts +1 -0
- package/src/layersManager.ts +63 -0
- package/src/light.ts +15 -0
- package/src/loaders/AbortableImageLoader.ts +203 -0
- package/src/loaders/AbortableTextureLoader.ts +74 -0
- package/src/loaders/index.ts +5 -0
- package/src/material/enhancer/DESIGN.md +300 -0
- package/src/material/enhancer/MaterialEnhancer.ts +112 -0
- package/src/material/enhancer/ShaderReplacer.test.ts +114 -0
- package/src/material/enhancer/ShaderReplacer.ts +97 -0
- package/src/material/enhancer/batchTexture.ts +8 -0
- package/src/material/enhancer/index.ts +46 -0
- package/src/material/enhancer/instancedSprite/index.ts +7 -0
- package/src/material/enhancer/instancedSprite/instancedSpriteBaseEnhancer/index.test.ts +214 -0
- package/src/material/enhancer/instancedSprite/instancedSpriteBaseEnhancer/index.ts +134 -0
- package/src/material/enhancer/instancedSprite/instancedSpriteBaseEnhancer/markers.ts +21 -0
- package/src/material/enhancer/instancedSprite/instancedSpriteBaseEnhancer/material.ts +32 -0
- package/src/material/enhancer/instancedSprite/instancedSpriteBaseEnhancer/mutates.test.ts +277 -0
- package/src/material/enhancer/instancedSprite/instancedSpriteBaseEnhancer/mutates.ts +151 -0
- package/src/material/enhancer/instancedSprite/instancedSpriteBaseEnhancer/shader.test.ts +114 -0
- package/src/material/enhancer/instancedSprite/instancedSpriteBaseEnhancer/shader.ts +49 -0
- package/src/material/enhancer/instancedSprite/instancedSpriteBaseEnhancer/state.test.ts +82 -0
- package/src/material/enhancer/instancedSprite/instancedSpriteBaseEnhancer/state.ts +80 -0
- package/src/material/enhancer/instancedSprite/instancedSpriteBaseEnhancer/types.ts +146 -0
- package/src/material/enhancer/instancedSprite/instancedSpriteMaterialEnhancer.ts +105 -0
- package/src/material/enhancer/model/index.ts +25 -0
- package/src/material/enhancer/model/modelBaseEnhancer/index.test.ts +74 -0
- package/src/material/enhancer/model/modelBaseEnhancer/index.ts +110 -0
- package/src/material/enhancer/model/modelBaseEnhancer/markers.ts +27 -0
- package/src/material/enhancer/model/modelBaseEnhancer/material.test.ts +66 -0
- package/src/material/enhancer/model/modelBaseEnhancer/material.ts +44 -0
- package/src/material/enhancer/model/modelBaseEnhancer/mutates.test.ts +84 -0
- package/src/material/enhancer/model/modelBaseEnhancer/mutates.ts +47 -0
- package/src/material/enhancer/model/modelBaseEnhancer/shader.test.ts +24 -0
- package/src/material/enhancer/model/modelBaseEnhancer/shader.ts +162 -0
- package/src/material/enhancer/model/modelBaseEnhancer/state.test.ts +103 -0
- package/src/material/enhancer/model/modelBaseEnhancer/state.ts +52 -0
- package/src/material/enhancer/model/modelBaseEnhancer/types.ts +89 -0
- package/src/material/enhancer/model/modelMaterialEnhancer.ts +91 -0
- package/src/material/enhancer/model/modelWaterEnhancer/index.test.ts +71 -0
- package/src/material/enhancer/model/modelWaterEnhancer/index.ts +175 -0
- package/src/material/enhancer/model/modelWaterEnhancer/material.test.ts +48 -0
- package/src/material/enhancer/model/modelWaterEnhancer/material.ts +25 -0
- package/src/material/enhancer/model/modelWaterEnhancer/mutates.test.ts +89 -0
- package/src/material/enhancer/model/modelWaterEnhancer/mutates.ts +89 -0
- package/src/material/enhancer/model/modelWaterEnhancer/shader.test.ts +34 -0
- package/src/material/enhancer/model/modelWaterEnhancer/shader.ts +111 -0
- package/src/material/enhancer/model/modelWaterEnhancer/state.test.ts +105 -0
- package/src/material/enhancer/model/modelWaterEnhancer/state.ts +59 -0
- package/src/material/enhancer/model/modelWaterEnhancer/types.ts +141 -0
- package/src/material/enhancer/model/pntsEnhancer/index.test.ts +96 -0
- package/src/material/enhancer/model/pntsEnhancer/index.ts +82 -0
- package/src/material/enhancer/model/pntsEnhancer/markers.ts +6 -0
- package/src/material/enhancer/model/pntsEnhancer/material.test.ts +37 -0
- package/src/material/enhancer/model/pntsEnhancer/material.ts +21 -0
- package/src/material/enhancer/model/pntsEnhancer/mutates.test.ts +80 -0
- package/src/material/enhancer/model/pntsEnhancer/mutates.ts +29 -0
- package/src/material/enhancer/model/pntsEnhancer/shader.test.ts +32 -0
- package/src/material/enhancer/model/pntsEnhancer/shader.ts +56 -0
- package/src/material/enhancer/model/pntsEnhancer/state.test.ts +87 -0
- package/src/material/enhancer/model/pntsEnhancer/state.ts +29 -0
- package/src/material/enhancer/model/pntsEnhancer/types.ts +38 -0
- package/src/material/enhancer/polygon/index.ts +22 -0
- package/src/material/enhancer/polygon/polygonBaseEnhancer/index.test.ts +101 -0
- package/src/material/enhancer/polygon/polygonBaseEnhancer/index.ts +130 -0
- package/src/material/enhancer/polygon/polygonBaseEnhancer/markers.ts +23 -0
- package/src/material/enhancer/polygon/polygonBaseEnhancer/material.test.ts +19 -0
- package/src/material/enhancer/polygon/polygonBaseEnhancer/material.ts +38 -0
- package/src/material/enhancer/polygon/polygonBaseEnhancer/mutates.test.ts +75 -0
- package/src/material/enhancer/polygon/polygonBaseEnhancer/mutates.ts +122 -0
- package/src/material/enhancer/polygon/polygonBaseEnhancer/shader.test.ts +25 -0
- package/src/material/enhancer/polygon/polygonBaseEnhancer/shader.ts +249 -0
- package/src/material/enhancer/polygon/polygonBaseEnhancer/state.test.ts +102 -0
- package/src/material/enhancer/polygon/polygonBaseEnhancer/state.ts +92 -0
- package/src/material/enhancer/polygon/polygonBaseEnhancer/types.ts +150 -0
- package/src/material/enhancer/polygon/polygonMaterialEnhancer.ts +97 -0
- package/src/material/enhancer/polygon/polygonWaterEnhancer/index.test.ts +72 -0
- package/src/material/enhancer/polygon/polygonWaterEnhancer/index.ts +164 -0
- package/src/material/enhancer/polygon/polygonWaterEnhancer/material.test.ts +48 -0
- package/src/material/enhancer/polygon/polygonWaterEnhancer/material.ts +35 -0
- package/src/material/enhancer/polygon/polygonWaterEnhancer/mutates.ts +61 -0
- package/src/material/enhancer/polygon/polygonWaterEnhancer/shader.test.ts +34 -0
- package/src/material/enhancer/polygon/polygonWaterEnhancer/shader.ts +96 -0
- package/src/material/enhancer/polygon/polygonWaterEnhancer/state.test.ts +98 -0
- package/src/material/enhancer/polygon/polygonWaterEnhancer/state.ts +57 -0
- package/src/material/enhancer/polygon/polygonWaterEnhancer/types.ts +115 -0
- package/src/material/enhancer/polyline/index.ts +7 -0
- package/src/material/enhancer/polyline/polylineBaseEnhancer/index.test.ts +157 -0
- package/src/material/enhancer/polyline/polylineBaseEnhancer/index.ts +154 -0
- package/src/material/enhancer/polyline/polylineBaseEnhancer/markers.ts +19 -0
- package/src/material/enhancer/polyline/polylineBaseEnhancer/material.test.ts +42 -0
- package/src/material/enhancer/polyline/polylineBaseEnhancer/material.ts +38 -0
- package/src/material/enhancer/polyline/polylineBaseEnhancer/mutates.test.ts +120 -0
- package/src/material/enhancer/polyline/polylineBaseEnhancer/mutates.ts +169 -0
- package/src/material/enhancer/polyline/polylineBaseEnhancer/shader.test.ts +67 -0
- package/src/material/enhancer/polyline/polylineBaseEnhancer/shader.ts +75 -0
- package/src/material/enhancer/polyline/polylineBaseEnhancer/state.test.ts +55 -0
- package/src/material/enhancer/polyline/polylineBaseEnhancer/state.ts +91 -0
- package/src/material/enhancer/polyline/polylineBaseEnhancer/types.ts +170 -0
- package/src/material/enhancer/polyline/polylineMaterialEnhancer.ts +102 -0
- package/src/material/enhancer/sdfText/index.ts +7 -0
- package/src/material/enhancer/sdfText/sdfTextBaseEnhancer/index.ts +125 -0
- package/src/material/enhancer/sdfText/sdfTextBaseEnhancer/markers.ts +19 -0
- package/src/material/enhancer/sdfText/sdfTextBaseEnhancer/material.test.ts +35 -0
- package/src/material/enhancer/sdfText/sdfTextBaseEnhancer/material.ts +32 -0
- package/src/material/enhancer/sdfText/sdfTextBaseEnhancer/mutates.test.ts +381 -0
- package/src/material/enhancer/sdfText/sdfTextBaseEnhancer/mutates.ts +232 -0
- package/src/material/enhancer/sdfText/sdfTextBaseEnhancer/shader.ts +36 -0
- package/src/material/enhancer/sdfText/sdfTextBaseEnhancer/state.test.ts +118 -0
- package/src/material/enhancer/sdfText/sdfTextBaseEnhancer/state.ts +107 -0
- package/src/material/enhancer/sdfText/sdfTextBaseEnhancer/types.ts +184 -0
- package/src/material/enhancer/sdfText/sdfTextMaterialEnhancer.ts +100 -0
- package/src/material/enhancer/shadowMap/index.ts +7 -0
- package/src/material/enhancer/shadowMap/shadowMapDepthEnhancer/index.ts +97 -0
- package/src/material/enhancer/shadowMap/shadowMapDepthEnhancer/markers.ts +10 -0
- package/src/material/enhancer/shadowMap/shadowMapDepthEnhancer/material.ts +31 -0
- package/src/material/enhancer/shadowMap/shadowMapDepthEnhancer/mutates.ts +8 -0
- package/src/material/enhancer/shadowMap/shadowMapDepthEnhancer/shader.test.ts +17 -0
- package/src/material/enhancer/shadowMap/shadowMapDepthEnhancer/shader.ts +53 -0
- package/src/material/enhancer/shadowMap/shadowMapDepthEnhancer/state.ts +17 -0
- package/src/material/enhancer/shadowMap/shadowMapDepthEnhancer/types.ts +26 -0
- package/src/material/enhancer/test-utils/shaderCompatibility.ts +124 -0
- package/src/material/enhancer/tileComposite/compose.test.ts +95 -0
- package/src/material/enhancer/tileComposite/compose.ts +112 -0
- package/src/material/enhancer/tileComposite/index.ts +23 -0
- package/src/material/enhancer/tileComposite/tileCompositeBaseEnhancer/index.ts +11 -0
- package/src/material/enhancer/tileComposite/tileCompositeBaseEnhancer/mutates.ts +132 -0
- package/src/material/enhancer/tileComposite/tileCompositeBaseEnhancer/shader.ts +245 -0
- package/src/material/enhancer/tileComposite/tileCompositeBaseEnhancer/types.ts +43 -0
- package/src/material/enhancer/tileComposite/tileElevationHeatmapEnhancer/index.ts +29 -0
- package/src/material/enhancer/tileComposite/tileElevationHeatmapEnhancer/mutates.ts +68 -0
- package/src/material/enhancer/tileComposite/tileElevationHeatmapEnhancer/shader.ts +24 -0
- package/src/material/enhancer/tileComposite/tileHillshadeEnhancer/index.ts +29 -0
- package/src/material/enhancer/tileComposite/tileHillshadeEnhancer/mutates.ts +34 -0
- package/src/material/enhancer/tileComposite/tileHillshadeEnhancer/shader.ts +36 -0
- package/src/material/enhancer/tileComposite/tileWaterEnhancer/index.ts +23 -0
- package/src/material/enhancer/tileComposite/tileWaterEnhancer/mutates.ts +23 -0
- package/src/material/enhancer/tileComposite/tileWaterEnhancer/shader.ts +8 -0
- package/src/material/enhancer/tileComposite/tileWatermaskEnhancer/index.ts +23 -0
- package/src/material/enhancer/tileComposite/tileWatermaskEnhancer/mutates.ts +34 -0
- package/src/material/enhancer/tileComposite/tileWatermaskEnhancer/shader.ts +13 -0
- package/src/material/enhancer/tileComposite/types.ts +58 -0
- package/src/material/index.ts +3 -0
- package/src/material/macro/index.ts +1 -0
- package/src/material/macro/tileShader.test.ts +136 -0
- package/src/material/macro/tileShader.ts +287 -0
- package/src/material/overrideMaterialsForMRT.ts +439 -0
- package/src/material/selectiveEffectMaterialSetup.test.ts +52 -0
- package/src/material/selectiveEffectMaterialSetup.ts +53 -0
- package/src/material/types/index.ts +1 -0
- package/src/material/types/uniform.ts +1 -0
- package/src/mesh/DrapedMesh.ts +101 -0
- package/src/mesh/batchTexture.test.ts +646 -0
- package/src/mesh/batchTexture.ts +437 -0
- package/src/mesh/batchedFeature.ts +186 -0
- package/src/mesh/batchedSdfText.ts +484 -0
- package/src/mesh/featureMesh.ts +43 -0
- package/src/mesh/index.ts +16 -0
- package/src/mesh/instanced.ts +117 -0
- package/src/mesh/model.ts +483 -0
- package/src/mesh/pickableMesh.ts +55 -0
- package/src/mesh/pickableMeshWrapper.ts +529 -0
- package/src/mesh/polygon.ts +699 -0
- package/src/mesh/polygonOutline.ts +393 -0
- package/src/mesh/polyline.ts +523 -0
- package/src/mesh/releaseGeometryArrays.ts +57 -0
- package/src/mesh/rtcRteHelper.ts +211 -0
- package/src/mesh/sdfText.test.ts +200 -0
- package/src/mesh/sdfText.ts +1019 -0
- package/src/mesh/sprite/billboardAtlas.test.ts +177 -0
- package/src/mesh/sprite/billboardAtlas.ts +210 -0
- package/src/mesh/sprite/billboardAtlasImageLoader.ts +29 -0
- package/src/mesh/sprite/index.ts +1 -0
- package/src/mesh/sprite/instancedSprite.ts +694 -0
- package/src/mesh/tile.test.ts +393 -0
- package/src/mesh/tile.ts +1790 -0
- package/src/object3DEvent.ts +6 -0
- package/src/orchestrators/RenderPassOrchestrator.ts +147 -0
- package/src/orchestrators/index.ts +1 -0
- package/src/passes/AllDepthCopyPass.ts +165 -0
- package/src/passes/CustomRenderPass.ts +279 -0
- package/src/passes/NormalCopyPass.ts +125 -0
- package/src/passes/RenderTargetCopyPass.ts +91 -0
- package/src/passes/SkyEnvMapPass.ts +58 -0
- package/src/passes/index.ts +5 -0
- package/src/pick/pickHelper.ts +273 -0
- package/src/pick/pickTerrain.ts +254 -0
- package/src/plugins/AttributionPlugin/AttributionPlugin.test.ts +210 -0
- package/src/plugins/AttributionPlugin/attribution.test.ts +225 -0
- package/src/plugins/AttributionPlugin/attribution.ts +355 -0
- package/src/plugins/AttributionPlugin/attributionStyles.ts +163 -0
- package/src/plugins/AttributionPlugin/index.ts +702 -0
- package/src/plugins/index.ts +1 -0
- package/src/quality.ts +1 -0
- package/src/renderOrder.ts +3 -0
- package/src/scene.test.ts +164 -0
- package/src/scene.ts +127 -0
- package/src/shaders/index.ts +1 -0
- package/src/solar.test.ts +81 -0
- package/src/solar.ts +101 -0
- package/src/source.ts +80 -0
- package/src/stats.ts +102 -0
- package/src/tasks/computeVertexNormalsAsync.ts +15 -0
- package/src/tasks/constructPolygonBatchedFeature.ts +34 -0
- package/src/tasks/constructPolylineBatchedFeature.ts +27 -0
- package/src/tasks/constructQuantizedMeshTerrainMesh.ts +24 -0
- package/src/tasks/constructTerrainMesh.ts +25 -0
- package/src/tasks/getImageDataFromBlob.ts +13 -0
- package/src/tasks/getImageDataFromImageBitmap.ts +12 -0
- package/src/tasks/parseMvtTile.ts +22 -0
- package/src/tasks/queueTask.ts +19 -0
- package/src/tasks/toCreasedNormalsAsync.ts +18 -0
- package/src/tasks/upsampleQuantizedMeshTerrainMesh.ts +44 -0
- package/src/tasks/upsampleTerrainMesh.ts +39 -0
- package/src/texture.ts +19 -0
- package/src/textures.ts +13 -0
- package/src/tileTexture/CompositeShader.snapshot.test.ts +59 -0
- package/src/tileTexture/CompositeShader.test.ts +168 -0
- package/src/tileTexture/CompositeShader.ts +53 -0
- package/src/tileTexture/SlotPlanner.test.ts +105 -0
- package/src/tileTexture/SlotPlanner.ts +102 -0
- package/src/tileTexture/TileTextureCache.test.ts +227 -0
- package/src/tileTexture/TileTextureCache.ts +192 -0
- package/src/tileTexture/TileTextureCompositor.test.ts +260 -0
- package/src/tileTexture/TileTextureCompositor.ts +421 -0
- package/src/tileTexture/__snapshots__/CompositeShader.snapshot.test.ts.snap +2649 -0
- package/src/tileTexture/index.ts +8 -0
- package/src/tileTexture/types.ts +150 -0
- package/src/type/index.ts +261 -0
- package/src/uniforms.ts +20 -0
- package/src/utils/arraysEqual.ts +9 -0
- package/src/utils/blendModes.ts +80 -0
- package/src/utils/geometry.ts +53 -0
- package/src/utils/hillshadeNormalMapGenerator.ts +193 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/object.test.ts +14 -0
- package/src/utils/object.ts +7 -0
- package/src/utils/replacer.test.ts +42 -0
- package/src/utils/replacer.ts +89 -0
- package/src/utils/screen.ts +29 -0
- package/src/utils/textureFragmentIndex.test.ts +224 -0
- package/src/utils/textureFragmentIndex.ts +97 -0
- package/src/utils/worker.ts +3 -0
- package/src/vite-env.d.ts +2 -0
- package/src/worker/index.ts +13 -0
- package/src/worker/tasks/computeVertexNormals.ts +15 -0
- package/src/worker/tasks/toCreasedNormals.ts +22 -0
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
TextMesh as NavaraTextMesh,
|
|
3
|
+
TextMaterial as NavaraTextMaterial,
|
|
4
|
+
} from "@navaramap/engine";
|
|
5
|
+
import type { FontManager } from "@navaramap/font";
|
|
6
|
+
import { type Color } from "three";
|
|
7
|
+
import invariant from "tiny-invariant";
|
|
8
|
+
|
|
9
|
+
import type { EventContext } from "../event/context";
|
|
10
|
+
|
|
11
|
+
import { InstancedMesh, type InstancedMeshOptions } from "./instanced";
|
|
12
|
+
import type { PickableMesh } from "./pickableMesh";
|
|
13
|
+
import { SDFTextMesh } from "./sdfText";
|
|
14
|
+
|
|
15
|
+
type PositionsInfoBase = {
|
|
16
|
+
batchIDs: Float32Array<ArrayBufferLike> | null;
|
|
17
|
+
positionSize: number;
|
|
18
|
+
batchIDSize: number;
|
|
19
|
+
nPositions: number;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type PositionsInfo = PositionsInfoBase &
|
|
23
|
+
(
|
|
24
|
+
| {
|
|
25
|
+
RTE: true;
|
|
26
|
+
position: {
|
|
27
|
+
high: Float32Array<ArrayBufferLike>;
|
|
28
|
+
low: Float32Array<ArrayBufferLike>;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
| {
|
|
32
|
+
RTE: false;
|
|
33
|
+
position: Float32Array<ArrayBufferLike>;
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
export class BatchedSdfTextMesh
|
|
38
|
+
extends InstancedMesh<SDFTextMesh>
|
|
39
|
+
implements PickableMesh
|
|
40
|
+
{
|
|
41
|
+
readonly ctx: EventContext;
|
|
42
|
+
/** The font identifier from material — may be a family name or a URL. */
|
|
43
|
+
private _fontIdentifier: string;
|
|
44
|
+
/** Per-batch text quality. All instanced meshes in this batch share it
|
|
45
|
+
* because they all sample the same atlas texture; flipping quality requires
|
|
46
|
+
* a new BatchedSdfTextMesh. */
|
|
47
|
+
private _highQuality: boolean;
|
|
48
|
+
private _fontManager: FontManager;
|
|
49
|
+
private _needRender?: () => void;
|
|
50
|
+
/** Unsubscribe from the font manager's atlas-eviction notifications. */
|
|
51
|
+
private _unsubscribeEvict?: () => void;
|
|
52
|
+
/**
|
|
53
|
+
* Face URLs loaded by this mesh for font-family fonts.
|
|
54
|
+
* Each URL in this set has had loadFont() called exactly once by this mesh
|
|
55
|
+
* and must be balanced with unloadFont() on dispose or font change.
|
|
56
|
+
*/
|
|
57
|
+
private _loadedFaceUrls: Set<string>;
|
|
58
|
+
|
|
59
|
+
constructor(
|
|
60
|
+
ctx: EventContext,
|
|
61
|
+
m: NavaraTextMesh,
|
|
62
|
+
fontIdentifier: string,
|
|
63
|
+
options: InstancedMeshOptions,
|
|
64
|
+
loadedFaceUrls?: Set<string>,
|
|
65
|
+
) {
|
|
66
|
+
super(options);
|
|
67
|
+
this.ctx = ctx;
|
|
68
|
+
this._fontIdentifier = fontIdentifier;
|
|
69
|
+
this._highQuality = m.material.highQuality ?? false;
|
|
70
|
+
invariant(ctx.fontManager);
|
|
71
|
+
this._fontManager = ctx.fontManager;
|
|
72
|
+
this._loadedFaceUrls = loadedFaceUrls ?? new Set();
|
|
73
|
+
this.initMeshes(m);
|
|
74
|
+
// When the shared atlas evicts glyphs, a still-in-flight glyph this batch
|
|
75
|
+
// already baked into a visible mesh may have had its rect reused. Rebuild
|
|
76
|
+
// any such stale mesh so its UVs and retains refresh.
|
|
77
|
+
this._unsubscribeEvict = this._fontManager.onAtlasEvicted(
|
|
78
|
+
this._fontIdentifier,
|
|
79
|
+
this._highQuality,
|
|
80
|
+
() => this._revalidateStaleMeshes(),
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* After an atlas eviction, re-prepare and force-rebuild any visible mesh whose
|
|
86
|
+
* shaped text is now stale (its pinned glyphs may have been evicted before the
|
|
87
|
+
* retain landed and its rect reused). Fresh meshes short-circuit on the cheap
|
|
88
|
+
* `isTextPrepared` check, so this is inexpensive to run per eviction.
|
|
89
|
+
*/
|
|
90
|
+
private _revalidateStaleMeshes(): void {
|
|
91
|
+
const q = this._highQuality;
|
|
92
|
+
for (const mesh of this.meshes()) {
|
|
93
|
+
const text = mesh.text;
|
|
94
|
+
if (!mesh.visible || !text) continue;
|
|
95
|
+
if (this._fontManager.isTextPrepared(this._fontIdentifier, text, q)) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
this._fontManager
|
|
99
|
+
.prepareText(this._fontIdentifier, text, q, this._loadedFaceUrls)
|
|
100
|
+
.then(() => {
|
|
101
|
+
// Text may have changed (or the mesh hidden) while re-preparing.
|
|
102
|
+
if (mesh.text !== text || !mesh.visible) return;
|
|
103
|
+
const sharedTex = this._fontManager.getAtlasTexture(
|
|
104
|
+
this._fontIdentifier,
|
|
105
|
+
q,
|
|
106
|
+
);
|
|
107
|
+
if (sharedTex) mesh.setAtlasTexture(sharedTex);
|
|
108
|
+
mesh.setColorAtlasTexture(
|
|
109
|
+
this._fontManager.getColorAtlasTexture(this._fontIdentifier, q),
|
|
110
|
+
);
|
|
111
|
+
// Force a rebuild even though the text string is unchanged: the baked
|
|
112
|
+
// atlas rects and glyph retains must refresh against the new metrics.
|
|
113
|
+
mesh.setText(text, true);
|
|
114
|
+
this._needRender?.();
|
|
115
|
+
})
|
|
116
|
+
.catch((err: unknown) => {
|
|
117
|
+
console.error("Failed to revalidate text after eviction:", err);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
get fontIdentifier(): string {
|
|
123
|
+
return this._fontIdentifier;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
get highQuality(): boolean {
|
|
127
|
+
return this._highQuality;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private initMeshes(m: NavaraTextMesh) {
|
|
131
|
+
const positionInfo = this.extractPositions(m);
|
|
132
|
+
if (!positionInfo) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const { position, nPositions, positionSize, batchIDs, batchIDSize, RTE } =
|
|
137
|
+
positionInfo;
|
|
138
|
+
|
|
139
|
+
const material = m.material;
|
|
140
|
+
const transform = m.transform;
|
|
141
|
+
|
|
142
|
+
// Get the font-level shared atlas textures (one DataTexture per font,
|
|
143
|
+
// shared across all per-feature meshes). The color atlas is `null` for
|
|
144
|
+
// monochrome fonts.
|
|
145
|
+
const sharedTex = this._fontManager.getAtlasTexture(
|
|
146
|
+
this._fontIdentifier,
|
|
147
|
+
this._highQuality,
|
|
148
|
+
);
|
|
149
|
+
const sharedColorTex = this._fontManager.getColorAtlasTexture(
|
|
150
|
+
this._fontIdentifier,
|
|
151
|
+
this._highQuality,
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
for (let i = 0; i < nPositions; i++) {
|
|
155
|
+
const batchIdIdx = i * batchIDSize;
|
|
156
|
+
const batchId = batchIDs ? batchIDs[batchIdIdx] : undefined;
|
|
157
|
+
const posIdx = i * positionSize;
|
|
158
|
+
const pos = RTE
|
|
159
|
+
? {
|
|
160
|
+
high: position.high.subarray(posIdx, posIdx + positionSize),
|
|
161
|
+
low: position.low.subarray(posIdx, posIdx + positionSize),
|
|
162
|
+
}
|
|
163
|
+
: position.subarray(posIdx, posIdx + positionSize);
|
|
164
|
+
|
|
165
|
+
const mesh = new SDFTextMesh(
|
|
166
|
+
pos,
|
|
167
|
+
material,
|
|
168
|
+
transform,
|
|
169
|
+
this._fontManager,
|
|
170
|
+
this._fontIdentifier,
|
|
171
|
+
batchId,
|
|
172
|
+
RTE,
|
|
173
|
+
);
|
|
174
|
+
mesh.renderOrder = this.renderOrder;
|
|
175
|
+
// Re-prepare evicted glyphs through the batch so font-family faces and
|
|
176
|
+
// refcounts stay consistent; request a render once they're rebuilt.
|
|
177
|
+
mesh.setGlyphLifecycleHandlers(
|
|
178
|
+
(text) =>
|
|
179
|
+
this._fontManager.prepareText(
|
|
180
|
+
this._fontIdentifier,
|
|
181
|
+
text,
|
|
182
|
+
this._highQuality,
|
|
183
|
+
this._loadedFaceUrls,
|
|
184
|
+
),
|
|
185
|
+
() => this._needRender?.(),
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
if (sharedTex) {
|
|
189
|
+
mesh.setAtlasTexture(sharedTex);
|
|
190
|
+
}
|
|
191
|
+
mesh.setColorAtlasTexture(sharedColorTex);
|
|
192
|
+
|
|
193
|
+
mesh.update(material);
|
|
194
|
+
|
|
195
|
+
this.addWithBatchIndex(mesh, i);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async _update(m: NavaraTextMesh, needRender?: () => void) {
|
|
200
|
+
if (needRender) this._needRender = needRender;
|
|
201
|
+
|
|
202
|
+
const material = m.material;
|
|
203
|
+
const text = material.text ?? "";
|
|
204
|
+
|
|
205
|
+
const positionInfo = this.extractPositions(m);
|
|
206
|
+
if (positionInfo) {
|
|
207
|
+
const { position, nPositions, positionSize, RTE } = positionInfo;
|
|
208
|
+
|
|
209
|
+
invariant(
|
|
210
|
+
nPositions === this.meshes().length,
|
|
211
|
+
"Number of positions in the updated geometry must match the number of existing meshes",
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
const transform = m.transform;
|
|
215
|
+
for (let i = 0; i < nPositions; i++) {
|
|
216
|
+
const posIdx = i * positionSize;
|
|
217
|
+
const pos = RTE
|
|
218
|
+
? {
|
|
219
|
+
high: position.high.subarray(posIdx, posIdx + positionSize),
|
|
220
|
+
low: position.low.subarray(posIdx, posIdx + positionSize),
|
|
221
|
+
}
|
|
222
|
+
: position.subarray(posIdx, posIdx + positionSize);
|
|
223
|
+
this.meshes()[i].setPosition(pos, RTE, transform);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const fontIdentifier = m.material.font ?? this._fontIdentifier;
|
|
228
|
+
const needFontUpdate = fontIdentifier !== this._fontIdentifier;
|
|
229
|
+
|
|
230
|
+
// Quality is immutable per batch (see _highQuality docs); use the batch's
|
|
231
|
+
// quality everywhere, ignoring `m.material.highQuality` on updates.
|
|
232
|
+
const q = this._highQuality;
|
|
233
|
+
|
|
234
|
+
if (needFontUpdate) {
|
|
235
|
+
// Unload old font resources.
|
|
236
|
+
if (this._loadedFaceUrls.size > 0) {
|
|
237
|
+
await Promise.all(
|
|
238
|
+
[...this._loadedFaceUrls].map((url) =>
|
|
239
|
+
this._fontManager.unloadFont(url, q),
|
|
240
|
+
),
|
|
241
|
+
);
|
|
242
|
+
this._loadedFaceUrls.clear();
|
|
243
|
+
} else if (!this._fontManager.isFamily(this._fontIdentifier)) {
|
|
244
|
+
await this._fontManager.unloadFont(this._fontIdentifier, q);
|
|
245
|
+
}
|
|
246
|
+
// For standalone new fonts load upfront; family faces are loaded lazily
|
|
247
|
+
// by prepareText below.
|
|
248
|
+
if (!this._fontManager.isFamily(fontIdentifier)) {
|
|
249
|
+
await this._fontManager.loadFont(fontIdentifier, q);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
this._fontIdentifier = fontIdentifier;
|
|
253
|
+
|
|
254
|
+
// If the text hasn't been prepared in the worker yet, schedule async preparation
|
|
255
|
+
if (
|
|
256
|
+
(needFontUpdate || text) &&
|
|
257
|
+
!this._fontManager.isTextPrepared(this._fontIdentifier, text, q)
|
|
258
|
+
) {
|
|
259
|
+
this._fontManager
|
|
260
|
+
.prepareText(this._fontIdentifier, text, q, this._loadedFaceUrls)
|
|
261
|
+
.then(() => {
|
|
262
|
+
this._applyUpdate(material, needRender, needFontUpdate);
|
|
263
|
+
})
|
|
264
|
+
.catch((err: unknown) => {
|
|
265
|
+
console.error("Failed to prepare text:", err);
|
|
266
|
+
needRender?.();
|
|
267
|
+
});
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
this._applyUpdate(material, needRender, needFontUpdate);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
private _applyUpdate(
|
|
275
|
+
material: NavaraTextMaterial,
|
|
276
|
+
needRender?: () => void,
|
|
277
|
+
forceUpdate = false,
|
|
278
|
+
) {
|
|
279
|
+
// Update shared textures (in-place update if either atlas grew)
|
|
280
|
+
const sharedTex = this._fontManager.getAtlasTexture(
|
|
281
|
+
this._fontIdentifier,
|
|
282
|
+
this._highQuality,
|
|
283
|
+
);
|
|
284
|
+
const sharedColorTex = this._fontManager.getColorAtlasTexture(
|
|
285
|
+
this._fontIdentifier,
|
|
286
|
+
this._highQuality,
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
for (const mesh of this.meshes()) {
|
|
290
|
+
if (sharedTex) mesh.setAtlasTexture(sharedTex);
|
|
291
|
+
mesh.setColorAtlasTexture(sharedColorTex);
|
|
292
|
+
mesh.update(material, forceUpdate);
|
|
293
|
+
this.markVisibility(mesh);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (needRender) needRender();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
override onBeforePicking() {
|
|
300
|
+
for (const mesh of this.meshes()) {
|
|
301
|
+
mesh.onBeforePicking();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
override onAfterPicking() {
|
|
306
|
+
for (const mesh of this.meshes()) {
|
|
307
|
+
mesh.onAfterPicking();
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
private extractPositions(m: NavaraTextMesh): PositionsInfo | null {
|
|
312
|
+
const { buf } = this.ctx;
|
|
313
|
+
const g = m.geometry;
|
|
314
|
+
|
|
315
|
+
const batchIdsData = g.batch_ids;
|
|
316
|
+
const batchIDs = buf.removeF32(batchIdsData.data);
|
|
317
|
+
const batchIDSize = batchIdsData.size;
|
|
318
|
+
|
|
319
|
+
const positionData = g.position;
|
|
320
|
+
const position = positionData
|
|
321
|
+
? buf.removeF32(positionData.data)
|
|
322
|
+
: undefined;
|
|
323
|
+
|
|
324
|
+
if (position && positionData) {
|
|
325
|
+
const positionSize = positionData.size;
|
|
326
|
+
const nPositions = position.length / positionSize;
|
|
327
|
+
|
|
328
|
+
return {
|
|
329
|
+
position,
|
|
330
|
+
batchIDs,
|
|
331
|
+
batchIDSize,
|
|
332
|
+
positionSize,
|
|
333
|
+
nPositions,
|
|
334
|
+
RTE: false,
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const positionHighData = g.position_3d_high;
|
|
339
|
+
const positionLowData = g.position_3d_low;
|
|
340
|
+
const positionHigh = positionHighData
|
|
341
|
+
? buf.removeF32(positionHighData.data)
|
|
342
|
+
: undefined;
|
|
343
|
+
const positionLow = positionLowData
|
|
344
|
+
? buf.removeF32(positionLowData.data)
|
|
345
|
+
: undefined;
|
|
346
|
+
|
|
347
|
+
if (positionHigh && positionLow && positionHighData && positionLowData) {
|
|
348
|
+
const positionLowSize = positionLowData.size;
|
|
349
|
+
const positionHighSize = positionHighData.size;
|
|
350
|
+
invariant(
|
|
351
|
+
positionLowSize === positionHighSize,
|
|
352
|
+
"Position high and low size mismatch",
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
const nPositions = positionHigh.length / positionHighSize;
|
|
356
|
+
|
|
357
|
+
return {
|
|
358
|
+
position: { high: positionHigh, low: positionLow },
|
|
359
|
+
batchIDs,
|
|
360
|
+
batchIDSize,
|
|
361
|
+
positionSize: positionHighSize,
|
|
362
|
+
nPositions,
|
|
363
|
+
RTE: true,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
setTextByBatchIndex(batchIndex: number, text: string) {
|
|
371
|
+
const mesh = this.meshes()[batchIndex];
|
|
372
|
+
|
|
373
|
+
if (mesh) {
|
|
374
|
+
// If the text hasn't been prepared in the worker yet, schedule async preparation
|
|
375
|
+
if (
|
|
376
|
+
text &&
|
|
377
|
+
!this._fontManager.isTextPrepared(
|
|
378
|
+
this._fontIdentifier,
|
|
379
|
+
text,
|
|
380
|
+
this._highQuality,
|
|
381
|
+
)
|
|
382
|
+
) {
|
|
383
|
+
// Capture the intended visibility before the async font prep begins.
|
|
384
|
+
// A concurrent processTextChanged → mesh.update(material) call may
|
|
385
|
+
// reset mesh.visible to false (because this._text is still empty)
|
|
386
|
+
// while the font is loading.
|
|
387
|
+
const intendedVisible = mesh.visible;
|
|
388
|
+
|
|
389
|
+
this._fontManager
|
|
390
|
+
.prepareText(
|
|
391
|
+
this._fontIdentifier,
|
|
392
|
+
text,
|
|
393
|
+
this._highQuality,
|
|
394
|
+
this._loadedFaceUrls,
|
|
395
|
+
)
|
|
396
|
+
.then(() => {
|
|
397
|
+
// Refresh shared atlas textures if the worker rasterized new glyphs
|
|
398
|
+
const sharedTex = this._fontManager.getAtlasTexture(
|
|
399
|
+
this._fontIdentifier,
|
|
400
|
+
this._highQuality,
|
|
401
|
+
);
|
|
402
|
+
if (sharedTex) {
|
|
403
|
+
mesh.setAtlasTexture(sharedTex);
|
|
404
|
+
}
|
|
405
|
+
mesh.setColorAtlasTexture(
|
|
406
|
+
this._fontManager.getColorAtlasTexture(
|
|
407
|
+
this._fontIdentifier,
|
|
408
|
+
this._highQuality,
|
|
409
|
+
),
|
|
410
|
+
);
|
|
411
|
+
mesh.setText(text);
|
|
412
|
+
// Restore intended visibility now that text content is available
|
|
413
|
+
mesh.visible = intendedVisible;
|
|
414
|
+
this.markVisibility(mesh);
|
|
415
|
+
this._needRender?.();
|
|
416
|
+
})
|
|
417
|
+
.catch((err: unknown) => {
|
|
418
|
+
console.error("Failed to prepare text:", err);
|
|
419
|
+
this._needRender?.();
|
|
420
|
+
});
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
mesh.setText(text);
|
|
424
|
+
this.markVisibility(mesh);
|
|
425
|
+
this._needRender?.();
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
setFeatureColorByBatchIndex(batchIndex: number, color: Color) {
|
|
430
|
+
const mesh = this.meshes()[batchIndex];
|
|
431
|
+
if (mesh) {
|
|
432
|
+
mesh.setColor(color);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
setFeatureShowByBatchIndex(batchIndex: number, rawVisible: boolean) {
|
|
437
|
+
const mesh = this.meshes()[batchIndex];
|
|
438
|
+
if (mesh) {
|
|
439
|
+
mesh._setFeatureShow(rawVisible);
|
|
440
|
+
this.markVisibility(mesh);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
setFeatureHeightByBatchIndex(batchIndex: number, height: number) {
|
|
445
|
+
const mesh = this.meshes()[batchIndex];
|
|
446
|
+
if (mesh) {
|
|
447
|
+
mesh.setHeight(height);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
setFeatureSizeByBatchIndex(batchIndex: number, size: number) {
|
|
452
|
+
const mesh = this.meshes()[batchIndex];
|
|
453
|
+
if (mesh) {
|
|
454
|
+
mesh.setSize(size);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
setFeatureOpacityByBatchIndex(batchIndex: number, opacity: number) {
|
|
459
|
+
const mesh = this.meshes()[batchIndex];
|
|
460
|
+
if (mesh) {
|
|
461
|
+
const clampedOpacity = Number.isFinite(opacity)
|
|
462
|
+
? Math.max(0, Math.min(1, opacity))
|
|
463
|
+
: 1.0;
|
|
464
|
+
mesh.setOpacity(clampedOpacity);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
dispose() {
|
|
469
|
+
this._unsubscribeEvict?.();
|
|
470
|
+
this._unsubscribeEvict = undefined;
|
|
471
|
+
const q = this._highQuality;
|
|
472
|
+
const unload =
|
|
473
|
+
this._loadedFaceUrls.size > 0
|
|
474
|
+
? Promise.all(
|
|
475
|
+
[...this._loadedFaceUrls].map((url) =>
|
|
476
|
+
this._fontManager.unloadFont(url, q),
|
|
477
|
+
),
|
|
478
|
+
)
|
|
479
|
+
: this._fontManager.unloadFont(this._fontIdentifier, q);
|
|
480
|
+
void unload.catch((err: unknown) => {
|
|
481
|
+
console.error("Failed to unload font during dispose:", err);
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Unimplemented } from "@navaramap/core";
|
|
2
|
+
import type { Color, Material } from "three";
|
|
3
|
+
|
|
4
|
+
// Interface for feature's mesh.
|
|
5
|
+
export class FeatureMesh {
|
|
6
|
+
_setFeatureColor(_color: Color, _material?: Material) {
|
|
7
|
+
throw new Unimplemented();
|
|
8
|
+
}
|
|
9
|
+
_getFeatureColor(): Color {
|
|
10
|
+
throw new Unimplemented();
|
|
11
|
+
}
|
|
12
|
+
_setFeatureShow(_visible: boolean) {
|
|
13
|
+
throw new Unimplemented();
|
|
14
|
+
}
|
|
15
|
+
_setFeatureExtrudedHeight(_height: number) {
|
|
16
|
+
throw new Unimplemented();
|
|
17
|
+
}
|
|
18
|
+
_setFeatureHeight(_height: number) {
|
|
19
|
+
throw new Unimplemented();
|
|
20
|
+
}
|
|
21
|
+
_setFeatureWidth(_width: number) {
|
|
22
|
+
throw new Unimplemented();
|
|
23
|
+
}
|
|
24
|
+
_setFeatureOpacity(_opacity: number) {
|
|
25
|
+
throw new Unimplemented();
|
|
26
|
+
}
|
|
27
|
+
_setFrustumCulled(_culled: boolean) {
|
|
28
|
+
throw new Unimplemented();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const isFeatureMesh = (v: object): v is FeatureMesh => {
|
|
33
|
+
return (
|
|
34
|
+
"_setFeatureColor" in v &&
|
|
35
|
+
"_getFeatureColor" in v &&
|
|
36
|
+
"_setFeatureShow" in v &&
|
|
37
|
+
"_setFeatureExtrudedHeight" in v &&
|
|
38
|
+
"_setFeatureHeight" in v &&
|
|
39
|
+
"_setFeatureWidth" in v &&
|
|
40
|
+
"_setFeatureOpacity" in v &&
|
|
41
|
+
"_setFrustumCulled" in v
|
|
42
|
+
);
|
|
43
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from "./model";
|
|
2
|
+
export * from "./polygon";
|
|
3
|
+
export * from "./polyline";
|
|
4
|
+
export * from "./polygonOutline";
|
|
5
|
+
export * from "./featureMesh";
|
|
6
|
+
export * from "./batchedFeature";
|
|
7
|
+
export * from "./instanced";
|
|
8
|
+
export * from "./batchTexture";
|
|
9
|
+
export * from "./tile";
|
|
10
|
+
export * from "./pickableMesh";
|
|
11
|
+
export * from "./pickableMeshWrapper";
|
|
12
|
+
export * from "./rtcRteHelper";
|
|
13
|
+
export * from "./sprite";
|
|
14
|
+
export * from "./sdfText";
|
|
15
|
+
export * from "./batchedSdfText";
|
|
16
|
+
export * from "./DrapedMesh";
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Color, Mesh, Object3D } from "three";
|
|
2
|
+
|
|
3
|
+
import { isFeatureMesh } from "./featureMesh";
|
|
4
|
+
import type { PickableMesh } from "./pickableMesh";
|
|
5
|
+
|
|
6
|
+
export type InstancedMeshOptions = {
|
|
7
|
+
renderOrder?: number;
|
|
8
|
+
layerId: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// This is used for point related mesh like point, billboard and text.
|
|
12
|
+
export class InstancedMesh<M extends Object3D>
|
|
13
|
+
extends Mesh
|
|
14
|
+
implements PickableMesh
|
|
15
|
+
{
|
|
16
|
+
visibleMeshes = new Set();
|
|
17
|
+
allMeshes: M[] = [];
|
|
18
|
+
active = false;
|
|
19
|
+
|
|
20
|
+
constructor(options: InstancedMeshOptions) {
|
|
21
|
+
super();
|
|
22
|
+
this.renderOrder = options.renderOrder ?? this.renderOrder;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// This is used to keep rendering the parent tile while the child tiles are being prepared.
|
|
26
|
+
setActive(active: boolean) {
|
|
27
|
+
this.active = active;
|
|
28
|
+
this.visible = active;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
addWithBatchIndex(m: M, batchIndex: number) {
|
|
32
|
+
m.userData.batchIndex = batchIndex;
|
|
33
|
+
|
|
34
|
+
// Manage `mesh` manually, since Three.js traverses all children.
|
|
35
|
+
this.allMeshes.push(m);
|
|
36
|
+
|
|
37
|
+
this.markVisibility(m);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
markVisibility(m: M) {
|
|
41
|
+
// Avoid adding this mesh to `Mesh.children` if the mesh is invisible,
|
|
42
|
+
// since Three.js traverses all `Mesh.children` on every frame to decide whether the mesh is rendered or not.
|
|
43
|
+
if (m.visible && !this.visibleMeshes.has(m.id)) {
|
|
44
|
+
this.add(m);
|
|
45
|
+
this.visibleMeshes.add(m.id);
|
|
46
|
+
} else if (!m.visible && this.visibleMeshes.has(m.id)) {
|
|
47
|
+
this.remove(m);
|
|
48
|
+
this.visibleMeshes.delete(m.id);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
meshes() {
|
|
53
|
+
return this.allMeshes;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getMeshByBatchIndex(batchIndex: number) {
|
|
57
|
+
return this.meshes()[batchIndex];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
setFeatureColorByBatchIndex(batchIndex: number, color: Color) {
|
|
61
|
+
const mesh = this.getMeshByBatchIndex(batchIndex);
|
|
62
|
+
if (!mesh) return;
|
|
63
|
+
|
|
64
|
+
if (!isFeatureMesh(mesh))
|
|
65
|
+
throw new Error(`Mesh doesn't support FeatureMesh`);
|
|
66
|
+
|
|
67
|
+
mesh._setFeatureColor(color);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
setFeatureShowByBatchIndex(batchIndex: number, rawVisible: boolean) {
|
|
71
|
+
const visible = this.active && rawVisible;
|
|
72
|
+
const mesh = this.getMeshByBatchIndex(batchIndex);
|
|
73
|
+
if (!mesh) return;
|
|
74
|
+
|
|
75
|
+
if (!isFeatureMesh(mesh))
|
|
76
|
+
throw new Error(`Mesh doesn't support FeatureMesh`);
|
|
77
|
+
|
|
78
|
+
mesh._setFeatureShow(visible);
|
|
79
|
+
|
|
80
|
+
this.markVisibility(mesh);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
setFeatureHeightByBatchIndex(batchIndex: number, height: number) {
|
|
84
|
+
const mesh = this.getMeshByBatchIndex(batchIndex);
|
|
85
|
+
if (!mesh) return;
|
|
86
|
+
|
|
87
|
+
if (!isFeatureMesh(mesh))
|
|
88
|
+
throw new Error(`Mesh doesn't support FeatureMesh`);
|
|
89
|
+
|
|
90
|
+
mesh._setFeatureHeight(height);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
onBeforePicking() {
|
|
94
|
+
this.setPickable(1.0);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
onAfterPicking() {
|
|
98
|
+
this.setPickable(0.0);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private setPickable(v: number) {
|
|
102
|
+
for (const mesh of this.meshes()) {
|
|
103
|
+
mesh.userData.uPickable.value = v;
|
|
104
|
+
|
|
105
|
+
if (isFeatureMesh(mesh)) {
|
|
106
|
+
// The frustum used for picking is only 1 pixel in size,
|
|
107
|
+
// and both the text and its background dynamically change positions,
|
|
108
|
+
// they risk being incorrectly culled. Therefore, frustumCulled must be set to false
|
|
109
|
+
mesh._setFrustumCulled(v < 0.5);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
getRenderable(): Object3D {
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
}
|