@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,82 @@
|
|
|
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 { createPntsMutates } from "./mutates";
|
|
10
|
+
import { transformShader } from "./shader";
|
|
11
|
+
import { DEFAULT_PNTS_PROPS, DEFAULT_PNTS_STATE, updateState } from "./state";
|
|
12
|
+
import type { PntsMutates, PntsProps, PntsState } from "./types";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Factory function to create a PNTS (point cloud) material enhancer.
|
|
16
|
+
*
|
|
17
|
+
* This enhancer handles:
|
|
18
|
+
* - Point size
|
|
19
|
+
* - Color
|
|
20
|
+
* - Height offset via geodetic normal
|
|
21
|
+
* - PNTS color range normalization (1/65535)
|
|
22
|
+
*
|
|
23
|
+
* @param material - The Three.js PointsMaterial to enhance
|
|
24
|
+
*/
|
|
25
|
+
export function createPntsEnhancer(
|
|
26
|
+
material: SupportedMaterial,
|
|
27
|
+
): MaterialEnhancer<
|
|
28
|
+
SupportedMaterial,
|
|
29
|
+
PntsProps,
|
|
30
|
+
PntsState,
|
|
31
|
+
PntsMutates,
|
|
32
|
+
typeof AVAILABLE_SHADERS
|
|
33
|
+
> {
|
|
34
|
+
let state: PntsState | null = null;
|
|
35
|
+
let mutates: PntsMutates | null = null;
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
material,
|
|
39
|
+
availableShaders: AVAILABLE_SHADERS,
|
|
40
|
+
|
|
41
|
+
transformShader: (shader: WebGLProgramParametersWithUniforms): void => {
|
|
42
|
+
invariant(
|
|
43
|
+
state && mutates,
|
|
44
|
+
"mount() must be called before transformShader",
|
|
45
|
+
);
|
|
46
|
+
transformShader(shader, state, mutates);
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
mount: (props: PntsProps): void => {
|
|
50
|
+
const mergedProps = defaults({}, props, DEFAULT_PNTS_PROPS);
|
|
51
|
+
state = updateState(mergedProps, DEFAULT_PNTS_STATE);
|
|
52
|
+
mutates = createPntsMutates();
|
|
53
|
+
mutates.update(state);
|
|
54
|
+
updateMaterialProps(material, mergedProps);
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
update: (props: PntsProps): void => {
|
|
58
|
+
invariant(state && mutates, "mount() must be called before update");
|
|
59
|
+
state = updateState(props, state);
|
|
60
|
+
mutates.update(state);
|
|
61
|
+
updateMaterialProps(material, props);
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
states: (): PntsState => {
|
|
65
|
+
invariant(state, "mount() must be called before states");
|
|
66
|
+
return state;
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
mutates: (): PntsMutates => {
|
|
70
|
+
invariant(mutates, "mount() must be called before mutates");
|
|
71
|
+
return mutates;
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
programCacheKey: (): string => {
|
|
75
|
+
// PNTS has no state that affects shader defines
|
|
76
|
+
return "";
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type { PntsMutates, PntsProps, PntsState };
|
|
82
|
+
export type { SupportedMaterial } from "./material";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { PointsMaterial } from "three";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
|
|
4
|
+
import { updateMaterialProps } from "./material";
|
|
5
|
+
|
|
6
|
+
describe("pntsEnhancer/material", () => {
|
|
7
|
+
describe("updateMaterialProps", () => {
|
|
8
|
+
it("should not update properties when props are undefined", () => {
|
|
9
|
+
const material = new PointsMaterial();
|
|
10
|
+
material.color.set(0xff0000);
|
|
11
|
+
material.size = 5;
|
|
12
|
+
|
|
13
|
+
updateMaterialProps(material, {});
|
|
14
|
+
expect(material.color.getHex()).toBe(0xff0000);
|
|
15
|
+
expect(material.size).toBe(5);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("should update color when provided", () => {
|
|
19
|
+
const material = new PointsMaterial();
|
|
20
|
+
updateMaterialProps(material, { color: 0x00ff00 });
|
|
21
|
+
expect(material.color.getHex()).toBe(0x00ff00);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("should update pointSize when provided", () => {
|
|
25
|
+
const material = new PointsMaterial();
|
|
26
|
+
updateMaterialProps(material, { pointSize: 3 });
|
|
27
|
+
expect(material.size).toBe(3);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should update both color and pointSize when provided", () => {
|
|
31
|
+
const material = new PointsMaterial();
|
|
32
|
+
updateMaterialProps(material, { color: 0x0000ff, pointSize: 7 });
|
|
33
|
+
expect(material.color.getHex()).toBe(0x0000ff);
|
|
34
|
+
expect(material.size).toBe(7);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { MaterialsFromShaders, ShaderName } from "../../MaterialEnhancer";
|
|
2
|
+
|
|
3
|
+
import type { PntsProps } from "./types";
|
|
4
|
+
|
|
5
|
+
export const AVAILABLE_SHADERS = ["points"] satisfies ShaderName[];
|
|
6
|
+
export type SupportedMaterial = MaterialsFromShaders<typeof AVAILABLE_SHADERS>;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Update Three.js PointsMaterial properties from props.
|
|
10
|
+
*/
|
|
11
|
+
export const updateMaterialProps = (
|
|
12
|
+
material: SupportedMaterial,
|
|
13
|
+
props: PntsProps,
|
|
14
|
+
): void => {
|
|
15
|
+
if (props.color !== undefined) {
|
|
16
|
+
material.color.set(props.color);
|
|
17
|
+
}
|
|
18
|
+
if (props.pointSize !== undefined) {
|
|
19
|
+
material.size = props.pointSize;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import type { ShaderUniforms } from "../../MaterialEnhancer";
|
|
4
|
+
|
|
5
|
+
import { createPntsMutates } from "./mutates";
|
|
6
|
+
import { DEFAULT_PNTS_STATE } from "./state";
|
|
7
|
+
import type { PntsState } from "./types";
|
|
8
|
+
|
|
9
|
+
describe("pntsEnhancer/mutates", () => {
|
|
10
|
+
describe("update syncs refs from state", () => {
|
|
11
|
+
it("should sync uAddHeight from state.height", () => {
|
|
12
|
+
const state: PntsState = { ...DEFAULT_PNTS_STATE, height: 100 };
|
|
13
|
+
const mutates = createPntsMutates();
|
|
14
|
+
mutates.update(state);
|
|
15
|
+
|
|
16
|
+
const uniforms: ShaderUniforms = {};
|
|
17
|
+
mutates.updateUniforms(uniforms, state);
|
|
18
|
+
|
|
19
|
+
expect(uniforms.uAddHeight?.value).toBe(100);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should sync uGeodeticNormal from state.geodeticNormal", () => {
|
|
23
|
+
const state: PntsState = {
|
|
24
|
+
...DEFAULT_PNTS_STATE,
|
|
25
|
+
geodeticNormal: { x: 0.1, y: 0.2, z: 0.3 },
|
|
26
|
+
};
|
|
27
|
+
const mutates = createPntsMutates();
|
|
28
|
+
mutates.update(state);
|
|
29
|
+
|
|
30
|
+
const uniforms: ShaderUniforms = {};
|
|
31
|
+
mutates.updateUniforms(uniforms, state);
|
|
32
|
+
|
|
33
|
+
expect(uniforms.uGeodeticNormal?.value).toEqual([0.1, 0.2, 0.3]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should default to zero values", () => {
|
|
37
|
+
const mutates = createPntsMutates();
|
|
38
|
+
mutates.update(DEFAULT_PNTS_STATE);
|
|
39
|
+
|
|
40
|
+
const uniforms: ShaderUniforms = {};
|
|
41
|
+
mutates.updateUniforms(uniforms, DEFAULT_PNTS_STATE);
|
|
42
|
+
|
|
43
|
+
expect(uniforms.uAddHeight?.value).toBe(0);
|
|
44
|
+
expect(uniforms.uGeodeticNormal?.value).toEqual([0, 0, 0]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("should update refs when state changes", () => {
|
|
48
|
+
const mutates = createPntsMutates();
|
|
49
|
+
|
|
50
|
+
const state1: PntsState = { ...DEFAULT_PNTS_STATE, height: 50 };
|
|
51
|
+
mutates.update(state1);
|
|
52
|
+
|
|
53
|
+
const uniforms: ShaderUniforms = {};
|
|
54
|
+
mutates.updateUniforms(uniforms, state1);
|
|
55
|
+
expect(uniforms.uAddHeight?.value).toBe(50);
|
|
56
|
+
|
|
57
|
+
const state2: PntsState = { ...DEFAULT_PNTS_STATE, height: 200 };
|
|
58
|
+
mutates.update(state2);
|
|
59
|
+
// Ref should be updated in place
|
|
60
|
+
expect(uniforms.uAddHeight?.value).toBe(200);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe("updateUniforms assigns refs", () => {
|
|
65
|
+
it("should assign ref objects (not copies) to uniforms", () => {
|
|
66
|
+
const mutates = createPntsMutates();
|
|
67
|
+
mutates.update(DEFAULT_PNTS_STATE);
|
|
68
|
+
|
|
69
|
+
const uniforms: ShaderUniforms = {};
|
|
70
|
+
mutates.updateUniforms(uniforms, DEFAULT_PNTS_STATE);
|
|
71
|
+
|
|
72
|
+
const heightRef = uniforms.uAddHeight;
|
|
73
|
+
expect(heightRef).toBeDefined();
|
|
74
|
+
|
|
75
|
+
// Update state and verify the same ref object is updated
|
|
76
|
+
mutates.update({ ...DEFAULT_PNTS_STATE, height: 999 });
|
|
77
|
+
expect(heightRef?.value).toBe(999);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { PntsMutates, PntsRefs } from "./types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Default refs with initial values.
|
|
5
|
+
*/
|
|
6
|
+
const DEFAULT_PNTS_REFS: PntsRefs = {
|
|
7
|
+
uAddHeight: { value: 0 },
|
|
8
|
+
uGeodeticNormal: { value: [0, 0, 0] },
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Create mutation functions for the PNTS enhancer.
|
|
13
|
+
* Refs are created internally and captured via closure.
|
|
14
|
+
*/
|
|
15
|
+
export const createPntsMutates = (): PntsMutates => {
|
|
16
|
+
const refs = structuredClone(DEFAULT_PNTS_REFS) as PntsRefs;
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
update: (state) => {
|
|
20
|
+
refs.uAddHeight.value = state.height;
|
|
21
|
+
const n = state.geodeticNormal;
|
|
22
|
+
refs.uGeodeticNormal.value = [n.x, n.y, n.z];
|
|
23
|
+
},
|
|
24
|
+
updateUniforms: (uniforms) => {
|
|
25
|
+
uniforms.uAddHeight = refs.uAddHeight;
|
|
26
|
+
uniforms.uGeodeticNormal = refs.uGeodeticNormal;
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { testShaderCompatibility } from "../../test-utils/shaderCompatibility";
|
|
2
|
+
|
|
3
|
+
import { PNTS_SHADER_MARKERS } from "./markers";
|
|
4
|
+
|
|
5
|
+
import { createPntsEnhancer, type SupportedMaterial } from ".";
|
|
6
|
+
|
|
7
|
+
testShaderCompatibility(
|
|
8
|
+
"pntsEnhancer",
|
|
9
|
+
(material) => createPntsEnhancer(material as SupportedMaterial),
|
|
10
|
+
[
|
|
11
|
+
{
|
|
12
|
+
name: "Default props",
|
|
13
|
+
props: {},
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: "With all props",
|
|
17
|
+
props: {
|
|
18
|
+
color: 0xff0000,
|
|
19
|
+
pointSize: 5,
|
|
20
|
+
height: 100,
|
|
21
|
+
geodeticNormal: { x: 0.1, y: 0.2, z: 0.97 },
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "With divideColor",
|
|
26
|
+
props: {
|
|
27
|
+
divideColor: true,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
PNTS_SHADER_MARKERS,
|
|
32
|
+
);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { WebGLProgramParametersWithUniforms } from "three";
|
|
2
|
+
import { ShaderChunk } from "three";
|
|
3
|
+
|
|
4
|
+
import { createReplacer } from "../../../../utils";
|
|
5
|
+
|
|
6
|
+
import type { PntsMutates, PntsState } from "./types";
|
|
7
|
+
|
|
8
|
+
const COLOR_DIVISOR = 65535.0;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Transform shader with PNTS-specific modifications.
|
|
12
|
+
*
|
|
13
|
+
* Vertex shader changes:
|
|
14
|
+
* - Adds uAddHeight and uGeodeticNormal uniforms
|
|
15
|
+
* - When `divideColor` is `true`, scales vertex colors by 1/65535 (PNTS color range normalization)
|
|
16
|
+
* - Offsets vertex position along geodetic normal by uAddHeight
|
|
17
|
+
*/
|
|
18
|
+
export const transformShader = (
|
|
19
|
+
shader: WebGLProgramParametersWithUniforms,
|
|
20
|
+
state: PntsState,
|
|
21
|
+
mutates: PntsMutates,
|
|
22
|
+
): void => {
|
|
23
|
+
shader.defines ??= {};
|
|
24
|
+
|
|
25
|
+
mutates.updateUniforms(shader.uniforms, state);
|
|
26
|
+
|
|
27
|
+
shader.vertexShader = createReplacer(shader.vertexShader)
|
|
28
|
+
.replaceWithCondition(
|
|
29
|
+
"#include <color_vertex>",
|
|
30
|
+
createReplacer(ShaderChunk.color_vertex).replace(
|
|
31
|
+
"vColor = vec4( 1.0 );",
|
|
32
|
+
`vColor = vec4( 1.0 / ${COLOR_DIVISOR}.0 );`,
|
|
33
|
+
).source,
|
|
34
|
+
state.divideColor,
|
|
35
|
+
)
|
|
36
|
+
.replace(
|
|
37
|
+
"#include <common>",
|
|
38
|
+
`#include <common>
|
|
39
|
+
uniform float uAddHeight;
|
|
40
|
+
uniform vec3 uGeodeticNormal;`,
|
|
41
|
+
)
|
|
42
|
+
.replace(
|
|
43
|
+
"#include <project_vertex>",
|
|
44
|
+
createReplacer(ShaderChunk.project_vertex)
|
|
45
|
+
.replace(
|
|
46
|
+
"vec4 mvPosition = vec4( transformed, 1.0 );",
|
|
47
|
+
`vec4 mvPosition = vec4( transformed, 1.0 );
|
|
48
|
+
vec4 mvNormal = viewMatrix * vec4(uGeodeticNormal, 0.0);`,
|
|
49
|
+
)
|
|
50
|
+
.replace(
|
|
51
|
+
"gl_Position = projectionMatrix * mvPosition;",
|
|
52
|
+
`mvPosition += mvNormal * uAddHeight;
|
|
53
|
+
gl_Position = projectionMatrix * mvPosition;`,
|
|
54
|
+
).source,
|
|
55
|
+
).source;
|
|
56
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { DEFAULT_PNTS_STATE, updateState } from "./state";
|
|
4
|
+
import type { PntsProps, PntsState } from "./types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Helper to create expected state by merging with defaults.
|
|
8
|
+
*/
|
|
9
|
+
const createExpectedState = (
|
|
10
|
+
overrides: Partial<PntsState> = {},
|
|
11
|
+
): PntsState => ({
|
|
12
|
+
...DEFAULT_PNTS_STATE,
|
|
13
|
+
...overrides,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe("pntsEnhancer/state", () => {
|
|
17
|
+
describe("updateState", () => {
|
|
18
|
+
type TestCase = {
|
|
19
|
+
name: string;
|
|
20
|
+
props: PntsProps;
|
|
21
|
+
currentState: PntsState;
|
|
22
|
+
expected: PntsState;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const testCases: TestCase[] = [
|
|
26
|
+
{
|
|
27
|
+
name: "returns default state when given empty props",
|
|
28
|
+
props: {},
|
|
29
|
+
currentState: DEFAULT_PNTS_STATE,
|
|
30
|
+
expected: createExpectedState(),
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "applies height only",
|
|
34
|
+
props: { height: 100 },
|
|
35
|
+
currentState: DEFAULT_PNTS_STATE,
|
|
36
|
+
expected: createExpectedState({ height: 100 }),
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "applies geodeticNormal only",
|
|
40
|
+
props: { geodeticNormal: { x: 0.5, y: 0.5, z: 0.707 } },
|
|
41
|
+
currentState: DEFAULT_PNTS_STATE,
|
|
42
|
+
expected: createExpectedState({
|
|
43
|
+
geodeticNormal: { x: 0.5, y: 0.5, z: 0.707 },
|
|
44
|
+
}),
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "applies all state props",
|
|
48
|
+
props: {
|
|
49
|
+
height: 200,
|
|
50
|
+
geodeticNormal: { x: 1, y: 0, z: 0 },
|
|
51
|
+
},
|
|
52
|
+
currentState: DEFAULT_PNTS_STATE,
|
|
53
|
+
expected: createExpectedState({
|
|
54
|
+
height: 200,
|
|
55
|
+
geodeticNormal: { x: 1, y: 0, z: 0 },
|
|
56
|
+
}),
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
it.each(testCases)("$name", ({ props, currentState, expected }) => {
|
|
61
|
+
const result = updateState(props, currentState);
|
|
62
|
+
expect(result).toEqual(expected);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("falls back to currentState for missing props", () => {
|
|
66
|
+
const currentState: PntsState = {
|
|
67
|
+
height: 150,
|
|
68
|
+
geodeticNormal: { x: 0.1, y: 0.2, z: 0.3 },
|
|
69
|
+
divideColor: false,
|
|
70
|
+
};
|
|
71
|
+
const result = updateState({}, currentState);
|
|
72
|
+
expect(result.height).toBe(150);
|
|
73
|
+
expect(result.geodeticNormal).toEqual({ x: 0.1, y: 0.2, z: 0.3 });
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("overrides only specified props", () => {
|
|
77
|
+
const currentState: PntsState = {
|
|
78
|
+
height: 150,
|
|
79
|
+
geodeticNormal: { x: 0.1, y: 0.2, z: 0.3 },
|
|
80
|
+
divideColor: false,
|
|
81
|
+
};
|
|
82
|
+
const result = updateState({ height: 300 }, currentState);
|
|
83
|
+
expect(result.height).toBe(300);
|
|
84
|
+
expect(result.geodeticNormal).toEqual({ x: 0.1, y: 0.2, z: 0.3 });
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { PntsProps, PntsState } from "./types";
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_PNTS_PROPS: Required<PntsProps> = {
|
|
4
|
+
color: 0,
|
|
5
|
+
pointSize: 1,
|
|
6
|
+
height: 0,
|
|
7
|
+
geodeticNormal: { x: 0, y: 0, z: 0 },
|
|
8
|
+
divideColor: false,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/** Default state derived from DEFAULT_PNTS_PROPS. */
|
|
12
|
+
export const DEFAULT_PNTS_STATE: PntsState = {
|
|
13
|
+
height: DEFAULT_PNTS_PROPS.height,
|
|
14
|
+
geodeticNormal: DEFAULT_PNTS_PROPS.geodeticNormal,
|
|
15
|
+
divideColor: false,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Update immutable state from props.
|
|
20
|
+
* Props override currentState values; missing props fall back to currentState.
|
|
21
|
+
*/
|
|
22
|
+
export const updateState = (
|
|
23
|
+
props: PntsProps,
|
|
24
|
+
currentState: PntsState,
|
|
25
|
+
): PntsState => ({
|
|
26
|
+
height: props.height ?? currentState.height,
|
|
27
|
+
geodeticNormal: props.geodeticNormal ?? currentState.geodeticNormal,
|
|
28
|
+
divideColor: !!props.divideColor,
|
|
29
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { UniformValue } from "../../../types";
|
|
2
|
+
import type { Mutates } from "../../MaterialEnhancer";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Props for the PNTS (point cloud) enhancer.
|
|
6
|
+
*/
|
|
7
|
+
export type PntsProps = {
|
|
8
|
+
color?: number;
|
|
9
|
+
pointSize?: number;
|
|
10
|
+
height?: number;
|
|
11
|
+
divideColor?: boolean;
|
|
12
|
+
geodeticNormal?: { x: number; y: number; z: number };
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Immutable state for the PNTS enhancer.
|
|
17
|
+
*/
|
|
18
|
+
export type PntsState = Readonly<{
|
|
19
|
+
height: number;
|
|
20
|
+
geodeticNormal: { x: number; y: number; z: number };
|
|
21
|
+
divideColor: boolean;
|
|
22
|
+
}>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Mutable references (uniforms) for the PNTS enhancer.
|
|
26
|
+
* Internal type - not exposed externally.
|
|
27
|
+
*/
|
|
28
|
+
export type PntsRefs = {
|
|
29
|
+
uAddHeight: UniformValue<number>;
|
|
30
|
+
uGeodeticNormal: UniformValue<number[]>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type PntsUniforms = Partial<PntsRefs>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Mutation functions for the PNTS enhancer.
|
|
37
|
+
*/
|
|
38
|
+
export type PntsMutates = Mutates<PntsState, PntsUniforms>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { createPolygonBaseEnhancer } from "./polygonBaseEnhancer";
|
|
2
|
+
export {
|
|
3
|
+
POLYGON_BASE_SHADER_MARKERS,
|
|
4
|
+
createPolygonBaseShaderReplacer,
|
|
5
|
+
} from "./polygonBaseEnhancer";
|
|
6
|
+
export type {
|
|
7
|
+
PolygonBaseMutates,
|
|
8
|
+
PolygonBaseProps,
|
|
9
|
+
PolygonBaseState,
|
|
10
|
+
} from "./polygonBaseEnhancer";
|
|
11
|
+
|
|
12
|
+
export { createPolygonWaterEnhancer } from "./polygonWaterEnhancer";
|
|
13
|
+
export type {
|
|
14
|
+
PolygonWaterCombinedMutates,
|
|
15
|
+
PolygonWaterCombinedStates,
|
|
16
|
+
PolygonWaterProps,
|
|
17
|
+
PolygonWaterState,
|
|
18
|
+
WaterOnlyProps,
|
|
19
|
+
} from "./polygonWaterEnhancer";
|
|
20
|
+
|
|
21
|
+
export { createPolygonMaterialEnhancer } from "./polygonMaterialEnhancer";
|
|
22
|
+
export type { PolygonMaterialProps } from "./polygonMaterialEnhancer";
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { MeshLambertMaterial } from "three";
|
|
2
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
3
|
+
|
|
4
|
+
import { createPolygonBaseEnhancer } from ".";
|
|
5
|
+
|
|
6
|
+
describe("polygonBaseEnhancer", () => {
|
|
7
|
+
let enhancer: ReturnType<typeof createPolygonBaseEnhancer>;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
enhancer = createPolygonBaseEnhancer(new MeshLambertMaterial());
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
describe("lifecycle", () => {
|
|
14
|
+
it("states() should throw if called before mount", () => {
|
|
15
|
+
const freshEnhancer = createPolygonBaseEnhancer(
|
|
16
|
+
new MeshLambertMaterial(),
|
|
17
|
+
);
|
|
18
|
+
expect(() => freshEnhancer.states()).toThrow(
|
|
19
|
+
"mount() must be called before states",
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("mutates() should throw if called before mount", () => {
|
|
24
|
+
const freshEnhancer = createPolygonBaseEnhancer(
|
|
25
|
+
new MeshLambertMaterial(),
|
|
26
|
+
);
|
|
27
|
+
expect(() => freshEnhancer.mutates()).toThrow(
|
|
28
|
+
"mount() must be called before mutates",
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("update() should throw if called before mount", () => {
|
|
33
|
+
const freshEnhancer = createPolygonBaseEnhancer(
|
|
34
|
+
new MeshLambertMaterial(),
|
|
35
|
+
);
|
|
36
|
+
expect(() => freshEnhancer.update({})).toThrow(
|
|
37
|
+
"mount() must be called before update",
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe("programCacheKey", () => {
|
|
43
|
+
it("should return cache key based on shader-affecting state", () => {
|
|
44
|
+
enhancer.mount({
|
|
45
|
+
useBatchTexture: true,
|
|
46
|
+
useBatchColorShow: false,
|
|
47
|
+
useBatchHeight: true,
|
|
48
|
+
useBatchExtrudedHeight: false,
|
|
49
|
+
isTexturized: true,
|
|
50
|
+
clampToGround: false,
|
|
51
|
+
useRTE: true,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const cacheKey = enhancer.programCacheKey();
|
|
55
|
+
const parsed = JSON.parse(cacheKey);
|
|
56
|
+
|
|
57
|
+
expect(parsed).toEqual({
|
|
58
|
+
useBatchTexture: true,
|
|
59
|
+
useBatchColorShow: false,
|
|
60
|
+
useBatchHeight: true,
|
|
61
|
+
useBatchExtrudedHeight: false,
|
|
62
|
+
isTexturized: true,
|
|
63
|
+
clampToGround: false,
|
|
64
|
+
useRTE: true,
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("should return different cache keys when useRTE differs", () => {
|
|
69
|
+
enhancer.mount({ useRTE: false });
|
|
70
|
+
const cacheKey1 = enhancer.programCacheKey();
|
|
71
|
+
|
|
72
|
+
const enhancer2 = createPolygonBaseEnhancer(new MeshLambertMaterial());
|
|
73
|
+
enhancer2.mount({ useRTE: true });
|
|
74
|
+
const cacheKey2 = enhancer2.programCacheKey();
|
|
75
|
+
|
|
76
|
+
expect(cacheKey1).not.toBe(cacheKey2);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("should return different cache keys for different shader-affecting states", () => {
|
|
80
|
+
enhancer.mount({ useBatchTexture: false });
|
|
81
|
+
const cacheKey1 = enhancer.programCacheKey();
|
|
82
|
+
|
|
83
|
+
const enhancer2 = createPolygonBaseEnhancer(new MeshLambertMaterial());
|
|
84
|
+
enhancer2.mount({ useBatchTexture: true });
|
|
85
|
+
const cacheKey2 = enhancer2.programCacheKey();
|
|
86
|
+
|
|
87
|
+
expect(cacheKey1).not.toBe(cacheKey2);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("should return same cache key for same shader-affecting states with different non-affecting states", () => {
|
|
91
|
+
enhancer.mount({ useBatchTexture: true, addHeight: 10, opacity: 0.5 });
|
|
92
|
+
const cacheKey1 = enhancer.programCacheKey();
|
|
93
|
+
|
|
94
|
+
const enhancer2 = createPolygonBaseEnhancer(new MeshLambertMaterial());
|
|
95
|
+
enhancer2.mount({ useBatchTexture: true, addHeight: 100, opacity: 1.0 });
|
|
96
|
+
const cacheKey2 = enhancer2.programCacheKey();
|
|
97
|
+
|
|
98
|
+
expect(cacheKey1).toBe(cacheKey2);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|