@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,36 @@
|
|
|
1
|
+
import sdfTextFragmentShader from "@shaders/glsl/sdfText.frag.glsl";
|
|
2
|
+
import sdfTextVertexShader from "@shaders/glsl/sdfText.vert.glsl";
|
|
3
|
+
import type { WebGLProgramParametersWithUniforms } from "three";
|
|
4
|
+
|
|
5
|
+
import type { SdfTextBaseMutates, SdfTextBaseState } from "./types";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Transform shader with sdfText base modifications.
|
|
9
|
+
*
|
|
10
|
+
* SdfText uses custom ShaderMaterial shaders. This function:
|
|
11
|
+
* 1. Sets the vertex/fragment shader sources
|
|
12
|
+
* 2. Sets defines based on state (USE_RTE)
|
|
13
|
+
* 3. Assigns uniform refs via mutates.updateUniforms()
|
|
14
|
+
*/
|
|
15
|
+
export const transformShader = (
|
|
16
|
+
shader: WebGLProgramParametersWithUniforms,
|
|
17
|
+
state: SdfTextBaseState,
|
|
18
|
+
mutates: SdfTextBaseMutates,
|
|
19
|
+
): void => {
|
|
20
|
+
// Set shaders — sdfText always uses the same shader pair
|
|
21
|
+
shader.vertexShader = sdfTextVertexShader;
|
|
22
|
+
shader.fragmentShader = sdfTextFragmentShader;
|
|
23
|
+
|
|
24
|
+
// Set defines based on state
|
|
25
|
+
shader.defines ??= {};
|
|
26
|
+
|
|
27
|
+
if (state.useRTE) {
|
|
28
|
+
shader.defines.USE_RTE = 1;
|
|
29
|
+
}
|
|
30
|
+
if (state.useMsdf) {
|
|
31
|
+
shader.defines.USE_MSDF = 1;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Assign uniform refs to shader.uniforms via mutates
|
|
35
|
+
mutates.updateUniforms(shader.uniforms, state);
|
|
36
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { DEFAULT_BASE_STATE, updateState } from "./state";
|
|
4
|
+
import { sdfRadiusFor } from "./types";
|
|
5
|
+
|
|
6
|
+
describe("sdfTextBaseEnhancer / state", () => {
|
|
7
|
+
describe("updateState", () => {
|
|
8
|
+
it("initializes state from props with defaults", () => {
|
|
9
|
+
const state = updateState({ fontSize: 24 }, DEFAULT_BASE_STATE);
|
|
10
|
+
expect(state.fontSize).toBe(24);
|
|
11
|
+
expect(state.center).toEqual([0.5, 0.0]);
|
|
12
|
+
expect(state.sizeInMeters).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("preserves immutable fields (useRTE) from currentState", () => {
|
|
16
|
+
const currentState = { ...DEFAULT_BASE_STATE, useRTE: true };
|
|
17
|
+
const state = updateState({ useRTE: false }, currentState);
|
|
18
|
+
expect(state.useRTE).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("updates color from hex to RGB tuple", () => {
|
|
22
|
+
const state = updateState({ color: 0xff0000 }, DEFAULT_BASE_STATE);
|
|
23
|
+
expect(state.color.getHex()).toBe(0xff0000);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("updates fontSize", () => {
|
|
27
|
+
const state = updateState({ fontSize: 32 }, DEFAULT_BASE_STATE);
|
|
28
|
+
expect(state.fontSize).toBe(32);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("updates center", () => {
|
|
32
|
+
const state = updateState({ center: [0.0, 0.5] }, DEFAULT_BASE_STATE);
|
|
33
|
+
expect(state.center).toEqual([0.0, 0.5]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("updates sizeInMeters", () => {
|
|
37
|
+
const state = updateState({ sizeInMeters: true }, DEFAULT_BASE_STATE);
|
|
38
|
+
expect(state.sizeInMeters).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("updates addHeight", () => {
|
|
42
|
+
const state = updateState({ addHeight: 100 }, DEFAULT_BASE_STATE);
|
|
43
|
+
expect(state.addHeight).toBe(100);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("updates offsetDepth", () => {
|
|
47
|
+
const state = updateState({ offsetDepth: false }, DEFAULT_BASE_STATE);
|
|
48
|
+
expect(state.offsetDepth).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("converts outlineWidth using the current quality's range (SDF default)", () => {
|
|
52
|
+
const state = updateState({ outlineWidth: 2.0 }, DEFAULT_BASE_STATE);
|
|
53
|
+
expect(state.outlineWidth).toBeCloseTo(
|
|
54
|
+
2.0 / sdfRadiusFor(DEFAULT_BASE_STATE.useMsdf),
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("updates outlineColor from hex", () => {
|
|
59
|
+
const state = updateState({ outlineColor: 0x00ff00 }, DEFAULT_BASE_STATE);
|
|
60
|
+
expect(state.outlineColor.getHex()).toBe(0x00ff00);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("updates outlineOpacity", () => {
|
|
64
|
+
const state = updateState({ outlineOpacity: 0.5 }, DEFAULT_BASE_STATE);
|
|
65
|
+
expect(state.outlineOpacity).toBe(0.5);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("updates showBackground", () => {
|
|
69
|
+
const state = updateState({ showBackground: true }, DEFAULT_BASE_STATE);
|
|
70
|
+
expect(state.showBackground).toBe(true);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("updates backgroundColor from hex", () => {
|
|
74
|
+
const state = updateState(
|
|
75
|
+
{ backgroundColor: 0x0000ff },
|
|
76
|
+
DEFAULT_BASE_STATE,
|
|
77
|
+
);
|
|
78
|
+
expect(state.backgroundColor.getHex()).toBe(0x0000ff);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("updates backgroundOutlineColor from hex", () => {
|
|
82
|
+
const state = updateState(
|
|
83
|
+
{ backgroundOutlineColor: 0xffff00 },
|
|
84
|
+
DEFAULT_BASE_STATE,
|
|
85
|
+
);
|
|
86
|
+
expect(state.backgroundOutlineColor.getHex()).toBe(0xffff00);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("updates backgroundOutlineWidth", () => {
|
|
90
|
+
const state = updateState(
|
|
91
|
+
{ backgroundOutlineWidth: 0.5 },
|
|
92
|
+
DEFAULT_BASE_STATE,
|
|
93
|
+
);
|
|
94
|
+
expect(state.backgroundOutlineWidth).toBe(0.5);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("updates pickable", () => {
|
|
98
|
+
const state = updateState({ pickable: true }, DEFAULT_BASE_STATE);
|
|
99
|
+
expect(state.pickable).toBe(true);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("updates depthTest", () => {
|
|
103
|
+
const state = updateState({ depthTest: false }, DEFAULT_BASE_STATE);
|
|
104
|
+
expect(state.depthTest).toBe(false);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("falls back to currentState for missing props", () => {
|
|
108
|
+
const currentState = {
|
|
109
|
+
...DEFAULT_BASE_STATE,
|
|
110
|
+
fontSize: 42,
|
|
111
|
+
center: [1, 2] as [number, number],
|
|
112
|
+
};
|
|
113
|
+
const state = updateState({}, currentState);
|
|
114
|
+
expect(state.fontSize).toBe(42);
|
|
115
|
+
expect(state.center).toEqual([1, 2]);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Color } from "three";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
sdfRadiusFor,
|
|
5
|
+
type SdfTextBaseProps,
|
|
6
|
+
type SdfTextBaseState,
|
|
7
|
+
} from "./types";
|
|
8
|
+
|
|
9
|
+
const hexToColor = (hex: number): Color => {
|
|
10
|
+
return new Color().setHex(hex);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const DEFAULT_BASE_PROPS: Required<
|
|
14
|
+
Omit<SdfTextBaseProps, "atlasTexture" | "rtcCenter">
|
|
15
|
+
> = {
|
|
16
|
+
useRTE: false,
|
|
17
|
+
useMsdf: false,
|
|
18
|
+
color: 0xffffff,
|
|
19
|
+
opacity: 1.0,
|
|
20
|
+
fontSize: 16.0,
|
|
21
|
+
center: [0.5, 0.0],
|
|
22
|
+
sizeInMeters: true,
|
|
23
|
+
addHeight: 0.0,
|
|
24
|
+
offsetDepth: true,
|
|
25
|
+
outlineWidth: 0,
|
|
26
|
+
outlineColor: 0x000000,
|
|
27
|
+
outlineOpacity: 1.0,
|
|
28
|
+
showBackground: false,
|
|
29
|
+
backgroundColor: 0xff0000,
|
|
30
|
+
backgroundOutlineColor: 0xff0000,
|
|
31
|
+
backgroundOutlineWidth: 0.1,
|
|
32
|
+
pickable: false,
|
|
33
|
+
depthTest: true,
|
|
34
|
+
transparent: true,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** Default state derived from DEFAULT_BASE_PROPS */
|
|
38
|
+
export const DEFAULT_BASE_STATE: SdfTextBaseState = {
|
|
39
|
+
useRTE: DEFAULT_BASE_PROPS.useRTE,
|
|
40
|
+
useMsdf: DEFAULT_BASE_PROPS.useMsdf,
|
|
41
|
+
color: hexToColor(DEFAULT_BASE_PROPS.color),
|
|
42
|
+
opacity: DEFAULT_BASE_PROPS.opacity,
|
|
43
|
+
fontSize: DEFAULT_BASE_PROPS.fontSize,
|
|
44
|
+
center: DEFAULT_BASE_PROPS.center,
|
|
45
|
+
sizeInMeters: DEFAULT_BASE_PROPS.sizeInMeters,
|
|
46
|
+
addHeight: DEFAULT_BASE_PROPS.addHeight,
|
|
47
|
+
offsetDepth: DEFAULT_BASE_PROPS.offsetDepth,
|
|
48
|
+
outlineWidth:
|
|
49
|
+
DEFAULT_BASE_PROPS.outlineWidth / sdfRadiusFor(DEFAULT_BASE_PROPS.useMsdf),
|
|
50
|
+
outlineColor: hexToColor(DEFAULT_BASE_PROPS.outlineColor),
|
|
51
|
+
outlineOpacity: DEFAULT_BASE_PROPS.outlineOpacity,
|
|
52
|
+
showBackground: DEFAULT_BASE_PROPS.showBackground,
|
|
53
|
+
backgroundColor: hexToColor(DEFAULT_BASE_PROPS.backgroundColor),
|
|
54
|
+
backgroundOutlineColor: hexToColor(DEFAULT_BASE_PROPS.backgroundOutlineColor),
|
|
55
|
+
backgroundOutlineWidth: DEFAULT_BASE_PROPS.backgroundOutlineWidth,
|
|
56
|
+
pickable: DEFAULT_BASE_PROPS.pickable,
|
|
57
|
+
depthTest: DEFAULT_BASE_PROPS.depthTest,
|
|
58
|
+
transparent: DEFAULT_BASE_PROPS.transparent,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Update mutable state from props.
|
|
63
|
+
* Props override currentState values; missing props fall back to currentState.
|
|
64
|
+
* Pass DEFAULT_BASE_STATE as currentState for initial mount.
|
|
65
|
+
*/
|
|
66
|
+
export const updateState = (
|
|
67
|
+
props: SdfTextBaseProps,
|
|
68
|
+
currentState: SdfTextBaseState,
|
|
69
|
+
): SdfTextBaseState => {
|
|
70
|
+
return {
|
|
71
|
+
// Immutable after mount
|
|
72
|
+
useRTE: currentState.useRTE,
|
|
73
|
+
useMsdf: currentState.useMsdf,
|
|
74
|
+
// Mutable
|
|
75
|
+
color:
|
|
76
|
+
props.color !== undefined ? hexToColor(props.color) : currentState.color,
|
|
77
|
+
opacity: props.opacity ?? currentState.opacity,
|
|
78
|
+
fontSize: props.fontSize ?? currentState.fontSize,
|
|
79
|
+
center: props.center ?? currentState.center,
|
|
80
|
+
sizeInMeters: props.sizeInMeters ?? currentState.sizeInMeters,
|
|
81
|
+
addHeight: props.addHeight ?? currentState.addHeight,
|
|
82
|
+
offsetDepth: props.offsetDepth ?? currentState.offsetDepth,
|
|
83
|
+
outlineWidth:
|
|
84
|
+
props.outlineWidth !== undefined
|
|
85
|
+
? props.outlineWidth / sdfRadiusFor(currentState.useMsdf)
|
|
86
|
+
: currentState.outlineWidth,
|
|
87
|
+
outlineColor:
|
|
88
|
+
props.outlineColor !== undefined
|
|
89
|
+
? hexToColor(props.outlineColor)
|
|
90
|
+
: currentState.outlineColor,
|
|
91
|
+
outlineOpacity: props.outlineOpacity ?? currentState.outlineOpacity,
|
|
92
|
+
showBackground: props.showBackground ?? currentState.showBackground,
|
|
93
|
+
backgroundColor:
|
|
94
|
+
props.backgroundColor !== undefined
|
|
95
|
+
? hexToColor(props.backgroundColor)
|
|
96
|
+
: currentState.backgroundColor,
|
|
97
|
+
backgroundOutlineColor:
|
|
98
|
+
props.backgroundOutlineColor !== undefined
|
|
99
|
+
? hexToColor(props.backgroundOutlineColor)
|
|
100
|
+
: currentState.backgroundOutlineColor,
|
|
101
|
+
backgroundOutlineWidth:
|
|
102
|
+
props.backgroundOutlineWidth ?? currentState.backgroundOutlineWidth,
|
|
103
|
+
pickable: props.pickable ?? currentState.pickable,
|
|
104
|
+
depthTest: props.depthTest ?? currentState.depthTest,
|
|
105
|
+
transparent: props.transparent ?? currentState.transparent,
|
|
106
|
+
};
|
|
107
|
+
};
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { atlasRangePx } from "@navaramap/font";
|
|
2
|
+
import type { Color, DataTexture, Matrix4, Vector2, Vector3 } from "three";
|
|
3
|
+
|
|
4
|
+
import type { UniformValue } from "../../../types";
|
|
5
|
+
import type { Mutates } from "../../MaterialEnhancer";
|
|
6
|
+
|
|
7
|
+
/** Pixel range covered by a quality's atlas distance field; defines how
|
|
8
|
+
* outline-width pixels translate to a distance-value delta. SDF (`useMsdf=false`)
|
|
9
|
+
* uses the classic 35 px radius from `sdf_glyph_renderer`; MSDF uses
|
|
10
|
+
* `MSDF_RANGE_PX` (8 px). See [`atlasRangePx`] in `@navaramap/font`. */
|
|
11
|
+
export const sdfRadiusFor = (useMsdf: boolean): number => atlasRangePx(useMsdf);
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Props for the sdfText base enhancer.
|
|
15
|
+
*/
|
|
16
|
+
export type SdfTextBaseProps = {
|
|
17
|
+
// Immutable after mount
|
|
18
|
+
useRTE?: boolean;
|
|
19
|
+
/** When `true` the fragment shader samples the atlas as 4-channel MTSDF
|
|
20
|
+
* (median of RGB + true SDF in alpha) instead of single-channel R8. */
|
|
21
|
+
useMsdf?: boolean;
|
|
22
|
+
|
|
23
|
+
// Mutable state
|
|
24
|
+
color?: number; // hex color
|
|
25
|
+
opacity?: number;
|
|
26
|
+
fontSize?: number;
|
|
27
|
+
center?: [number, number];
|
|
28
|
+
sizeInMeters?: boolean;
|
|
29
|
+
addHeight?: number;
|
|
30
|
+
offsetDepth?: boolean;
|
|
31
|
+
outlineWidth?: number; // raw width, converted in state via sdfRadiusFor(useMsdf)
|
|
32
|
+
outlineColor?: number; // hex
|
|
33
|
+
outlineOpacity?: number;
|
|
34
|
+
showBackground?: boolean;
|
|
35
|
+
backgroundColor?: number; // hex
|
|
36
|
+
backgroundOutlineColor?: number; // hex
|
|
37
|
+
backgroundOutlineWidth?: number;
|
|
38
|
+
pickable?: boolean;
|
|
39
|
+
|
|
40
|
+
// Material properties (set directly on material, not via uniforms)
|
|
41
|
+
depthTest?: boolean;
|
|
42
|
+
transparent?: boolean;
|
|
43
|
+
|
|
44
|
+
// External uniform refs / values (may change over time)
|
|
45
|
+
rtcCenter?: [number, number, number];
|
|
46
|
+
atlasTexture?: UniformValue<DataTexture | null>;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Immutable state snapshot for the sdfText base enhancer.
|
|
51
|
+
*/
|
|
52
|
+
export type SdfTextBaseState = Readonly<{
|
|
53
|
+
// Immutable after mount
|
|
54
|
+
useRTE: boolean;
|
|
55
|
+
useMsdf: boolean;
|
|
56
|
+
|
|
57
|
+
// Mutable
|
|
58
|
+
color: Color;
|
|
59
|
+
opacity: number;
|
|
60
|
+
fontSize: number;
|
|
61
|
+
center: [number, number];
|
|
62
|
+
sizeInMeters: boolean;
|
|
63
|
+
addHeight: number;
|
|
64
|
+
offsetDepth: boolean;
|
|
65
|
+
outlineWidth: number; // pre-converted: raw / sdfRadiusFor(useMsdf)
|
|
66
|
+
outlineColor: Color;
|
|
67
|
+
outlineOpacity: number;
|
|
68
|
+
showBackground: boolean;
|
|
69
|
+
backgroundColor: Color;
|
|
70
|
+
backgroundOutlineColor: Color;
|
|
71
|
+
backgroundOutlineWidth: number;
|
|
72
|
+
pickable: boolean;
|
|
73
|
+
|
|
74
|
+
// Material properties
|
|
75
|
+
depthTest: boolean;
|
|
76
|
+
transparent: boolean;
|
|
77
|
+
}>;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Mutable references (uniforms) for the sdfText base enhancer.
|
|
81
|
+
* These are shared references with shader.uniforms.
|
|
82
|
+
* Internal type - not exposed externally.
|
|
83
|
+
*/
|
|
84
|
+
export type SdfTextBaseRefs = {
|
|
85
|
+
uColor: UniformValue<Color>;
|
|
86
|
+
uOpacity: UniformValue<number>;
|
|
87
|
+
uFontSize: UniformValue<number>;
|
|
88
|
+
uCenter: UniformValue<Vector2>;
|
|
89
|
+
uSizeInMeters: UniformValue<boolean>;
|
|
90
|
+
uAddHeight: UniformValue<number>;
|
|
91
|
+
uOffsetDepth: UniformValue<boolean>;
|
|
92
|
+
uSdfThreshold: UniformValue<number>;
|
|
93
|
+
uOutlineWidth: UniformValue<number>;
|
|
94
|
+
uOutlineColor: UniformValue<Color>;
|
|
95
|
+
uOutlineOpacity: UniformValue<number>;
|
|
96
|
+
uShowBackground: UniformValue<boolean>;
|
|
97
|
+
uBackgroundColor: UniformValue<Color>;
|
|
98
|
+
uBackgroundOutlineColor: UniformValue<Color>;
|
|
99
|
+
uBackgroundOutlineWidth: UniformValue<number>;
|
|
100
|
+
uFovRad: UniformValue<number>;
|
|
101
|
+
uScreenHeightPx: UniformValue<number>;
|
|
102
|
+
uFarPlane: UniformValue<number>;
|
|
103
|
+
uTextWidth: UniformValue<number>;
|
|
104
|
+
uTextHeight: UniformValue<number>;
|
|
105
|
+
uBgYBounds: UniformValue<Vector2>;
|
|
106
|
+
uRTCCenter: UniformValue<Vector3>;
|
|
107
|
+
uRTCCenterView: UniformValue<Vector3>;
|
|
108
|
+
uEyeRTELow: UniformValue<Vector3>;
|
|
109
|
+
uEyeRTEHigh: UniformValue<Vector3>;
|
|
110
|
+
nvr_uBatchId: UniformValue<number>;
|
|
111
|
+
nvr_uPickable: UniformValue<number>;
|
|
112
|
+
uAtlas: UniformValue<DataTexture | null>;
|
|
113
|
+
/** COLRv1 RGBA atlas. `null` when the font has no color glyphs. */
|
|
114
|
+
uColorAtlas: UniformValue<DataTexture | null>;
|
|
115
|
+
/** Current SDF atlas pixel dimensions; updated when the Rust atlas grows. */
|
|
116
|
+
uSdfAtlasSize: UniformValue<Vector2>;
|
|
117
|
+
/** Current color atlas pixel dimensions; updated when the color atlas grows. */
|
|
118
|
+
uColorAtlasSize: UniformValue<Vector2>;
|
|
119
|
+
|
|
120
|
+
// Conditional RTE/RTC position uniforms
|
|
121
|
+
uRTEPositionLOW?: UniformValue<Vector3>;
|
|
122
|
+
uRTEPositionHIGH?: UniformValue<Vector3>;
|
|
123
|
+
uRTCPosition?: UniformValue<Vector3>;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export type SdfTextBaseUniforms = Partial<SdfTextBaseRefs>;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Mutation functions for the sdfText base enhancer.
|
|
130
|
+
*/
|
|
131
|
+
export type SdfTextBaseMutates = Mutates<
|
|
132
|
+
SdfTextBaseState,
|
|
133
|
+
SdfTextBaseUniforms,
|
|
134
|
+
{
|
|
135
|
+
/**
|
|
136
|
+
* Update per-frame camera uniforms (FOV, screen height, far plane, RTE eye).
|
|
137
|
+
*/
|
|
138
|
+
updatePerFrame: (
|
|
139
|
+
fovRad: number,
|
|
140
|
+
screenHeightPx: number,
|
|
141
|
+
farPlane: number,
|
|
142
|
+
cameraX: number,
|
|
143
|
+
cameraY: number,
|
|
144
|
+
cameraZ: number,
|
|
145
|
+
viewMatrix: Matrix4,
|
|
146
|
+
state: SdfTextBaseState,
|
|
147
|
+
) => void;
|
|
148
|
+
/**
|
|
149
|
+
* Update text dimension uniforms after text shaping.
|
|
150
|
+
*/
|
|
151
|
+
updateTextDimensions: (
|
|
152
|
+
textWidth: number,
|
|
153
|
+
textHeight: number,
|
|
154
|
+
bgMinY: number,
|
|
155
|
+
bgMaxY: number,
|
|
156
|
+
) => void;
|
|
157
|
+
/**
|
|
158
|
+
* Set the SDF atlas texture external ref.
|
|
159
|
+
*/
|
|
160
|
+
setAtlasTexture: (texture: UniformValue<DataTexture | null>) => void;
|
|
161
|
+
/**
|
|
162
|
+
* Set the COLRv1 color atlas texture external ref.
|
|
163
|
+
*/
|
|
164
|
+
setColorAtlasTexture: (texture: UniformValue<DataTexture | null>) => void;
|
|
165
|
+
/**
|
|
166
|
+
* Sync the atlas-size uniforms with the currently-bound atlas textures.
|
|
167
|
+
* Cheap to call every frame; the shader divides glyph pixel rects by these
|
|
168
|
+
* to derive UVs, so this is how atlas resizes propagate to existing meshes.
|
|
169
|
+
*/
|
|
170
|
+
updateAtlasSizes: () => void;
|
|
171
|
+
/**
|
|
172
|
+
* Update position uniforms (RTE or RTC).
|
|
173
|
+
*/
|
|
174
|
+
setPosition: (
|
|
175
|
+
position: Float32Array | { high: Float32Array; low: Float32Array },
|
|
176
|
+
useRTE: boolean,
|
|
177
|
+
rtcCenter?: [number, number, number],
|
|
178
|
+
) => void;
|
|
179
|
+
/**
|
|
180
|
+
* Set the batch ID uniform (immutable after mount, but needed for batch creation).
|
|
181
|
+
*/
|
|
182
|
+
setBatchId: (batchId: number) => void;
|
|
183
|
+
}
|
|
184
|
+
>;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SdfText Material Enhancer - Currently just the Base enhancer
|
|
3
|
+
*
|
|
4
|
+
* This module provides sdfText material functionality using the base enhancer.
|
|
5
|
+
* Structured for future composition if additional enhancers are needed.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { MaterialEnhancer } from "../MaterialEnhancer";
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
createSdfTextBaseEnhancer,
|
|
12
|
+
type SdfTextBaseMutates,
|
|
13
|
+
type SdfTextBaseProps,
|
|
14
|
+
type SdfTextBaseState,
|
|
15
|
+
type SupportedMaterial,
|
|
16
|
+
} from "./sdfTextBaseEnhancer";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Props for the sdfText material enhancer.
|
|
20
|
+
* Currently just wraps the base props, but structured for future composition.
|
|
21
|
+
*/
|
|
22
|
+
export type SdfTextMaterialProps = {
|
|
23
|
+
base?: SdfTextBaseProps;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// Shaders this enhancer supports (custom ShaderMaterial via the "shader" shader name)
|
|
27
|
+
const AVAILABLE_SHADERS = ["shader"] as const;
|
|
28
|
+
type AVAILABLE_SHADERS = typeof AVAILABLE_SHADERS;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Factory function to create the sdfText material enhancer.
|
|
32
|
+
*
|
|
33
|
+
* This creates a new enhancer instance with its own internal state.
|
|
34
|
+
*
|
|
35
|
+
* @param material - The Three.js ShaderMaterial to enhance
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const material = new ShaderMaterial({ transparent: true });
|
|
40
|
+
* const enhancer = createSdfTextMaterialEnhancer(material);
|
|
41
|
+
*
|
|
42
|
+
* // Mount with base props
|
|
43
|
+
* enhancer.mount({
|
|
44
|
+
* base: { color: 0xffffff, fontSize: 16, useRTE: true },
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* // Get state directly via states() - refresh after updates
|
|
48
|
+
* const state = enhancer.states();
|
|
49
|
+
*
|
|
50
|
+
* // Update per-frame via mutates()
|
|
51
|
+
* const mutates = enhancer.mutates();
|
|
52
|
+
* mutates.updatePerFrame(fov, screenHeight, farPlane, camX, camY, camZ, state);
|
|
53
|
+
*
|
|
54
|
+
* // Update props (then call states() again to get fresh state)
|
|
55
|
+
* enhancer.update({ base: { color: 0xff0000 } });
|
|
56
|
+
*
|
|
57
|
+
* // Use transformShader for onBeforeCompile
|
|
58
|
+
* material.onBeforeCompile = enhancer.transformShader;
|
|
59
|
+
* material.customProgramCacheKey = enhancer.programCacheKey;
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export function createSdfTextMaterialEnhancer(
|
|
63
|
+
material: SupportedMaterial,
|
|
64
|
+
): MaterialEnhancer<
|
|
65
|
+
SupportedMaterial,
|
|
66
|
+
SdfTextMaterialProps,
|
|
67
|
+
SdfTextBaseState,
|
|
68
|
+
SdfTextBaseMutates,
|
|
69
|
+
AVAILABLE_SHADERS
|
|
70
|
+
> {
|
|
71
|
+
const baseEnhancer = createSdfTextBaseEnhancer(material);
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
material,
|
|
75
|
+
availableShaders: AVAILABLE_SHADERS,
|
|
76
|
+
|
|
77
|
+
transformShader: (shader) => {
|
|
78
|
+
baseEnhancer.transformShader(shader);
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
mount: (props) => {
|
|
82
|
+
baseEnhancer.mount(props.base ?? {});
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
update: (props) => {
|
|
86
|
+
if (props.base) {
|
|
87
|
+
baseEnhancer.update(props.base);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
states: () => baseEnhancer.states(),
|
|
92
|
+
|
|
93
|
+
mutates: () => baseEnhancer.mutates(),
|
|
94
|
+
|
|
95
|
+
programCacheKey: () => baseEnhancer.programCacheKey(),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Re-export types for convenience
|
|
100
|
+
export type { SdfTextBaseMutates, SdfTextBaseProps, SdfTextBaseState };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { defaults } from "lodash-es";
|
|
2
|
+
import type { WebGLProgramParametersWithUniforms } from "three";
|
|
3
|
+
import invariant from "tiny-invariant";
|
|
4
|
+
|
|
5
|
+
import type { MaterialEnhancer } from "../../MaterialEnhancer";
|
|
6
|
+
|
|
7
|
+
import { AVAILABLE_SHADERS, type SupportedMaterial } from "./material";
|
|
8
|
+
import { createShadowMapDepthMutates } from "./mutates";
|
|
9
|
+
import { transformShader } from "./shader";
|
|
10
|
+
import {
|
|
11
|
+
DEFAULT_SHADOW_MAP_DEPTH_PROPS,
|
|
12
|
+
DEFAULT_SHADOW_MAP_DEPTH_STATE,
|
|
13
|
+
updateState,
|
|
14
|
+
} from "./state";
|
|
15
|
+
import type {
|
|
16
|
+
ShadowMapDepthMutates,
|
|
17
|
+
ShadowMapDepthProps,
|
|
18
|
+
ShadowMapDepthState,
|
|
19
|
+
} from "./types";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Factory function to create a shadow map depth enhancer.
|
|
23
|
+
*
|
|
24
|
+
* This enhancer handles shadow map depth shader injection.
|
|
25
|
+
* It's designed to be used with customDepthMaterial for shadow map generation.
|
|
26
|
+
*
|
|
27
|
+
* @param material - The Three.js material to enhance
|
|
28
|
+
*/
|
|
29
|
+
export function createShadowMapDepthEnhancer(
|
|
30
|
+
material: SupportedMaterial,
|
|
31
|
+
): MaterialEnhancer<
|
|
32
|
+
SupportedMaterial,
|
|
33
|
+
ShadowMapDepthProps,
|
|
34
|
+
ShadowMapDepthState,
|
|
35
|
+
ShadowMapDepthMutates,
|
|
36
|
+
typeof AVAILABLE_SHADERS
|
|
37
|
+
> {
|
|
38
|
+
// Internal state - immutable, always replaced as a whole
|
|
39
|
+
let state: ShadowMapDepthState | null = null;
|
|
40
|
+
// Internal mutates object (refs are external, set via props)
|
|
41
|
+
let mutates: ShadowMapDepthMutates | null = null;
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
material,
|
|
45
|
+
availableShaders: AVAILABLE_SHADERS,
|
|
46
|
+
|
|
47
|
+
transformShader: (shader: WebGLProgramParametersWithUniforms): void => {
|
|
48
|
+
invariant(
|
|
49
|
+
state && mutates,
|
|
50
|
+
"mount() must be called before transformShader",
|
|
51
|
+
);
|
|
52
|
+
transformShader(shader, state, mutates);
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
mount: (props: ShadowMapDepthProps): void => {
|
|
56
|
+
const mergedProps = defaults({}, props, DEFAULT_SHADOW_MAP_DEPTH_PROPS);
|
|
57
|
+
state = updateState(mergedProps, DEFAULT_SHADOW_MAP_DEPTH_STATE);
|
|
58
|
+
// Create mutates
|
|
59
|
+
mutates = createShadowMapDepthMutates();
|
|
60
|
+
mutates.update(state);
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
update: (props: ShadowMapDepthProps): void => {
|
|
64
|
+
invariant(state && mutates, "mount() must be called before update");
|
|
65
|
+
state = updateState(props, state);
|
|
66
|
+
mutates.update(state);
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
states: (): ShadowMapDepthState => {
|
|
70
|
+
invariant(state, "mount() must be called before states");
|
|
71
|
+
return state;
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
mutates: (): ShadowMapDepthMutates => {
|
|
75
|
+
invariant(mutates, "mount() must be called before mutates");
|
|
76
|
+
return mutates;
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
programCacheKey: (): string => {
|
|
80
|
+
invariant(state, "mount() must be called before programCacheKey");
|
|
81
|
+
// RTE is always enabled for this enhancer
|
|
82
|
+
return JSON.stringify({});
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Re-export public types
|
|
88
|
+
export type { ShadowMapDepthMutates, ShadowMapDepthProps, ShadowMapDepthState };
|
|
89
|
+
|
|
90
|
+
// Re-export SupportedMaterial
|
|
91
|
+
export type { SupportedMaterial } from "./material";
|
|
92
|
+
|
|
93
|
+
// Re-export marker types for composing enhancers
|
|
94
|
+
export {
|
|
95
|
+
SHADOW_MAP_DEPTH_SHADER_MARKERS,
|
|
96
|
+
createShadowMapDepthShaderReplacer,
|
|
97
|
+
} from "./markers";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ShaderMarkers, createShaderReplacer } from "../../ShaderReplacer";
|
|
2
|
+
|
|
3
|
+
export const SHADOW_MAP_DEPTH_SHADER_MARKERS = {
|
|
4
|
+
vertex: {},
|
|
5
|
+
fragment: {},
|
|
6
|
+
} as const satisfies ShaderMarkers;
|
|
7
|
+
|
|
8
|
+
export function createShadowMapDepthShaderReplacer(source: string) {
|
|
9
|
+
return createShaderReplacer<typeof SHADOW_MAP_DEPTH_SHADER_MARKERS>(source);
|
|
10
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
MeshBasicMaterial,
|
|
3
|
+
MeshLambertMaterial,
|
|
4
|
+
MeshPhongMaterial,
|
|
5
|
+
MeshPhysicalMaterial,
|
|
6
|
+
MeshStandardMaterial,
|
|
7
|
+
} from "three";
|
|
8
|
+
|
|
9
|
+
import type { ShaderName } from "../../MaterialEnhancer";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Material types that can be enhanced by this enhancer.
|
|
13
|
+
* Supports all standard mesh materials for depth/shadow rendering.
|
|
14
|
+
*/
|
|
15
|
+
export type SupportedMaterial =
|
|
16
|
+
| MeshBasicMaterial
|
|
17
|
+
| MeshLambertMaterial
|
|
18
|
+
| MeshPhongMaterial
|
|
19
|
+
| MeshStandardMaterial
|
|
20
|
+
| MeshPhysicalMaterial;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Shader types that this enhancer can transform.
|
|
24
|
+
*/
|
|
25
|
+
export const AVAILABLE_SHADERS = [
|
|
26
|
+
"basic",
|
|
27
|
+
"lambert",
|
|
28
|
+
"phong",
|
|
29
|
+
"standard",
|
|
30
|
+
"physical",
|
|
31
|
+
] satisfies ShaderName[];
|