@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,157 @@
|
|
|
1
|
+
import { ShaderMaterial, type WebGLProgramParametersWithUniforms } from "three";
|
|
2
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
3
|
+
|
|
4
|
+
import type { PolylineBaseProps } from "./types";
|
|
5
|
+
|
|
6
|
+
import { createPolylineBaseEnhancer } from "./index";
|
|
7
|
+
|
|
8
|
+
describe("polylineBaseEnhancer", () => {
|
|
9
|
+
let enhancer: ReturnType<typeof createPolylineBaseEnhancer>;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
enhancer = createPolylineBaseEnhancer(new ShaderMaterial());
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe("lifecycle", () => {
|
|
16
|
+
it("transformShader() should throw if called before mount", () => {
|
|
17
|
+
const freshEnhancer = createPolylineBaseEnhancer(new ShaderMaterial());
|
|
18
|
+
|
|
19
|
+
const shader = {
|
|
20
|
+
uniforms: {},
|
|
21
|
+
vertexShader: "",
|
|
22
|
+
fragmentShader: "",
|
|
23
|
+
defines: {},
|
|
24
|
+
} as WebGLProgramParametersWithUniforms;
|
|
25
|
+
|
|
26
|
+
expect(() => freshEnhancer.transformShader(shader)).toThrow(
|
|
27
|
+
"mount() must be called before transformShader",
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("states() should throw if called before mount", () => {
|
|
32
|
+
const freshEnhancer = createPolylineBaseEnhancer(new ShaderMaterial());
|
|
33
|
+
|
|
34
|
+
expect(() => freshEnhancer.states()).toThrow(
|
|
35
|
+
"mount() must be called before states",
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("mutates() should throw if called before mount", () => {
|
|
40
|
+
const freshEnhancer = createPolylineBaseEnhancer(new ShaderMaterial());
|
|
41
|
+
|
|
42
|
+
expect(() => freshEnhancer.mutates()).toThrow(
|
|
43
|
+
"mount() must be called before mutates",
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("update() should throw if called before mount", () => {
|
|
48
|
+
const freshEnhancer = createPolylineBaseEnhancer(new ShaderMaterial());
|
|
49
|
+
|
|
50
|
+
expect(() => freshEnhancer.update({})).toThrow(
|
|
51
|
+
"mount() must be called before update",
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("programCacheKey() should throw if called before mount", () => {
|
|
56
|
+
const freshEnhancer = createPolylineBaseEnhancer(new ShaderMaterial());
|
|
57
|
+
|
|
58
|
+
expect(() => freshEnhancer.programCacheKey()).toThrow(
|
|
59
|
+
"mount() must be called before programCacheKey",
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("should initialize state on mount", () => {
|
|
64
|
+
const props: PolylineBaseProps = {
|
|
65
|
+
color: 0xff0000,
|
|
66
|
+
width: 2,
|
|
67
|
+
pickable: true,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
enhancer.mount(props);
|
|
71
|
+
|
|
72
|
+
const state = enhancer.states();
|
|
73
|
+
expect(state.color).toBe(0xff0000);
|
|
74
|
+
expect(state.width).toBe(2);
|
|
75
|
+
expect(state.pickable).toBe(true);
|
|
76
|
+
expect(state.useRTE).toBe(false);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("should update state on update", () => {
|
|
80
|
+
enhancer.mount({ width: 2 });
|
|
81
|
+
|
|
82
|
+
const stateBefore = enhancer.states();
|
|
83
|
+
expect(stateBefore.width).toBe(2);
|
|
84
|
+
|
|
85
|
+
enhancer.update({ width: 5 });
|
|
86
|
+
|
|
87
|
+
const stateAfter = enhancer.states();
|
|
88
|
+
expect(stateAfter.width).toBe(5);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("should allow transformShader after mount", () => {
|
|
92
|
+
enhancer.mount({ width: 2 });
|
|
93
|
+
|
|
94
|
+
const shader = {
|
|
95
|
+
uniforms: {},
|
|
96
|
+
vertexShader: "",
|
|
97
|
+
fragmentShader: "",
|
|
98
|
+
defines: {},
|
|
99
|
+
} as WebGLProgramParametersWithUniforms;
|
|
100
|
+
|
|
101
|
+
// Should not throw
|
|
102
|
+
expect(() => enhancer.transformShader(shader)).not.toThrow();
|
|
103
|
+
|
|
104
|
+
// Should have assigned uniforms
|
|
105
|
+
expect(shader.uniforms.minMaxHeightAndWidth).toBeDefined();
|
|
106
|
+
expect(shader.uniforms.color).toBeDefined();
|
|
107
|
+
expect(shader.uniforms.nvr_uPickable).toBeDefined();
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe("programCacheKey", () => {
|
|
112
|
+
it("should return cache key based on shader-affecting state", () => {
|
|
113
|
+
enhancer.mount({
|
|
114
|
+
useBatchTexture: true,
|
|
115
|
+
useBatchColorShow: false,
|
|
116
|
+
useBatchHeight: true,
|
|
117
|
+
useBatchLineWidth: false,
|
|
118
|
+
isTexturized: true,
|
|
119
|
+
useRTE: true,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const cacheKey = enhancer.programCacheKey();
|
|
123
|
+
const parsed = JSON.parse(cacheKey);
|
|
124
|
+
|
|
125
|
+
expect(parsed).toEqual({
|
|
126
|
+
useBatchTexture: true,
|
|
127
|
+
useBatchColorShow: false,
|
|
128
|
+
useBatchHeight: true,
|
|
129
|
+
useBatchLineWidth: false,
|
|
130
|
+
isTexturized: true,
|
|
131
|
+
useRTE: true,
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("should return different cache keys for different shader-affecting states", () => {
|
|
136
|
+
enhancer.mount({ useBatchTexture: false });
|
|
137
|
+
const cacheKey1 = enhancer.programCacheKey();
|
|
138
|
+
|
|
139
|
+
const enhancer2 = createPolylineBaseEnhancer(new ShaderMaterial());
|
|
140
|
+
enhancer2.mount({ useBatchTexture: true });
|
|
141
|
+
const cacheKey2 = enhancer2.programCacheKey();
|
|
142
|
+
|
|
143
|
+
expect(cacheKey1).not.toBe(cacheKey2);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("should return same cache key for same shader-affecting states with different non-affecting states", () => {
|
|
147
|
+
enhancer.mount({ useBatchTexture: true, width: 2, color: 0xff0000 });
|
|
148
|
+
const cacheKey1 = enhancer.programCacheKey();
|
|
149
|
+
|
|
150
|
+
const enhancer2 = createPolylineBaseEnhancer(new ShaderMaterial());
|
|
151
|
+
enhancer2.mount({ useBatchTexture: true, width: 10, color: 0x00ff00 });
|
|
152
|
+
const cacheKey2 = enhancer2.programCacheKey();
|
|
153
|
+
|
|
154
|
+
expect(cacheKey1).toBe(cacheKey2);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
});
|
|
@@ -0,0 +1,154 @@
|
|
|
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 { updateMaterialProps } from "./material";
|
|
9
|
+
import { createBaseMutates } from "./mutates";
|
|
10
|
+
import { transformShader } from "./shader";
|
|
11
|
+
import { DEFAULT_BASE_PROPS, DEFAULT_BASE_STATE, updateState } from "./state";
|
|
12
|
+
import type {
|
|
13
|
+
PolylineBaseMutates,
|
|
14
|
+
PolylineBaseProps,
|
|
15
|
+
PolylineBaseState,
|
|
16
|
+
} from "./types";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Factory function to create a polyline base enhancer.
|
|
20
|
+
*
|
|
21
|
+
* This enhancer handles:
|
|
22
|
+
* - Color (via shader uniforms)
|
|
23
|
+
* - Height (minMaxHeight) and width
|
|
24
|
+
* - Clamp to ground (with ground normals support)
|
|
25
|
+
* - Texturized rendering (draped on terrain)
|
|
26
|
+
* - Picking
|
|
27
|
+
* - Batch texture attributes (color, show, height, lineWidth)
|
|
28
|
+
* - RTE (Relative-To-Eye) support for high-precision coordinates
|
|
29
|
+
*
|
|
30
|
+
* Supports ShaderMaterial with custom polyline shaders.
|
|
31
|
+
* Note: Unlike polygon materials, polylines don't support opacity/transparent/wireframe
|
|
32
|
+
* as these are managed via shader uniforms and custom shader code.
|
|
33
|
+
*
|
|
34
|
+
* @param material - The Three.js ShaderMaterial to enhance
|
|
35
|
+
*/
|
|
36
|
+
export function createPolylineBaseEnhancer(
|
|
37
|
+
material: SupportedMaterial,
|
|
38
|
+
): MaterialEnhancer<
|
|
39
|
+
SupportedMaterial,
|
|
40
|
+
PolylineBaseProps,
|
|
41
|
+
PolylineBaseState,
|
|
42
|
+
PolylineBaseMutates,
|
|
43
|
+
typeof AVAILABLE_SHADERS
|
|
44
|
+
> {
|
|
45
|
+
// Internal state - immutable, always replaced as a whole
|
|
46
|
+
let state: PolylineBaseState | null = null;
|
|
47
|
+
// Internal mutates object (refs are hidden inside)
|
|
48
|
+
let mutates: PolylineBaseMutates | null = null;
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
material,
|
|
52
|
+
availableShaders: AVAILABLE_SHADERS,
|
|
53
|
+
|
|
54
|
+
transformShader: (shader: WebGLProgramParametersWithUniforms): void => {
|
|
55
|
+
invariant(
|
|
56
|
+
state && mutates,
|
|
57
|
+
"mount() must be called before transformShader",
|
|
58
|
+
);
|
|
59
|
+
transformShader(shader, state, mutates, material);
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
mount: (props: PolylineBaseProps): void => {
|
|
63
|
+
const mergedProps = defaults({}, props, DEFAULT_BASE_PROPS);
|
|
64
|
+
// Create initial state with useRTE from props (useRTE can't change after mount)
|
|
65
|
+
const initialState = {
|
|
66
|
+
...DEFAULT_BASE_STATE,
|
|
67
|
+
useRTE: mergedProps.useRTE,
|
|
68
|
+
};
|
|
69
|
+
state = updateState(mergedProps, initialState);
|
|
70
|
+
// Create mutates (refs are created inside with default values)
|
|
71
|
+
mutates = createBaseMutates(mergedProps.useRTE);
|
|
72
|
+
mutates.update(state);
|
|
73
|
+
// Set all external refs at once
|
|
74
|
+
mutates.setExternalRefs({
|
|
75
|
+
batchDataTexture: props.batchDataTexture,
|
|
76
|
+
viewportAndPixelRatio: props.viewportAndPixelRatio,
|
|
77
|
+
frustumNearFar: props.frustumNearFar,
|
|
78
|
+
frustumRatio: props.frustumRatio,
|
|
79
|
+
});
|
|
80
|
+
updateMaterialProps(material, mergedProps);
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
update: (props: PolylineBaseProps): void => {
|
|
84
|
+
invariant(state && mutates, "mount() must be called before update");
|
|
85
|
+
|
|
86
|
+
// Capture previous state for shader-affecting properties
|
|
87
|
+
const prevIsTexturized = state.isTexturized;
|
|
88
|
+
const prevUseBatchTexture = state.useBatchTexture;
|
|
89
|
+
const prevUseBatchColorShow = state.useBatchColorShow;
|
|
90
|
+
const prevUseBatchHeight = state.useBatchHeight;
|
|
91
|
+
const prevUseBatchLineWidth = state.useBatchLineWidth;
|
|
92
|
+
|
|
93
|
+
state = updateState(props, state);
|
|
94
|
+
mutates.update(state);
|
|
95
|
+
|
|
96
|
+
// Trigger shader recompilation if shader-affecting state changed
|
|
97
|
+
const shaderStateChanged =
|
|
98
|
+
state.isTexturized !== prevIsTexturized ||
|
|
99
|
+
state.useBatchTexture !== prevUseBatchTexture ||
|
|
100
|
+
state.useBatchColorShow !== prevUseBatchColorShow ||
|
|
101
|
+
state.useBatchHeight !== prevUseBatchHeight ||
|
|
102
|
+
state.useBatchLineWidth !== prevUseBatchLineWidth;
|
|
103
|
+
|
|
104
|
+
if (shaderStateChanged) {
|
|
105
|
+
material.needsUpdate = true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (props.batchDataTexture) {
|
|
109
|
+
mutates.setBatchDataTexture(props.batchDataTexture);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
updateMaterialProps(material, props);
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
states: (): PolylineBaseState => {
|
|
116
|
+
invariant(state, "mount() must be called before states");
|
|
117
|
+
return state;
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
mutates: (): PolylineBaseMutates => {
|
|
121
|
+
invariant(mutates, "mount() must be called before mutates");
|
|
122
|
+
return mutates;
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
programCacheKey: (): string => {
|
|
126
|
+
invariant(state, "mount() must be called before programCacheKey");
|
|
127
|
+
// Return cache key based on all state that affects shader sources/defines
|
|
128
|
+
return JSON.stringify({
|
|
129
|
+
// Batch-texture related flags
|
|
130
|
+
useBatchTexture: state.useBatchTexture,
|
|
131
|
+
useBatchColorShow: state.useBatchColorShow,
|
|
132
|
+
useBatchHeight: state.useBatchHeight,
|
|
133
|
+
useBatchLineWidth: state.useBatchLineWidth,
|
|
134
|
+
// Additional shader-affecting state used by transformShader
|
|
135
|
+
isTexturized: state.isTexturized,
|
|
136
|
+
useRTE: state.useRTE,
|
|
137
|
+
// Custom defines that may influence shader variants
|
|
138
|
+
userDataDefines: material.userData?.defines ?? undefined,
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Re-export public types
|
|
145
|
+
export type { PolylineBaseMutates, PolylineBaseProps, PolylineBaseState };
|
|
146
|
+
|
|
147
|
+
// Re-export SupportedMaterial for use by composing enhancers
|
|
148
|
+
export type { SupportedMaterial } from "./material";
|
|
149
|
+
|
|
150
|
+
// Re-export marker types for composing enhancers
|
|
151
|
+
export {
|
|
152
|
+
POLYLINE_BASE_SHADER_MARKERS,
|
|
153
|
+
createPolylineBaseShaderReplacer,
|
|
154
|
+
} from "./markers";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ShaderMarkers } from "../../ShaderReplacer";
|
|
2
|
+
import { createShaderReplacer } from "../../ShaderReplacer";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Shader markers for the polyline base enhancer.
|
|
6
|
+
* These markers are placed in the shader code to allow composing enhancers to inject their own code.
|
|
7
|
+
*/
|
|
8
|
+
export const POLYLINE_BASE_SHADER_MARKERS = {
|
|
9
|
+
vertex: {},
|
|
10
|
+
fragment: {},
|
|
11
|
+
} as const satisfies ShaderMarkers;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Factory function to create a ShaderReplacer restricted to polyline base markers.
|
|
15
|
+
* Used by composing enhancers to safely modify shaders.
|
|
16
|
+
*/
|
|
17
|
+
export function createPolylineBaseShaderReplacer(source: string) {
|
|
18
|
+
return createShaderReplacer<typeof POLYLINE_BASE_SHADER_MARKERS>(source);
|
|
19
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ShaderMaterial } from "three";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
|
|
4
|
+
import { updateMaterialProps } from "./material";
|
|
5
|
+
|
|
6
|
+
describe("polylineBaseEnhancer/material", () => {
|
|
7
|
+
describe("updateMaterialProps", () => {
|
|
8
|
+
it("should not update properties when props are undefined", () => {
|
|
9
|
+
const material = new ShaderMaterial();
|
|
10
|
+
material.transparent = true;
|
|
11
|
+
material.depthWrite = false;
|
|
12
|
+
|
|
13
|
+
updateMaterialProps(material, {});
|
|
14
|
+
|
|
15
|
+
expect(material.transparent).toBe(true);
|
|
16
|
+
expect(material.depthWrite).toBe(false);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("should update transparent when provided", () => {
|
|
20
|
+
const material = new ShaderMaterial();
|
|
21
|
+
material.transparent = false;
|
|
22
|
+
|
|
23
|
+
updateMaterialProps(material, { transparent: true });
|
|
24
|
+
expect(material.transparent).toBe(true);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("should update depthWrite when provided", () => {
|
|
28
|
+
const material = new ShaderMaterial();
|
|
29
|
+
material.depthWrite = true;
|
|
30
|
+
|
|
31
|
+
updateMaterialProps(material, { depthWrite: false });
|
|
32
|
+
expect(material.depthWrite).toBe(false);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should update opacity when provided", () => {
|
|
36
|
+
const material = new ShaderMaterial();
|
|
37
|
+
material.opacity = 1.0;
|
|
38
|
+
updateMaterialProps(material, { opacity: 0.5 });
|
|
39
|
+
expect(material.opacity).toBe(0.5);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ShaderMaterial } from "three";
|
|
2
|
+
|
|
3
|
+
import type { ShaderName } from "../../MaterialEnhancer";
|
|
4
|
+
|
|
5
|
+
import type { PolylineBaseProps } from "./types";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Shaders that the polyline base enhancer supports.
|
|
9
|
+
* Polylines use ShaderMaterial with custom shaders, not built-in shaders like lambert or phong.
|
|
10
|
+
*/
|
|
11
|
+
export const AVAILABLE_SHADERS = ["shader"] satisfies ShaderName[];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Material types that the polyline base enhancer supports.
|
|
15
|
+
* Polylines use ShaderMaterial exclusively.
|
|
16
|
+
*/
|
|
17
|
+
export type SupportedMaterial = ShaderMaterial;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Update material properties that affect the Three.js material directly.
|
|
21
|
+
* These properties are not handled by shader uniforms.
|
|
22
|
+
* @param material - The material to update
|
|
23
|
+
* @param props - The props to apply
|
|
24
|
+
*/
|
|
25
|
+
export function updateMaterialProps(
|
|
26
|
+
material: SupportedMaterial,
|
|
27
|
+
props: PolylineBaseProps,
|
|
28
|
+
): void {
|
|
29
|
+
if (props.transparent !== undefined) {
|
|
30
|
+
material.transparent = props.transparent;
|
|
31
|
+
}
|
|
32
|
+
if (props.opacity !== undefined) {
|
|
33
|
+
material.opacity = props.opacity;
|
|
34
|
+
}
|
|
35
|
+
if (props.depthWrite !== undefined) {
|
|
36
|
+
material.depthWrite = props.depthWrite;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Vector2 } from "three";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
|
|
4
|
+
import type { ShaderUniforms } from "../../MaterialEnhancer";
|
|
5
|
+
|
|
6
|
+
import { createBaseMutates } from "./mutates";
|
|
7
|
+
import { DEFAULT_BASE_STATE } from "./state";
|
|
8
|
+
import type { PolylineBaseState } from "./types";
|
|
9
|
+
|
|
10
|
+
describe("polylineBaseEnhancer/mutates", () => {
|
|
11
|
+
describe("RTE uniforms", () => {
|
|
12
|
+
it("should assign RTE refs to shader.uniforms when useRTE=true", () => {
|
|
13
|
+
const state: PolylineBaseState = { ...DEFAULT_BASE_STATE, useRTE: true };
|
|
14
|
+
const mutates = createBaseMutates(true);
|
|
15
|
+
mutates.update(state);
|
|
16
|
+
|
|
17
|
+
const uniforms: ShaderUniforms = {};
|
|
18
|
+
mutates.updateUniforms(uniforms, state);
|
|
19
|
+
|
|
20
|
+
expect(uniforms.modelViewMatrixRTE).toBeDefined();
|
|
21
|
+
expect(uniforms.u_cameraPositionHigh).toBeDefined();
|
|
22
|
+
expect(uniforms.u_cameraPositionLow).toBeDefined();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should not assign RTE refs to shader.uniforms when useRTE=false", () => {
|
|
26
|
+
const state: PolylineBaseState = { ...DEFAULT_BASE_STATE, useRTE: false };
|
|
27
|
+
const mutates = createBaseMutates(false);
|
|
28
|
+
mutates.update(state);
|
|
29
|
+
|
|
30
|
+
const uniforms: ShaderUniforms = {};
|
|
31
|
+
mutates.updateUniforms(uniforms, state);
|
|
32
|
+
|
|
33
|
+
expect(uniforms.modelViewMatrixRTE).toBeUndefined();
|
|
34
|
+
expect(uniforms.u_cameraPositionHigh).toBeUndefined();
|
|
35
|
+
expect(uniforms.u_cameraPositionLow).toBeUndefined();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe("update syncs refs from state", () => {
|
|
40
|
+
it("should sync core refs from state", () => {
|
|
41
|
+
const state: PolylineBaseState = {
|
|
42
|
+
...DEFAULT_BASE_STATE,
|
|
43
|
+
pickable: true,
|
|
44
|
+
minMaxHeight: [10, 100],
|
|
45
|
+
width: 3,
|
|
46
|
+
};
|
|
47
|
+
const mutates = createBaseMutates(false);
|
|
48
|
+
mutates.update(state);
|
|
49
|
+
|
|
50
|
+
const uniforms: ShaderUniforms = {};
|
|
51
|
+
mutates.updateUniforms(uniforms, state);
|
|
52
|
+
|
|
53
|
+
expect(uniforms.minMaxHeightAndWidth?.value).toEqual([10, 100, 3]);
|
|
54
|
+
expect(uniforms.nvr_uPickable?.value).toBe(1);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe("emissiveColor uniform passthrough", () => {
|
|
59
|
+
it("should pass emissiveColor=0 as vec3(0,0,0) — shader handles fallback", () => {
|
|
60
|
+
const state: PolylineBaseState = {
|
|
61
|
+
...DEFAULT_BASE_STATE,
|
|
62
|
+
color: 0xff9900,
|
|
63
|
+
emissiveColor: 0,
|
|
64
|
+
effectIdsMask: 1,
|
|
65
|
+
};
|
|
66
|
+
const mutates = createBaseMutates(false);
|
|
67
|
+
mutates.update(state);
|
|
68
|
+
|
|
69
|
+
const uniforms: ShaderUniforms = {};
|
|
70
|
+
mutates.updateUniforms(uniforms, state);
|
|
71
|
+
|
|
72
|
+
const vec = uniforms.uEmissiveColor as {
|
|
73
|
+
value: { x: number; y: number; z: number };
|
|
74
|
+
};
|
|
75
|
+
expect(vec.value.x).toBe(0);
|
|
76
|
+
expect(vec.value.y).toBe(0);
|
|
77
|
+
expect(vec.value.z).toBe(0);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("should pass explicit emissiveColor through to uniform", () => {
|
|
81
|
+
const state: PolylineBaseState = {
|
|
82
|
+
...DEFAULT_BASE_STATE,
|
|
83
|
+
color: 0xff9900,
|
|
84
|
+
emissiveColor: 0x0000ff,
|
|
85
|
+
effectIdsMask: 1,
|
|
86
|
+
};
|
|
87
|
+
const mutates = createBaseMutates(false);
|
|
88
|
+
mutates.update(state);
|
|
89
|
+
|
|
90
|
+
const uniforms: ShaderUniforms = {};
|
|
91
|
+
mutates.updateUniforms(uniforms, state);
|
|
92
|
+
|
|
93
|
+
const vec = uniforms.uEmissiveColor as {
|
|
94
|
+
value: { x: number; y: number; z: number };
|
|
95
|
+
};
|
|
96
|
+
// 0x0000ff → R=0.0, G=0.0, B=1.0
|
|
97
|
+
expect(vec.value.x).toBeCloseTo(0.0);
|
|
98
|
+
expect(vec.value.y).toBeCloseTo(0.0);
|
|
99
|
+
expect(vec.value.z).toBeCloseTo(1.0);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe("setPickingCoord", () => {
|
|
104
|
+
it("should update picking coordinate uniform", () => {
|
|
105
|
+
const state: PolylineBaseState = { ...DEFAULT_BASE_STATE };
|
|
106
|
+
const mutates = createBaseMutates(false);
|
|
107
|
+
|
|
108
|
+
const pickingCoord = new Vector2(100, 200);
|
|
109
|
+
mutates.update(state);
|
|
110
|
+
mutates.setPickingCoord(pickingCoord);
|
|
111
|
+
|
|
112
|
+
const uniforms: ShaderUniforms = {};
|
|
113
|
+
mutates.updateUniforms(uniforms, state);
|
|
114
|
+
|
|
115
|
+
const coord = uniforms.nvr_uPickingCoord as { value: Vector2 };
|
|
116
|
+
expect(coord.value.x).toBe(100);
|
|
117
|
+
expect(coord.value.y).toBe(200);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Color as ThreeColor,
|
|
3
|
+
Matrix4 as ThreeMatrix4,
|
|
4
|
+
Texture,
|
|
5
|
+
UniformsLib,
|
|
6
|
+
Vector2 as ThreeVector2,
|
|
7
|
+
Vector3 as ThreeVector3,
|
|
8
|
+
} from "three";
|
|
9
|
+
|
|
10
|
+
import type { UniformValue } from "../../../types";
|
|
11
|
+
|
|
12
|
+
import type {
|
|
13
|
+
PolylineBaseMutates,
|
|
14
|
+
PolylineBaseRefs,
|
|
15
|
+
PolylineBaseState,
|
|
16
|
+
} from "./types";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Default refs with initial values.
|
|
20
|
+
* These are cloned in createBaseMutates and synced from state via update().
|
|
21
|
+
*/
|
|
22
|
+
const DEFAULT_BASE_REFS: PolylineBaseRefs = {
|
|
23
|
+
minMaxHeightAndWidth: { value: [0, 0, 1] },
|
|
24
|
+
maxWidth: { value: 10000 },
|
|
25
|
+
uAddHeight: { value: 0 },
|
|
26
|
+
color: { value: new ThreeColor(0xffffff) },
|
|
27
|
+
nvr_uPickable: { value: 0 },
|
|
28
|
+
uEffectIdsMask: { value: 0 },
|
|
29
|
+
uEmissiveColor: { value: new ThreeVector3(0, 0, 0) },
|
|
30
|
+
uEmissiveIntensity: { value: 0 },
|
|
31
|
+
nvr_uPickingCoord: { value: new ThreeVector2(-1, -1) },
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Create mutation functions for the polyline base enhancer.
|
|
36
|
+
* Refs are created internally and captured via closure.
|
|
37
|
+
*
|
|
38
|
+
* @param useRTE - Whether RTE is enabled (determines if RTE refs are created)
|
|
39
|
+
*/
|
|
40
|
+
export const createBaseMutates = (useRTE: boolean): PolylineBaseMutates => {
|
|
41
|
+
// Clone defaults so each enhancer instance gets independent ref objects
|
|
42
|
+
const refs = structuredClone(DEFAULT_BASE_REFS) as PolylineBaseRefs;
|
|
43
|
+
|
|
44
|
+
// Restore Three.js objects (structuredClone creates plain objects for Three.js types)
|
|
45
|
+
refs.color.value = new ThreeColor(0xffffff);
|
|
46
|
+
refs.uEmissiveColor.value = new ThreeVector3(0, 0, 0);
|
|
47
|
+
refs.nvr_uPickingCoord.value = new ThreeVector2(-1, -1);
|
|
48
|
+
|
|
49
|
+
// Conditionally create RTE refs (useRTE can't change after mount)
|
|
50
|
+
if (useRTE) {
|
|
51
|
+
refs.modelViewMatrixRTE = { value: new ThreeMatrix4() };
|
|
52
|
+
refs.u_cameraPositionHigh = { value: new ThreeVector3() };
|
|
53
|
+
refs.u_cameraPositionLow = { value: new ThreeVector3() };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
update: (state) => {
|
|
58
|
+
// Sync refs from state
|
|
59
|
+
refs.minMaxHeightAndWidth.value = [
|
|
60
|
+
state.minMaxHeight[0],
|
|
61
|
+
state.minMaxHeight[1],
|
|
62
|
+
state.width,
|
|
63
|
+
];
|
|
64
|
+
refs.maxWidth.value = state.maxWidth;
|
|
65
|
+
refs.uAddHeight.value = state.addHeight;
|
|
66
|
+
refs.nvr_uPickable.value = state.pickable ? 1 : 0;
|
|
67
|
+
refs.uEffectIdsMask.value = state.effectIdsMask;
|
|
68
|
+
const c = state.emissiveColor;
|
|
69
|
+
refs.uEmissiveColor.value.set(
|
|
70
|
+
((c >> 16) & 0xff) / 255,
|
|
71
|
+
((c >> 8) & 0xff) / 255,
|
|
72
|
+
(c & 0xff) / 255,
|
|
73
|
+
);
|
|
74
|
+
refs.uEmissiveIntensity.value = state.emissiveIntensity;
|
|
75
|
+
|
|
76
|
+
// Update color uniform using Color.setHex()
|
|
77
|
+
refs.color.value.setHex(state.color);
|
|
78
|
+
},
|
|
79
|
+
updateUniforms: (uniforms, state) => {
|
|
80
|
+
// Include Three.js lighting uniforms
|
|
81
|
+
Object.assign(uniforms, UniformsLib["lights"]);
|
|
82
|
+
|
|
83
|
+
// Assign core uniform refs to shader.uniforms
|
|
84
|
+
uniforms.minMaxHeightAndWidth = refs.minMaxHeightAndWidth;
|
|
85
|
+
uniforms.maxWidth = refs.maxWidth;
|
|
86
|
+
uniforms.uAddHeight = refs.uAddHeight;
|
|
87
|
+
uniforms.color = refs.color;
|
|
88
|
+
uniforms.nvr_uPickable = refs.nvr_uPickable;
|
|
89
|
+
uniforms.uEffectIdsMask = refs.uEffectIdsMask;
|
|
90
|
+
uniforms.uEmissiveColor = refs.uEmissiveColor;
|
|
91
|
+
uniforms.uEmissiveIntensity = refs.uEmissiveIntensity;
|
|
92
|
+
uniforms.nvr_uPickingCoord = refs.nvr_uPickingCoord;
|
|
93
|
+
|
|
94
|
+
// RTE uniforms
|
|
95
|
+
if (
|
|
96
|
+
state.useRTE &&
|
|
97
|
+
refs.modelViewMatrixRTE &&
|
|
98
|
+
refs.u_cameraPositionHigh &&
|
|
99
|
+
refs.u_cameraPositionLow
|
|
100
|
+
) {
|
|
101
|
+
uniforms.u_cameraPositionHigh = refs.u_cameraPositionHigh;
|
|
102
|
+
uniforms.u_cameraPositionLow = refs.u_cameraPositionLow;
|
|
103
|
+
uniforms.modelViewMatrixRTE = refs.modelViewMatrixRTE;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Batch texture
|
|
107
|
+
if (refs.batchDataTexture) {
|
|
108
|
+
uniforms.batchDataTexture = refs.batchDataTexture;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// External shared uniforms
|
|
112
|
+
if (refs.viewportAndPixelRatio) {
|
|
113
|
+
uniforms.viewportAndPixelRatio = refs.viewportAndPixelRatio;
|
|
114
|
+
}
|
|
115
|
+
if (refs.frustumNearFar) {
|
|
116
|
+
uniforms.frustumNearFar = refs.frustumNearFar;
|
|
117
|
+
}
|
|
118
|
+
if (refs.frustumRatio) {
|
|
119
|
+
uniforms.frustumRatio = refs.frustumRatio;
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
setBatchDataTexture: (texture: UniformValue<Texture | null>): void => {
|
|
123
|
+
refs.batchDataTexture = texture;
|
|
124
|
+
},
|
|
125
|
+
setPickingCoord: (coord: ThreeVector2): void => {
|
|
126
|
+
refs.nvr_uPickingCoord.value.copy(coord);
|
|
127
|
+
},
|
|
128
|
+
setExternalRefs: (externalRefs: {
|
|
129
|
+
batchDataTexture?: UniformValue<Texture | null>;
|
|
130
|
+
viewportAndPixelRatio?: {
|
|
131
|
+
value: [x: number, y: number, z: number] | undefined | null;
|
|
132
|
+
};
|
|
133
|
+
frustumNearFar?: { value: [x: number, y: number] | undefined | null };
|
|
134
|
+
frustumRatio?: {
|
|
135
|
+
value: [x: number, y: number, z: number, w: number] | undefined | null;
|
|
136
|
+
};
|
|
137
|
+
}): void => {
|
|
138
|
+
if (externalRefs.batchDataTexture) {
|
|
139
|
+
refs.batchDataTexture = externalRefs.batchDataTexture;
|
|
140
|
+
}
|
|
141
|
+
if (externalRefs.viewportAndPixelRatio) {
|
|
142
|
+
refs.viewportAndPixelRatio = externalRefs.viewportAndPixelRatio;
|
|
143
|
+
}
|
|
144
|
+
if (externalRefs.frustumNearFar) {
|
|
145
|
+
refs.frustumNearFar = externalRefs.frustumNearFar;
|
|
146
|
+
}
|
|
147
|
+
if (externalRefs.frustumRatio) {
|
|
148
|
+
refs.frustumRatio = externalRefs.frustumRatio;
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
updateRteUniforms: (
|
|
152
|
+
modelViewMatrixRTE: ThreeMatrix4,
|
|
153
|
+
cameraPositionHigh: ThreeVector3,
|
|
154
|
+
cameraPositionLow: ThreeVector3,
|
|
155
|
+
state: PolylineBaseState,
|
|
156
|
+
): void => {
|
|
157
|
+
if (!state.useRTE) return;
|
|
158
|
+
if (refs.modelViewMatrixRTE) {
|
|
159
|
+
refs.modelViewMatrixRTE.value.copy(modelViewMatrixRTE);
|
|
160
|
+
}
|
|
161
|
+
if (refs.u_cameraPositionHigh) {
|
|
162
|
+
refs.u_cameraPositionHigh.value.copy(cameraPositionHigh);
|
|
163
|
+
}
|
|
164
|
+
if (refs.u_cameraPositionLow) {
|
|
165
|
+
refs.u_cameraPositionLow.value.copy(cameraPositionLow);
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
};
|