@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,102 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { DEFAULT_BASE_STATE, updateState } from "./state";
|
|
4
|
+
import type { PolygonBaseProps, PolygonBaseState } from "./types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Helper to create expected base state by merging with defaults.
|
|
8
|
+
*/
|
|
9
|
+
const createExpectedState = (
|
|
10
|
+
overrides: Partial<PolygonBaseState> = {},
|
|
11
|
+
): PolygonBaseState => ({
|
|
12
|
+
...DEFAULT_BASE_STATE,
|
|
13
|
+
...overrides,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe("polygonBaseEnhancer/state", () => {
|
|
17
|
+
describe("updateState", () => {
|
|
18
|
+
type TestCase = {
|
|
19
|
+
name: string;
|
|
20
|
+
props: PolygonBaseProps;
|
|
21
|
+
currentState: PolygonBaseState;
|
|
22
|
+
expected: PolygonBaseState;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const testCases: TestCase[] = [
|
|
26
|
+
{
|
|
27
|
+
name: "returns default state when given empty props",
|
|
28
|
+
props: {},
|
|
29
|
+
currentState: DEFAULT_BASE_STATE,
|
|
30
|
+
expected: createExpectedState(),
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "applies all props",
|
|
34
|
+
props: {
|
|
35
|
+
useRTE: true, // ignored - useRTE preserves currentState
|
|
36
|
+
isTexturized: true,
|
|
37
|
+
clampToGround: true,
|
|
38
|
+
pickable: true,
|
|
39
|
+
minMaxHeight: [10, 100],
|
|
40
|
+
addExtrudedHeight: 50,
|
|
41
|
+
addHeight: 20,
|
|
42
|
+
reflectivity: 0.5,
|
|
43
|
+
roughness: 0.3,
|
|
44
|
+
},
|
|
45
|
+
currentState: DEFAULT_BASE_STATE,
|
|
46
|
+
expected: createExpectedState({
|
|
47
|
+
// useRTE stays false because updateState preserves currentState.useRTE
|
|
48
|
+
isTexturized: true,
|
|
49
|
+
clampToGround: true,
|
|
50
|
+
pickable: true,
|
|
51
|
+
minMaxHeight: [10, 100],
|
|
52
|
+
addExtrudedHeight: 50,
|
|
53
|
+
addHeight: 20,
|
|
54
|
+
reflectivity: 0.5,
|
|
55
|
+
roughness: 0.3,
|
|
56
|
+
}),
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: "applies height props only",
|
|
60
|
+
props: {
|
|
61
|
+
minMaxHeight: [0, 50],
|
|
62
|
+
addExtrudedHeight: 25,
|
|
63
|
+
addHeight: 10,
|
|
64
|
+
},
|
|
65
|
+
currentState: DEFAULT_BASE_STATE,
|
|
66
|
+
expected: createExpectedState({
|
|
67
|
+
minMaxHeight: [0, 50],
|
|
68
|
+
addExtrudedHeight: 25,
|
|
69
|
+
addHeight: 10,
|
|
70
|
+
}),
|
|
71
|
+
},
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
it.each(testCases)("$name", ({ props, currentState, expected }) => {
|
|
75
|
+
const result = updateState(props, currentState);
|
|
76
|
+
expect(result).toEqual(expected);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("preserves useRTE from currentState (immutable after mount)", () => {
|
|
80
|
+
const stateWithRTE: PolygonBaseState = {
|
|
81
|
+
...DEFAULT_BASE_STATE,
|
|
82
|
+
useRTE: true,
|
|
83
|
+
};
|
|
84
|
+
const result = updateState({ useRTE: false }, stateWithRTE);
|
|
85
|
+
expect(result.useRTE).toBe(true);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("falls back to currentState for missing props", () => {
|
|
89
|
+
const currentState: PolygonBaseState = {
|
|
90
|
+
...DEFAULT_BASE_STATE,
|
|
91
|
+
clampToGround: true,
|
|
92
|
+
pickable: true,
|
|
93
|
+
addHeight: 42,
|
|
94
|
+
};
|
|
95
|
+
const result = updateState({ addExtrudedHeight: 10 }, currentState);
|
|
96
|
+
expect(result.clampToGround).toBe(true);
|
|
97
|
+
expect(result.pickable).toBe(true);
|
|
98
|
+
expect(result.addHeight).toBe(42);
|
|
99
|
+
expect(result.addExtrudedHeight).toBe(10);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { PolygonBaseProps, PolygonBaseState } from "./types";
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_BASE_PROPS: Required<
|
|
4
|
+
Omit<
|
|
5
|
+
PolygonBaseProps,
|
|
6
|
+
"globeNormalTexture" | "batchDataTexture" | "minMaxHeight"
|
|
7
|
+
>
|
|
8
|
+
> = {
|
|
9
|
+
color: 0,
|
|
10
|
+
opacity: 1,
|
|
11
|
+
transparent: false,
|
|
12
|
+
wireframe: false,
|
|
13
|
+
addExtrudedHeight: 0,
|
|
14
|
+
addHeight: 0,
|
|
15
|
+
clampToGround: false,
|
|
16
|
+
isTexturized: false,
|
|
17
|
+
pickable: false,
|
|
18
|
+
effectIdsMask: 0,
|
|
19
|
+
reflectivity: 0,
|
|
20
|
+
roughness: 0,
|
|
21
|
+
emissiveColor: 0,
|
|
22
|
+
emissiveIntensity: 0,
|
|
23
|
+
useRTE: false,
|
|
24
|
+
batchColorEnabled: false,
|
|
25
|
+
useBatchTexture: false,
|
|
26
|
+
useBatchColorShow: false,
|
|
27
|
+
useBatchHeight: false,
|
|
28
|
+
useBatchExtrudedHeight: false,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** Default state derived from DEFAULT_BASE_PROPS */
|
|
32
|
+
export const DEFAULT_BASE_STATE: PolygonBaseState = {
|
|
33
|
+
useRTE: DEFAULT_BASE_PROPS.useRTE,
|
|
34
|
+
isTexturized: DEFAULT_BASE_PROPS.isTexturized,
|
|
35
|
+
clampToGround: DEFAULT_BASE_PROPS.clampToGround,
|
|
36
|
+
pickable: DEFAULT_BASE_PROPS.pickable,
|
|
37
|
+
emissiveColor: DEFAULT_BASE_PROPS.emissiveColor,
|
|
38
|
+
emissiveIntensity: DEFAULT_BASE_PROPS.emissiveIntensity,
|
|
39
|
+
effectIdsMask: 0,
|
|
40
|
+
minMaxHeight: undefined,
|
|
41
|
+
addExtrudedHeight: DEFAULT_BASE_PROPS.addExtrudedHeight,
|
|
42
|
+
addHeight: DEFAULT_BASE_PROPS.addHeight,
|
|
43
|
+
reflectivity: DEFAULT_BASE_PROPS.reflectivity,
|
|
44
|
+
roughness: DEFAULT_BASE_PROPS.roughness,
|
|
45
|
+
batchColorEnabled: DEFAULT_BASE_PROPS.batchColorEnabled,
|
|
46
|
+
useBatchTexture: DEFAULT_BASE_PROPS.useBatchTexture,
|
|
47
|
+
useBatchColorShow: DEFAULT_BASE_PROPS.useBatchColorShow,
|
|
48
|
+
useBatchHeight: DEFAULT_BASE_PROPS.useBatchHeight,
|
|
49
|
+
useBatchExtrudedHeight: DEFAULT_BASE_PROPS.useBatchExtrudedHeight,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Update immutable state from props.
|
|
54
|
+
* Props override currentState values; missing props fall back to currentState.
|
|
55
|
+
* Pass DEFAULT_BASE_STATE as currentState for initial mount.
|
|
56
|
+
*
|
|
57
|
+
* @param props - The props to apply
|
|
58
|
+
* @param currentState - The current state to use as fallback (use DEFAULT_BASE_STATE for mount)
|
|
59
|
+
*/
|
|
60
|
+
export const updateState = (
|
|
61
|
+
props: PolygonBaseProps,
|
|
62
|
+
currentState: PolygonBaseState,
|
|
63
|
+
): PolygonBaseState => {
|
|
64
|
+
const isTexturized = props.isTexturized ?? currentState.isTexturized;
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
// RTE cannot change after mount - always preserve current value
|
|
68
|
+
useRTE: currentState.useRTE,
|
|
69
|
+
isTexturized,
|
|
70
|
+
clampToGround: props.clampToGround ?? currentState.clampToGround,
|
|
71
|
+
pickable: props.pickable ?? currentState.pickable,
|
|
72
|
+
emissiveColor: props.emissiveColor ?? currentState.emissiveColor,
|
|
73
|
+
emissiveIntensity:
|
|
74
|
+
props.emissiveIntensity ?? currentState.emissiveIntensity,
|
|
75
|
+
effectIdsMask: props.effectIdsMask ?? currentState.effectIdsMask,
|
|
76
|
+
minMaxHeight: props.minMaxHeight ?? currentState.minMaxHeight,
|
|
77
|
+
addExtrudedHeight:
|
|
78
|
+
props.addExtrudedHeight ?? currentState.addExtrudedHeight,
|
|
79
|
+
addHeight: props.addHeight ?? currentState.addHeight,
|
|
80
|
+
reflectivity: props.reflectivity ?? currentState.reflectivity,
|
|
81
|
+
roughness: props.roughness ?? currentState.roughness,
|
|
82
|
+
// Batch flags can only transition from false to true, never back
|
|
83
|
+
batchColorEnabled:
|
|
84
|
+
props.batchColorEnabled ?? currentState.batchColorEnabled,
|
|
85
|
+
useBatchTexture: props.useBatchTexture ?? currentState.useBatchTexture,
|
|
86
|
+
useBatchColorShow:
|
|
87
|
+
props.useBatchColorShow ?? currentState.useBatchColorShow,
|
|
88
|
+
useBatchHeight: props.useBatchHeight ?? currentState.useBatchHeight,
|
|
89
|
+
useBatchExtrudedHeight:
|
|
90
|
+
props.useBatchExtrudedHeight ?? currentState.useBatchExtrudedHeight,
|
|
91
|
+
};
|
|
92
|
+
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { Matrix4, Texture, Vector3 } from "three";
|
|
2
|
+
|
|
3
|
+
import type { UniformValue } from "../../../types";
|
|
4
|
+
import type { BatchTextureFlags } from "../../batchTexture";
|
|
5
|
+
import type { Mutates } from "../../MaterialEnhancer";
|
|
6
|
+
|
|
7
|
+
type PolygonBatchTextureFlags = Required<
|
|
8
|
+
Omit<BatchTextureFlags, "useBatchLineWidth" | "useBatchSize">
|
|
9
|
+
>;
|
|
10
|
+
// Note: opacity is bundled with show in useBatchColorShow
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Props for the polygon core enhancer.
|
|
14
|
+
*/
|
|
15
|
+
export type PolygonBaseProps = {
|
|
16
|
+
// Basic material props
|
|
17
|
+
color?: number;
|
|
18
|
+
opacity?: number;
|
|
19
|
+
transparent?: boolean;
|
|
20
|
+
wireframe?: boolean;
|
|
21
|
+
|
|
22
|
+
// Height/extrusion
|
|
23
|
+
minMaxHeight?: [number, number];
|
|
24
|
+
addExtrudedHeight?: number;
|
|
25
|
+
addHeight?: number;
|
|
26
|
+
|
|
27
|
+
// Clamp to ground
|
|
28
|
+
clampToGround?: boolean;
|
|
29
|
+
isTexturized?: boolean;
|
|
30
|
+
|
|
31
|
+
// Picking
|
|
32
|
+
pickable?: boolean;
|
|
33
|
+
|
|
34
|
+
// Selective Effect
|
|
35
|
+
effectIdsMask?: number;
|
|
36
|
+
|
|
37
|
+
// Reflectivity
|
|
38
|
+
reflectivity?: number;
|
|
39
|
+
roughness?: number;
|
|
40
|
+
|
|
41
|
+
// Emissive (for selective effects)
|
|
42
|
+
emissiveColor?: number;
|
|
43
|
+
emissiveIntensity?: number;
|
|
44
|
+
|
|
45
|
+
// External uniforms (passed from CommonUniforms)
|
|
46
|
+
globeNormalTexture?: UniformValue<Texture | null>;
|
|
47
|
+
|
|
48
|
+
// Batch texture
|
|
49
|
+
batchDataTexture?: UniformValue<Texture | null>;
|
|
50
|
+
|
|
51
|
+
// Batch texture state flags - track when batch attributes are being used
|
|
52
|
+
// When batchColorEnabled is true, material.color is set to white and actual colors come from batch texture
|
|
53
|
+
batchColorEnabled?: boolean;
|
|
54
|
+
|
|
55
|
+
// RTE (Relative To Eye) support
|
|
56
|
+
useRTE?: boolean;
|
|
57
|
+
} & Partial<PolygonBatchTextureFlags>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Immutable state for the polygon base enhancer.
|
|
61
|
+
* This state is always replaced as a whole (never mutated).
|
|
62
|
+
* Returned directly via states() - refresh after updates.
|
|
63
|
+
*/
|
|
64
|
+
export type PolygonBaseState = Readonly<
|
|
65
|
+
{
|
|
66
|
+
useRTE: boolean;
|
|
67
|
+
isTexturized: boolean;
|
|
68
|
+
clampToGround: boolean;
|
|
69
|
+
pickable: boolean;
|
|
70
|
+
emissiveColor: number;
|
|
71
|
+
emissiveIntensity: number;
|
|
72
|
+
effectIdsMask: number;
|
|
73
|
+
minMaxHeight: [number, number] | undefined;
|
|
74
|
+
addExtrudedHeight: number;
|
|
75
|
+
addHeight: number;
|
|
76
|
+
reflectivity: number;
|
|
77
|
+
roughness: number;
|
|
78
|
+
// Batch texture state - when true, material.color is white and colors come from batch texture
|
|
79
|
+
batchColorEnabled: boolean;
|
|
80
|
+
} & PolygonBatchTextureFlags
|
|
81
|
+
>;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Mutable references (uniforms) for the polygon base enhancer.
|
|
85
|
+
*
|
|
86
|
+
* These are shared references with shader.uniforms and can be mutated directly
|
|
87
|
+
* for efficient GPU uniform updates without shader recompilation.
|
|
88
|
+
* Internal type - not exposed externally.
|
|
89
|
+
*/
|
|
90
|
+
export type PolygonBaseRefs = {
|
|
91
|
+
// Core uniforms
|
|
92
|
+
uMinMaxHeight: UniformValue<[number, number] | undefined>;
|
|
93
|
+
uAddExtrudedHeight: UniformValue<number>;
|
|
94
|
+
uAddHeight: UniformValue<number>;
|
|
95
|
+
uClampToGround: UniformValue<boolean>;
|
|
96
|
+
nvr_uPickable: UniformValue<number>;
|
|
97
|
+
uEffectIdsMask: UniformValue<number>;
|
|
98
|
+
uEmissiveIntensity: UniformValue<number>;
|
|
99
|
+
uIsTexturized: UniformValue<boolean>;
|
|
100
|
+
reflectivity: UniformValue<number>;
|
|
101
|
+
roughness: UniformValue<number>;
|
|
102
|
+
|
|
103
|
+
// Optional uniforms
|
|
104
|
+
batchDataTexture?: UniformValue<Texture | null>;
|
|
105
|
+
uGlobeNormal?: UniformValue<Texture | null>;
|
|
106
|
+
|
|
107
|
+
// RTE uniforms (only present if useRTE is true)
|
|
108
|
+
modelViewMatrixRTE?: UniformValue<Matrix4>;
|
|
109
|
+
u_cameraPositionHigh?: UniformValue<Vector3>;
|
|
110
|
+
u_cameraPositionLow?: UniformValue<Vector3>;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export type PolygonBaseUniforms = Partial<PolygonBaseRefs>;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Mutation functions for the polygon base enhancer.
|
|
117
|
+
* Includes `update(state)` to sync refs from state, plus additional methods.
|
|
118
|
+
*/
|
|
119
|
+
export type PolygonBaseMutates = Mutates<
|
|
120
|
+
PolygonBaseState,
|
|
121
|
+
PolygonBaseUniforms,
|
|
122
|
+
{
|
|
123
|
+
/**
|
|
124
|
+
* Update RTE (Relative-To-Eye) uniforms for high-precision rendering.
|
|
125
|
+
* Call this per-frame to update the model-view matrix and camera position.
|
|
126
|
+
* Does nothing if RTE is not enabled.
|
|
127
|
+
*
|
|
128
|
+
* @param modelViewMatrixRTE - The model-view matrix in RTE coordinates
|
|
129
|
+
* @param cameraPositionHigh - High-precision component of camera position
|
|
130
|
+
* @param cameraPositionLow - Low-precision component of camera position
|
|
131
|
+
* @param state - PolygonBaseState
|
|
132
|
+
*/
|
|
133
|
+
updateRteUniforms: (
|
|
134
|
+
modelViewMatrixRTE: Matrix4,
|
|
135
|
+
cameraPositionHigh: Vector3,
|
|
136
|
+
cameraPositionLow: Vector3,
|
|
137
|
+
state: PolygonBaseState,
|
|
138
|
+
) => void;
|
|
139
|
+
/**
|
|
140
|
+
* Set the batch data texture ref.
|
|
141
|
+
* This is needed because batchDataTexture is an external ref passed via props.
|
|
142
|
+
*/
|
|
143
|
+
setBatchDataTexture: (texture: UniformValue<Texture | null>) => void;
|
|
144
|
+
/**
|
|
145
|
+
* Set the globe normal texture ref.
|
|
146
|
+
* This is needed because globeNormalTexture is an external ref passed via props.
|
|
147
|
+
*/
|
|
148
|
+
setGlobeNormalTexture: (texture: UniformValue<Texture | null>) => void;
|
|
149
|
+
}
|
|
150
|
+
>;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Polygon Material Enhancer - Composed from Base + Water enhancers
|
|
3
|
+
*
|
|
4
|
+
* This module provides the full polygon material functionality by using
|
|
5
|
+
* the water enhancer factory which internally composes with the base enhancer.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { MaterialEnhancer } from "../MaterialEnhancer";
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
createPolygonBaseEnhancer,
|
|
12
|
+
type PolygonBaseMutates,
|
|
13
|
+
type PolygonBaseProps,
|
|
14
|
+
type PolygonBaseState,
|
|
15
|
+
} from "./polygonBaseEnhancer";
|
|
16
|
+
import {
|
|
17
|
+
createPolygonWaterEnhancer,
|
|
18
|
+
type PolygonWaterCombinedMutates,
|
|
19
|
+
type PolygonWaterCombinedStates,
|
|
20
|
+
type PolygonWaterProps,
|
|
21
|
+
type PolygonWaterState,
|
|
22
|
+
type WaterOnlyProps,
|
|
23
|
+
type AVAILABLE_SHADERS as WATER_AVAILABLE_SHADERS,
|
|
24
|
+
type SupportedMaterial as WaterSupportedMaterial,
|
|
25
|
+
} from "./polygonWaterEnhancer";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Combined props for the polygon material enhancer.
|
|
29
|
+
* Props are explicitly separated into base and water sections for clarity.
|
|
30
|
+
*/
|
|
31
|
+
export type PolygonMaterialProps = {
|
|
32
|
+
base?: PolygonBaseProps;
|
|
33
|
+
water?: WaterOnlyProps;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// Shaders this enhancer supports
|
|
37
|
+
type AVAILABLE_SHADERS = typeof WATER_AVAILABLE_SHADERS;
|
|
38
|
+
type SupportedMaterial = WaterSupportedMaterial;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Factory function to create the polygon material enhancer.
|
|
42
|
+
*
|
|
43
|
+
* This creates a new enhancer instance with its own internal state.
|
|
44
|
+
*
|
|
45
|
+
* @param material - The Three.js material to enhance
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const material = new MeshLambertMaterial();
|
|
50
|
+
* const enhancer = createPolygonMaterialEnhancer(material);
|
|
51
|
+
*
|
|
52
|
+
* // Mount with separated base and water props
|
|
53
|
+
* enhancer.mount({
|
|
54
|
+
* base: { color: 0xff0000, useRTE: true },
|
|
55
|
+
* water: { water: true, waterScaleNormal: 0.5 },
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* // Get state directly via states() - refresh after updates
|
|
59
|
+
* const { base, water } = enhancer.states();
|
|
60
|
+
*
|
|
61
|
+
* // Update RTE uniforms per-frame via mutates()
|
|
62
|
+
* if (base.useRTE) {
|
|
63
|
+
* const { base: baseMutates } = enhancer.mutates();
|
|
64
|
+
* baseMutates.updateRteUniforms(modelViewMatrix, cameraHigh, cameraLow);
|
|
65
|
+
* }
|
|
66
|
+
*
|
|
67
|
+
* // Update props (then call states() again to get fresh state)
|
|
68
|
+
* enhancer.update({ base: { addHeight: 100 } });
|
|
69
|
+
*
|
|
70
|
+
* // Use transformShader for onBeforeCompile
|
|
71
|
+
* material.onBeforeCompile = enhancer.transformShader;
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export function createPolygonMaterialEnhancer(
|
|
75
|
+
material: SupportedMaterial,
|
|
76
|
+
): MaterialEnhancer<
|
|
77
|
+
SupportedMaterial,
|
|
78
|
+
PolygonMaterialProps,
|
|
79
|
+
PolygonWaterCombinedStates,
|
|
80
|
+
PolygonWaterCombinedMutates,
|
|
81
|
+
AVAILABLE_SHADERS
|
|
82
|
+
> {
|
|
83
|
+
const baseEnhancer = createPolygonBaseEnhancer(material);
|
|
84
|
+
return createPolygonWaterEnhancer(baseEnhancer);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Re-export types for convenience
|
|
88
|
+
export type {
|
|
89
|
+
PolygonBaseMutates,
|
|
90
|
+
PolygonBaseProps,
|
|
91
|
+
PolygonBaseState,
|
|
92
|
+
PolygonWaterCombinedMutates,
|
|
93
|
+
PolygonWaterCombinedStates,
|
|
94
|
+
PolygonWaterProps,
|
|
95
|
+
PolygonWaterState,
|
|
96
|
+
WaterOnlyProps,
|
|
97
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { MeshLambertMaterial } from "three";
|
|
2
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
3
|
+
|
|
4
|
+
import { createPolygonBaseEnhancer } from "../polygonBaseEnhancer";
|
|
5
|
+
|
|
6
|
+
import { createPolygonWaterEnhancer } from ".";
|
|
7
|
+
|
|
8
|
+
describe("polygonWaterEnhancer", () => {
|
|
9
|
+
let enhancer: ReturnType<typeof createPolygonWaterEnhancer>;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
const baseEnhancer = createPolygonBaseEnhancer(new MeshLambertMaterial());
|
|
13
|
+
enhancer = createPolygonWaterEnhancer(baseEnhancer);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe("lifecycle", () => {
|
|
17
|
+
it("states() should throw if called before mount", () => {
|
|
18
|
+
const freshMaterial = new MeshLambertMaterial();
|
|
19
|
+
const baseEnhancer = createPolygonBaseEnhancer(freshMaterial);
|
|
20
|
+
const freshEnhancer = createPolygonWaterEnhancer(baseEnhancer);
|
|
21
|
+
|
|
22
|
+
expect(() => freshEnhancer.states()).toThrow(
|
|
23
|
+
"mount() must be called before states",
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe("programCacheKey", () => {
|
|
29
|
+
it("should combine base cache key with water-specific state", () => {
|
|
30
|
+
enhancer.mount({
|
|
31
|
+
base: { useBatchTexture: true },
|
|
32
|
+
water: { water: true },
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const cacheKey = enhancer.programCacheKey();
|
|
36
|
+
|
|
37
|
+
// Should contain both base and water cache keys
|
|
38
|
+
expect(cacheKey).toContain('"useBatchTexture":true');
|
|
39
|
+
expect(cacheKey).toContain('"useWater":true');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("should return different cache keys when useWater differs", () => {
|
|
43
|
+
enhancer.mount({ water: { water: false } });
|
|
44
|
+
const cacheKey1 = enhancer.programCacheKey();
|
|
45
|
+
|
|
46
|
+
const enhancer2 = createPolygonWaterEnhancer(
|
|
47
|
+
createPolygonBaseEnhancer(new MeshLambertMaterial()),
|
|
48
|
+
);
|
|
49
|
+
enhancer2.mount({ water: { water: true } });
|
|
50
|
+
const cacheKey2 = enhancer2.programCacheKey();
|
|
51
|
+
|
|
52
|
+
expect(cacheKey1).not.toBe(cacheKey2);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should return same cache key for same shader-affecting states with different non-affecting states", () => {
|
|
56
|
+
enhancer.mount({
|
|
57
|
+
water: { water: true, waterSpeed: 1.0, shininess: 10 },
|
|
58
|
+
});
|
|
59
|
+
const cacheKey1 = enhancer.programCacheKey();
|
|
60
|
+
|
|
61
|
+
const enhancer2 = createPolygonWaterEnhancer(
|
|
62
|
+
createPolygonBaseEnhancer(new MeshLambertMaterial()),
|
|
63
|
+
);
|
|
64
|
+
enhancer2.mount({
|
|
65
|
+
water: { water: true, waterSpeed: 5.0, shininess: 50 },
|
|
66
|
+
});
|
|
67
|
+
const cacheKey2 = enhancer2.programCacheKey();
|
|
68
|
+
|
|
69
|
+
expect(cacheKey1).toBe(cacheKey2);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,164 @@
|
|
|
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
|
+
import type {
|
|
7
|
+
PolygonBaseMutates,
|
|
8
|
+
PolygonBaseProps,
|
|
9
|
+
PolygonBaseState,
|
|
10
|
+
SupportedMaterial,
|
|
11
|
+
} from "../polygonBaseEnhancer";
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
AVAILABLE_SHADERS,
|
|
15
|
+
type SupportedMaterial as WaterSupportedMaterial,
|
|
16
|
+
} from "./material";
|
|
17
|
+
import { applyWaterMaterialConfig } from "./material";
|
|
18
|
+
import { createWaterMutates } from "./mutates";
|
|
19
|
+
import { transformWaterShader } from "./shader";
|
|
20
|
+
import {
|
|
21
|
+
DEFAULT_WATER_PROPS,
|
|
22
|
+
DEFAULT_WATER_STATE,
|
|
23
|
+
updateWaterState,
|
|
24
|
+
} from "./state";
|
|
25
|
+
import type {
|
|
26
|
+
PolygonWaterCombinedMutates,
|
|
27
|
+
PolygonWaterCombinedStates,
|
|
28
|
+
PolygonWaterProps,
|
|
29
|
+
PolygonWaterState,
|
|
30
|
+
WaterMutates,
|
|
31
|
+
WaterOnlyProps,
|
|
32
|
+
} from "./types";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Factory function to create a polygon water enhancer.
|
|
36
|
+
*
|
|
37
|
+
* @param baseEnhancer - The base polygon enhancer to compose with (material is obtained from this)
|
|
38
|
+
* @returns A new MaterialEnhancer with combined base + water functionality
|
|
39
|
+
*/
|
|
40
|
+
export function createPolygonWaterEnhancer(
|
|
41
|
+
baseEnhancer: MaterialEnhancer<
|
|
42
|
+
SupportedMaterial,
|
|
43
|
+
PolygonBaseProps,
|
|
44
|
+
PolygonBaseState,
|
|
45
|
+
PolygonBaseMutates,
|
|
46
|
+
typeof AVAILABLE_SHADERS
|
|
47
|
+
>,
|
|
48
|
+
): MaterialEnhancer<
|
|
49
|
+
WaterSupportedMaterial,
|
|
50
|
+
PolygonWaterProps,
|
|
51
|
+
PolygonWaterCombinedStates,
|
|
52
|
+
PolygonWaterCombinedMutates,
|
|
53
|
+
typeof AVAILABLE_SHADERS
|
|
54
|
+
> {
|
|
55
|
+
const { material } = baseEnhancer;
|
|
56
|
+
// Internal state - immutable, always replaced as a whole
|
|
57
|
+
let state: PolygonWaterState | null = null;
|
|
58
|
+
// Internal mutates object (refs are hidden inside)
|
|
59
|
+
let mutates: WaterMutates | null = null;
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
material: material as WaterSupportedMaterial,
|
|
63
|
+
availableShaders: AVAILABLE_SHADERS,
|
|
64
|
+
|
|
65
|
+
transformShader: (shader: WebGLProgramParametersWithUniforms): void => {
|
|
66
|
+
invariant(
|
|
67
|
+
state && mutates,
|
|
68
|
+
"mount() must be called before transformShader",
|
|
69
|
+
);
|
|
70
|
+
// First apply base transformations
|
|
71
|
+
baseEnhancer.transformShader(shader);
|
|
72
|
+
// Then apply water transformations
|
|
73
|
+
transformWaterShader(shader, state, mutates);
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
mount: (props: PolygonWaterProps): void => {
|
|
77
|
+
// Mount base enhancer first with base props
|
|
78
|
+
baseEnhancer.mount(props.base ?? {});
|
|
79
|
+
|
|
80
|
+
// Initialize water state and mutates with water props
|
|
81
|
+
const waterProps = props.water ?? {};
|
|
82
|
+
const mergedWaterProps = defaults({}, waterProps, DEFAULT_WATER_PROPS);
|
|
83
|
+
state = updateWaterState(mergedWaterProps, DEFAULT_WATER_STATE);
|
|
84
|
+
// Create mutates (refs are created inside with default values)
|
|
85
|
+
mutates = createWaterMutates();
|
|
86
|
+
mutates.update(state);
|
|
87
|
+
// Handle external ref (timeUniform identity doesn't change after mount)
|
|
88
|
+
if (waterProps.timeUniform) {
|
|
89
|
+
mutates.setTimeUniform(waterProps.timeUniform);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Apply material configuration (side effect)
|
|
93
|
+
const { isTexturized } = baseEnhancer.states();
|
|
94
|
+
applyWaterMaterialConfig(
|
|
95
|
+
material as WaterSupportedMaterial,
|
|
96
|
+
state,
|
|
97
|
+
isTexturized,
|
|
98
|
+
false,
|
|
99
|
+
);
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
update: (props: PolygonWaterProps): void => {
|
|
103
|
+
// Update base enhancer first with base props
|
|
104
|
+
if (props.base) {
|
|
105
|
+
baseEnhancer.update(props.base);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
invariant(state && mutates, "mount() must be called before update");
|
|
109
|
+
|
|
110
|
+
// Update water state and refs with water props
|
|
111
|
+
if (props.water) {
|
|
112
|
+
const prevUseWater = state.useWater;
|
|
113
|
+
state = updateWaterState(props.water, state);
|
|
114
|
+
mutates.update(state);
|
|
115
|
+
// Handle external ref (timeUniform identity doesn't change, only set once)
|
|
116
|
+
if (props.water.timeUniform) {
|
|
117
|
+
mutates.setTimeUniform(props.water.timeUniform);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Apply material configuration (side effect)
|
|
121
|
+
const { isTexturized } = baseEnhancer.states();
|
|
122
|
+
applyWaterMaterialConfig(material, state, isTexturized, prevUseWater);
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
states: (): PolygonWaterCombinedStates => {
|
|
127
|
+
invariant(state, "mount() must be called before states");
|
|
128
|
+
return {
|
|
129
|
+
base: baseEnhancer.states(),
|
|
130
|
+
water: state,
|
|
131
|
+
};
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
mutates: (): PolygonWaterCombinedMutates => {
|
|
135
|
+
invariant(mutates, "mount() must be called before mutates");
|
|
136
|
+
return {
|
|
137
|
+
base: baseEnhancer.mutates(),
|
|
138
|
+
water: mutates,
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
programCacheKey: (): string => {
|
|
143
|
+
invariant(state, "mount() must be called before programCacheKey");
|
|
144
|
+
// Combine base cache key with water-specific state
|
|
145
|
+
return (
|
|
146
|
+
baseEnhancer.programCacheKey() +
|
|
147
|
+
JSON.stringify({
|
|
148
|
+
useWater: state.useWater,
|
|
149
|
+
})
|
|
150
|
+
);
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Re-export public types
|
|
156
|
+
export type {
|
|
157
|
+
PolygonWaterCombinedMutates,
|
|
158
|
+
PolygonWaterCombinedStates,
|
|
159
|
+
PolygonWaterProps,
|
|
160
|
+
PolygonWaterState,
|
|
161
|
+
WaterOnlyProps,
|
|
162
|
+
AVAILABLE_SHADERS,
|
|
163
|
+
SupportedMaterial,
|
|
164
|
+
};
|