@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.
Files changed (350) hide show
  1. package/LICENSE +8 -0
  2. package/dist/assets/atmosphere/README.md +1 -0
  3. package/dist/assets/atmosphere/higher_order_scattering.bin +0 -0
  4. package/dist/assets/atmosphere/higher_order_scattering.exr +0 -0
  5. package/dist/assets/atmosphere/irradiance.bin +0 -0
  6. package/dist/assets/atmosphere/irradiance.exr +0 -0
  7. package/dist/assets/atmosphere/scattering.bin +0 -0
  8. package/dist/assets/atmosphere/scattering.exr +0 -0
  9. package/dist/assets/atmosphere/single_mie_scattering.bin +0 -0
  10. package/dist/assets/atmosphere/single_mie_scattering.exr +0 -0
  11. package/dist/assets/atmosphere/stars.bin +0 -0
  12. package/dist/assets/atmosphere/transmittance.bin +0 -0
  13. package/dist/assets/atmosphere/transmittance.exr +0 -0
  14. package/dist/assets/cloud/README.md +1 -0
  15. package/dist/assets/cloud/local_weather.png +0 -0
  16. package/dist/assets/cloud/shape.bin +1 -0
  17. package/dist/assets/cloud/shape_detail.bin +1 -0
  18. package/dist/assets/cloud/turbulence.png +0 -0
  19. package/dist/assets/fontWorker-CEJEfRpb.js +2 -0
  20. package/dist/assets/fontWorker-CEJEfRpb.js.map +1 -0
  21. package/dist/assets/index-BUB-ijMO.js +12 -0
  22. package/dist/assets/index-BUB-ijMO.js.map +1 -0
  23. package/dist/assets/navara_wasm_font_worker_bg-665OLxjy.wasm +0 -0
  24. package/dist/assets/navara_wasm_worker_bg-BXhKC5bE.wasm +0 -0
  25. package/dist/assets/noise/README.md +1 -0
  26. package/dist/assets/noise/stbn.bin +0 -0
  27. package/dist/assets/water/README.md +3 -0
  28. package/dist/assets/water/waternormals.jpg +0 -0
  29. package/dist/index.d.ts +10114 -0
  30. package/dist/index.js +34481 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/index.umd.cjs +6345 -0
  33. package/dist/index.umd.cjs.map +1 -0
  34. package/package.json +95 -0
  35. package/src/Color.ts +111 -0
  36. package/src/ShadowMapViewers.ts +49 -0
  37. package/src/atmosphere.test.ts +76 -0
  38. package/src/atmosphere.ts +364 -0
  39. package/src/bufferView.ts +90 -0
  40. package/src/camera.ts +182 -0
  41. package/src/concurrency.ts +15 -0
  42. package/src/constants/assets.ts +30 -0
  43. package/src/constants/decoder.ts +7 -0
  44. package/src/constants/index.ts +2 -0
  45. package/src/core/BaseDesc.ts +142 -0
  46. package/src/core/BaseHandle.ts +126 -0
  47. package/src/core/DescRegistry.ts +88 -0
  48. package/src/core/EffectDesc.ts +343 -0
  49. package/src/core/EffectDescRegistry.ts +31 -0
  50. package/src/core/InstancedMeshDesc.ts +413 -0
  51. package/src/core/LightDesc.ts +216 -0
  52. package/src/core/LightDescRegistry.ts +32 -0
  53. package/src/core/MeshDesc.ts +457 -0
  54. package/src/core/MeshDescRegistry.ts +32 -0
  55. package/src/core/MeshDescWithSelectiveEffect.ts +129 -0
  56. package/src/core/Registries.ts +59 -0
  57. package/src/core/SelectiveEffectRegistry.ts +90 -0
  58. package/src/core/ViewContext.ts +235 -0
  59. package/src/core/errors.ts +16 -0
  60. package/src/core/index.ts +50 -0
  61. package/src/device.ts +414 -0
  62. package/src/effects/CustomEffectPass.ts +28 -0
  63. package/src/effects/copy.ts +10 -0
  64. package/src/effects/effect.ts +87 -0
  65. package/src/effects/index.ts +4 -0
  66. package/src/effects/render.ts +10 -0
  67. package/src/evaluations/FeatureEvaluator.ts +529 -0
  68. package/src/evaluations/index.ts +1 -0
  69. package/src/event/HillshadeContext.test.ts +232 -0
  70. package/src/event/HillshadeContext.ts +299 -0
  71. package/src/event/context.ts +279 -0
  72. package/src/event/feature.ts +357 -0
  73. package/src/event/featureEvent.ts +81 -0
  74. package/src/event/features/billboard.ts +30 -0
  75. package/src/event/features/model.ts +192 -0
  76. package/src/event/features/modelGpuBytes.test.ts +69 -0
  77. package/src/event/features/modelGpuBytes.ts +87 -0
  78. package/src/event/features/point.ts +25 -0
  79. package/src/event/features/polygon.ts +23 -0
  80. package/src/event/features/polygonOutline.ts +19 -0
  81. package/src/event/features/polyline.ts +19 -0
  82. package/src/event/features/text.ts +71 -0
  83. package/src/event/hillshade.test.ts +842 -0
  84. package/src/event/hillshade.ts +588 -0
  85. package/src/event/index.ts +700 -0
  86. package/src/event/loaders.ts +53 -0
  87. package/src/event/tile.ts +19 -0
  88. package/src/event/worker.ts +999 -0
  89. package/src/event/workerTaskSettlement.test.ts +243 -0
  90. package/src/event/workerTaskSettlement.ts +128 -0
  91. package/src/inMemoryBufferStore.test.ts +60 -0
  92. package/src/inMemoryBufferStore.ts +67 -0
  93. package/src/index.iife.ts +11 -0
  94. package/src/index.ts +2556 -0
  95. package/src/input.ts +144 -0
  96. package/src/layer.ts +183 -0
  97. package/src/layers/effect/FinalCopyEffectDesc.ts +29 -0
  98. package/src/layers/effect/MRTPassEffectDesc.ts +105 -0
  99. package/src/layers/effect/README.md +9 -0
  100. package/src/layers/effect/SelectiveEffectDesc.ts +113 -0
  101. package/src/layers/effect/SkyEnvMapEffectDesc.ts +58 -0
  102. package/src/layers/effect/TransparentPassEffectDesc.ts +62 -0
  103. package/src/layers/effect/index.ts +5 -0
  104. package/src/layers/index.ts +1 -0
  105. package/src/layersManager.ts +63 -0
  106. package/src/light.ts +15 -0
  107. package/src/loaders/AbortableImageLoader.ts +203 -0
  108. package/src/loaders/AbortableTextureLoader.ts +74 -0
  109. package/src/loaders/index.ts +5 -0
  110. package/src/material/enhancer/DESIGN.md +300 -0
  111. package/src/material/enhancer/MaterialEnhancer.ts +112 -0
  112. package/src/material/enhancer/ShaderReplacer.test.ts +114 -0
  113. package/src/material/enhancer/ShaderReplacer.ts +97 -0
  114. package/src/material/enhancer/batchTexture.ts +8 -0
  115. package/src/material/enhancer/index.ts +46 -0
  116. package/src/material/enhancer/instancedSprite/index.ts +7 -0
  117. package/src/material/enhancer/instancedSprite/instancedSpriteBaseEnhancer/index.test.ts +214 -0
  118. package/src/material/enhancer/instancedSprite/instancedSpriteBaseEnhancer/index.ts +134 -0
  119. package/src/material/enhancer/instancedSprite/instancedSpriteBaseEnhancer/markers.ts +21 -0
  120. package/src/material/enhancer/instancedSprite/instancedSpriteBaseEnhancer/material.ts +32 -0
  121. package/src/material/enhancer/instancedSprite/instancedSpriteBaseEnhancer/mutates.test.ts +277 -0
  122. package/src/material/enhancer/instancedSprite/instancedSpriteBaseEnhancer/mutates.ts +151 -0
  123. package/src/material/enhancer/instancedSprite/instancedSpriteBaseEnhancer/shader.test.ts +114 -0
  124. package/src/material/enhancer/instancedSprite/instancedSpriteBaseEnhancer/shader.ts +49 -0
  125. package/src/material/enhancer/instancedSprite/instancedSpriteBaseEnhancer/state.test.ts +82 -0
  126. package/src/material/enhancer/instancedSprite/instancedSpriteBaseEnhancer/state.ts +80 -0
  127. package/src/material/enhancer/instancedSprite/instancedSpriteBaseEnhancer/types.ts +146 -0
  128. package/src/material/enhancer/instancedSprite/instancedSpriteMaterialEnhancer.ts +105 -0
  129. package/src/material/enhancer/model/index.ts +25 -0
  130. package/src/material/enhancer/model/modelBaseEnhancer/index.test.ts +74 -0
  131. package/src/material/enhancer/model/modelBaseEnhancer/index.ts +110 -0
  132. package/src/material/enhancer/model/modelBaseEnhancer/markers.ts +27 -0
  133. package/src/material/enhancer/model/modelBaseEnhancer/material.test.ts +66 -0
  134. package/src/material/enhancer/model/modelBaseEnhancer/material.ts +44 -0
  135. package/src/material/enhancer/model/modelBaseEnhancer/mutates.test.ts +84 -0
  136. package/src/material/enhancer/model/modelBaseEnhancer/mutates.ts +47 -0
  137. package/src/material/enhancer/model/modelBaseEnhancer/shader.test.ts +24 -0
  138. package/src/material/enhancer/model/modelBaseEnhancer/shader.ts +162 -0
  139. package/src/material/enhancer/model/modelBaseEnhancer/state.test.ts +103 -0
  140. package/src/material/enhancer/model/modelBaseEnhancer/state.ts +52 -0
  141. package/src/material/enhancer/model/modelBaseEnhancer/types.ts +89 -0
  142. package/src/material/enhancer/model/modelMaterialEnhancer.ts +91 -0
  143. package/src/material/enhancer/model/modelWaterEnhancer/index.test.ts +71 -0
  144. package/src/material/enhancer/model/modelWaterEnhancer/index.ts +175 -0
  145. package/src/material/enhancer/model/modelWaterEnhancer/material.test.ts +48 -0
  146. package/src/material/enhancer/model/modelWaterEnhancer/material.ts +25 -0
  147. package/src/material/enhancer/model/modelWaterEnhancer/mutates.test.ts +89 -0
  148. package/src/material/enhancer/model/modelWaterEnhancer/mutates.ts +89 -0
  149. package/src/material/enhancer/model/modelWaterEnhancer/shader.test.ts +34 -0
  150. package/src/material/enhancer/model/modelWaterEnhancer/shader.ts +111 -0
  151. package/src/material/enhancer/model/modelWaterEnhancer/state.test.ts +105 -0
  152. package/src/material/enhancer/model/modelWaterEnhancer/state.ts +59 -0
  153. package/src/material/enhancer/model/modelWaterEnhancer/types.ts +141 -0
  154. package/src/material/enhancer/model/pntsEnhancer/index.test.ts +96 -0
  155. package/src/material/enhancer/model/pntsEnhancer/index.ts +82 -0
  156. package/src/material/enhancer/model/pntsEnhancer/markers.ts +6 -0
  157. package/src/material/enhancer/model/pntsEnhancer/material.test.ts +37 -0
  158. package/src/material/enhancer/model/pntsEnhancer/material.ts +21 -0
  159. package/src/material/enhancer/model/pntsEnhancer/mutates.test.ts +80 -0
  160. package/src/material/enhancer/model/pntsEnhancer/mutates.ts +29 -0
  161. package/src/material/enhancer/model/pntsEnhancer/shader.test.ts +32 -0
  162. package/src/material/enhancer/model/pntsEnhancer/shader.ts +56 -0
  163. package/src/material/enhancer/model/pntsEnhancer/state.test.ts +87 -0
  164. package/src/material/enhancer/model/pntsEnhancer/state.ts +29 -0
  165. package/src/material/enhancer/model/pntsEnhancer/types.ts +38 -0
  166. package/src/material/enhancer/polygon/index.ts +22 -0
  167. package/src/material/enhancer/polygon/polygonBaseEnhancer/index.test.ts +101 -0
  168. package/src/material/enhancer/polygon/polygonBaseEnhancer/index.ts +130 -0
  169. package/src/material/enhancer/polygon/polygonBaseEnhancer/markers.ts +23 -0
  170. package/src/material/enhancer/polygon/polygonBaseEnhancer/material.test.ts +19 -0
  171. package/src/material/enhancer/polygon/polygonBaseEnhancer/material.ts +38 -0
  172. package/src/material/enhancer/polygon/polygonBaseEnhancer/mutates.test.ts +75 -0
  173. package/src/material/enhancer/polygon/polygonBaseEnhancer/mutates.ts +122 -0
  174. package/src/material/enhancer/polygon/polygonBaseEnhancer/shader.test.ts +25 -0
  175. package/src/material/enhancer/polygon/polygonBaseEnhancer/shader.ts +249 -0
  176. package/src/material/enhancer/polygon/polygonBaseEnhancer/state.test.ts +102 -0
  177. package/src/material/enhancer/polygon/polygonBaseEnhancer/state.ts +92 -0
  178. package/src/material/enhancer/polygon/polygonBaseEnhancer/types.ts +150 -0
  179. package/src/material/enhancer/polygon/polygonMaterialEnhancer.ts +97 -0
  180. package/src/material/enhancer/polygon/polygonWaterEnhancer/index.test.ts +72 -0
  181. package/src/material/enhancer/polygon/polygonWaterEnhancer/index.ts +164 -0
  182. package/src/material/enhancer/polygon/polygonWaterEnhancer/material.test.ts +48 -0
  183. package/src/material/enhancer/polygon/polygonWaterEnhancer/material.ts +35 -0
  184. package/src/material/enhancer/polygon/polygonWaterEnhancer/mutates.ts +61 -0
  185. package/src/material/enhancer/polygon/polygonWaterEnhancer/shader.test.ts +34 -0
  186. package/src/material/enhancer/polygon/polygonWaterEnhancer/shader.ts +96 -0
  187. package/src/material/enhancer/polygon/polygonWaterEnhancer/state.test.ts +98 -0
  188. package/src/material/enhancer/polygon/polygonWaterEnhancer/state.ts +57 -0
  189. package/src/material/enhancer/polygon/polygonWaterEnhancer/types.ts +115 -0
  190. package/src/material/enhancer/polyline/index.ts +7 -0
  191. package/src/material/enhancer/polyline/polylineBaseEnhancer/index.test.ts +157 -0
  192. package/src/material/enhancer/polyline/polylineBaseEnhancer/index.ts +154 -0
  193. package/src/material/enhancer/polyline/polylineBaseEnhancer/markers.ts +19 -0
  194. package/src/material/enhancer/polyline/polylineBaseEnhancer/material.test.ts +42 -0
  195. package/src/material/enhancer/polyline/polylineBaseEnhancer/material.ts +38 -0
  196. package/src/material/enhancer/polyline/polylineBaseEnhancer/mutates.test.ts +120 -0
  197. package/src/material/enhancer/polyline/polylineBaseEnhancer/mutates.ts +169 -0
  198. package/src/material/enhancer/polyline/polylineBaseEnhancer/shader.test.ts +67 -0
  199. package/src/material/enhancer/polyline/polylineBaseEnhancer/shader.ts +75 -0
  200. package/src/material/enhancer/polyline/polylineBaseEnhancer/state.test.ts +55 -0
  201. package/src/material/enhancer/polyline/polylineBaseEnhancer/state.ts +91 -0
  202. package/src/material/enhancer/polyline/polylineBaseEnhancer/types.ts +170 -0
  203. package/src/material/enhancer/polyline/polylineMaterialEnhancer.ts +102 -0
  204. package/src/material/enhancer/sdfText/index.ts +7 -0
  205. package/src/material/enhancer/sdfText/sdfTextBaseEnhancer/index.ts +125 -0
  206. package/src/material/enhancer/sdfText/sdfTextBaseEnhancer/markers.ts +19 -0
  207. package/src/material/enhancer/sdfText/sdfTextBaseEnhancer/material.test.ts +35 -0
  208. package/src/material/enhancer/sdfText/sdfTextBaseEnhancer/material.ts +32 -0
  209. package/src/material/enhancer/sdfText/sdfTextBaseEnhancer/mutates.test.ts +381 -0
  210. package/src/material/enhancer/sdfText/sdfTextBaseEnhancer/mutates.ts +232 -0
  211. package/src/material/enhancer/sdfText/sdfTextBaseEnhancer/shader.ts +36 -0
  212. package/src/material/enhancer/sdfText/sdfTextBaseEnhancer/state.test.ts +118 -0
  213. package/src/material/enhancer/sdfText/sdfTextBaseEnhancer/state.ts +107 -0
  214. package/src/material/enhancer/sdfText/sdfTextBaseEnhancer/types.ts +184 -0
  215. package/src/material/enhancer/sdfText/sdfTextMaterialEnhancer.ts +100 -0
  216. package/src/material/enhancer/shadowMap/index.ts +7 -0
  217. package/src/material/enhancer/shadowMap/shadowMapDepthEnhancer/index.ts +97 -0
  218. package/src/material/enhancer/shadowMap/shadowMapDepthEnhancer/markers.ts +10 -0
  219. package/src/material/enhancer/shadowMap/shadowMapDepthEnhancer/material.ts +31 -0
  220. package/src/material/enhancer/shadowMap/shadowMapDepthEnhancer/mutates.ts +8 -0
  221. package/src/material/enhancer/shadowMap/shadowMapDepthEnhancer/shader.test.ts +17 -0
  222. package/src/material/enhancer/shadowMap/shadowMapDepthEnhancer/shader.ts +53 -0
  223. package/src/material/enhancer/shadowMap/shadowMapDepthEnhancer/state.ts +17 -0
  224. package/src/material/enhancer/shadowMap/shadowMapDepthEnhancer/types.ts +26 -0
  225. package/src/material/enhancer/test-utils/shaderCompatibility.ts +124 -0
  226. package/src/material/enhancer/tileComposite/compose.test.ts +95 -0
  227. package/src/material/enhancer/tileComposite/compose.ts +112 -0
  228. package/src/material/enhancer/tileComposite/index.ts +23 -0
  229. package/src/material/enhancer/tileComposite/tileCompositeBaseEnhancer/index.ts +11 -0
  230. package/src/material/enhancer/tileComposite/tileCompositeBaseEnhancer/mutates.ts +132 -0
  231. package/src/material/enhancer/tileComposite/tileCompositeBaseEnhancer/shader.ts +245 -0
  232. package/src/material/enhancer/tileComposite/tileCompositeBaseEnhancer/types.ts +43 -0
  233. package/src/material/enhancer/tileComposite/tileElevationHeatmapEnhancer/index.ts +29 -0
  234. package/src/material/enhancer/tileComposite/tileElevationHeatmapEnhancer/mutates.ts +68 -0
  235. package/src/material/enhancer/tileComposite/tileElevationHeatmapEnhancer/shader.ts +24 -0
  236. package/src/material/enhancer/tileComposite/tileHillshadeEnhancer/index.ts +29 -0
  237. package/src/material/enhancer/tileComposite/tileHillshadeEnhancer/mutates.ts +34 -0
  238. package/src/material/enhancer/tileComposite/tileHillshadeEnhancer/shader.ts +36 -0
  239. package/src/material/enhancer/tileComposite/tileWaterEnhancer/index.ts +23 -0
  240. package/src/material/enhancer/tileComposite/tileWaterEnhancer/mutates.ts +23 -0
  241. package/src/material/enhancer/tileComposite/tileWaterEnhancer/shader.ts +8 -0
  242. package/src/material/enhancer/tileComposite/tileWatermaskEnhancer/index.ts +23 -0
  243. package/src/material/enhancer/tileComposite/tileWatermaskEnhancer/mutates.ts +34 -0
  244. package/src/material/enhancer/tileComposite/tileWatermaskEnhancer/shader.ts +13 -0
  245. package/src/material/enhancer/tileComposite/types.ts +58 -0
  246. package/src/material/index.ts +3 -0
  247. package/src/material/macro/index.ts +1 -0
  248. package/src/material/macro/tileShader.test.ts +136 -0
  249. package/src/material/macro/tileShader.ts +287 -0
  250. package/src/material/overrideMaterialsForMRT.ts +439 -0
  251. package/src/material/selectiveEffectMaterialSetup.test.ts +52 -0
  252. package/src/material/selectiveEffectMaterialSetup.ts +53 -0
  253. package/src/material/types/index.ts +1 -0
  254. package/src/material/types/uniform.ts +1 -0
  255. package/src/mesh/DrapedMesh.ts +101 -0
  256. package/src/mesh/batchTexture.test.ts +646 -0
  257. package/src/mesh/batchTexture.ts +437 -0
  258. package/src/mesh/batchedFeature.ts +186 -0
  259. package/src/mesh/batchedSdfText.ts +484 -0
  260. package/src/mesh/featureMesh.ts +43 -0
  261. package/src/mesh/index.ts +16 -0
  262. package/src/mesh/instanced.ts +117 -0
  263. package/src/mesh/model.ts +483 -0
  264. package/src/mesh/pickableMesh.ts +55 -0
  265. package/src/mesh/pickableMeshWrapper.ts +529 -0
  266. package/src/mesh/polygon.ts +699 -0
  267. package/src/mesh/polygonOutline.ts +393 -0
  268. package/src/mesh/polyline.ts +523 -0
  269. package/src/mesh/releaseGeometryArrays.ts +57 -0
  270. package/src/mesh/rtcRteHelper.ts +211 -0
  271. package/src/mesh/sdfText.test.ts +200 -0
  272. package/src/mesh/sdfText.ts +1019 -0
  273. package/src/mesh/sprite/billboardAtlas.test.ts +177 -0
  274. package/src/mesh/sprite/billboardAtlas.ts +210 -0
  275. package/src/mesh/sprite/billboardAtlasImageLoader.ts +29 -0
  276. package/src/mesh/sprite/index.ts +1 -0
  277. package/src/mesh/sprite/instancedSprite.ts +694 -0
  278. package/src/mesh/tile.test.ts +393 -0
  279. package/src/mesh/tile.ts +1790 -0
  280. package/src/object3DEvent.ts +6 -0
  281. package/src/orchestrators/RenderPassOrchestrator.ts +147 -0
  282. package/src/orchestrators/index.ts +1 -0
  283. package/src/passes/AllDepthCopyPass.ts +165 -0
  284. package/src/passes/CustomRenderPass.ts +279 -0
  285. package/src/passes/NormalCopyPass.ts +125 -0
  286. package/src/passes/RenderTargetCopyPass.ts +91 -0
  287. package/src/passes/SkyEnvMapPass.ts +58 -0
  288. package/src/passes/index.ts +5 -0
  289. package/src/pick/pickHelper.ts +273 -0
  290. package/src/pick/pickTerrain.ts +254 -0
  291. package/src/plugins/AttributionPlugin/AttributionPlugin.test.ts +210 -0
  292. package/src/plugins/AttributionPlugin/attribution.test.ts +225 -0
  293. package/src/plugins/AttributionPlugin/attribution.ts +355 -0
  294. package/src/plugins/AttributionPlugin/attributionStyles.ts +163 -0
  295. package/src/plugins/AttributionPlugin/index.ts +702 -0
  296. package/src/plugins/index.ts +1 -0
  297. package/src/quality.ts +1 -0
  298. package/src/renderOrder.ts +3 -0
  299. package/src/scene.test.ts +164 -0
  300. package/src/scene.ts +127 -0
  301. package/src/shaders/index.ts +1 -0
  302. package/src/solar.test.ts +81 -0
  303. package/src/solar.ts +101 -0
  304. package/src/source.ts +80 -0
  305. package/src/stats.ts +102 -0
  306. package/src/tasks/computeVertexNormalsAsync.ts +15 -0
  307. package/src/tasks/constructPolygonBatchedFeature.ts +34 -0
  308. package/src/tasks/constructPolylineBatchedFeature.ts +27 -0
  309. package/src/tasks/constructQuantizedMeshTerrainMesh.ts +24 -0
  310. package/src/tasks/constructTerrainMesh.ts +25 -0
  311. package/src/tasks/getImageDataFromBlob.ts +13 -0
  312. package/src/tasks/getImageDataFromImageBitmap.ts +12 -0
  313. package/src/tasks/parseMvtTile.ts +22 -0
  314. package/src/tasks/queueTask.ts +19 -0
  315. package/src/tasks/toCreasedNormalsAsync.ts +18 -0
  316. package/src/tasks/upsampleQuantizedMeshTerrainMesh.ts +44 -0
  317. package/src/tasks/upsampleTerrainMesh.ts +39 -0
  318. package/src/texture.ts +19 -0
  319. package/src/textures.ts +13 -0
  320. package/src/tileTexture/CompositeShader.snapshot.test.ts +59 -0
  321. package/src/tileTexture/CompositeShader.test.ts +168 -0
  322. package/src/tileTexture/CompositeShader.ts +53 -0
  323. package/src/tileTexture/SlotPlanner.test.ts +105 -0
  324. package/src/tileTexture/SlotPlanner.ts +102 -0
  325. package/src/tileTexture/TileTextureCache.test.ts +227 -0
  326. package/src/tileTexture/TileTextureCache.ts +192 -0
  327. package/src/tileTexture/TileTextureCompositor.test.ts +260 -0
  328. package/src/tileTexture/TileTextureCompositor.ts +421 -0
  329. package/src/tileTexture/__snapshots__/CompositeShader.snapshot.test.ts.snap +2649 -0
  330. package/src/tileTexture/index.ts +8 -0
  331. package/src/tileTexture/types.ts +150 -0
  332. package/src/type/index.ts +261 -0
  333. package/src/uniforms.ts +20 -0
  334. package/src/utils/arraysEqual.ts +9 -0
  335. package/src/utils/blendModes.ts +80 -0
  336. package/src/utils/geometry.ts +53 -0
  337. package/src/utils/hillshadeNormalMapGenerator.ts +193 -0
  338. package/src/utils/index.ts +8 -0
  339. package/src/utils/object.test.ts +14 -0
  340. package/src/utils/object.ts +7 -0
  341. package/src/utils/replacer.test.ts +42 -0
  342. package/src/utils/replacer.ts +89 -0
  343. package/src/utils/screen.ts +29 -0
  344. package/src/utils/textureFragmentIndex.test.ts +224 -0
  345. package/src/utils/textureFragmentIndex.ts +97 -0
  346. package/src/utils/worker.ts +3 -0
  347. package/src/vite-env.d.ts +2 -0
  348. package/src/worker/index.ts +13 -0
  349. package/src/worker/tasks/computeVertexNormals.ts +15 -0
  350. package/src/worker/tasks/toCreasedNormals.ts +22 -0
@@ -0,0 +1,36 @@
1
+ import sdfTextFragmentShader from "@shaders/glsl/sdfText.frag.glsl";
2
+ import sdfTextVertexShader from "@shaders/glsl/sdfText.vert.glsl";
3
+ import type { WebGLProgramParametersWithUniforms } from "three";
4
+
5
+ import type { SdfTextBaseMutates, SdfTextBaseState } from "./types";
6
+
7
+ /**
8
+ * Transform shader with sdfText base modifications.
9
+ *
10
+ * SdfText uses custom ShaderMaterial shaders. This function:
11
+ * 1. Sets the vertex/fragment shader sources
12
+ * 2. Sets defines based on state (USE_RTE)
13
+ * 3. Assigns uniform refs via mutates.updateUniforms()
14
+ */
15
+ export const transformShader = (
16
+ shader: WebGLProgramParametersWithUniforms,
17
+ state: SdfTextBaseState,
18
+ mutates: SdfTextBaseMutates,
19
+ ): void => {
20
+ // Set shaders — sdfText always uses the same shader pair
21
+ shader.vertexShader = sdfTextVertexShader;
22
+ shader.fragmentShader = sdfTextFragmentShader;
23
+
24
+ // Set defines based on state
25
+ shader.defines ??= {};
26
+
27
+ if (state.useRTE) {
28
+ shader.defines.USE_RTE = 1;
29
+ }
30
+ if (state.useMsdf) {
31
+ shader.defines.USE_MSDF = 1;
32
+ }
33
+
34
+ // Assign uniform refs to shader.uniforms via mutates
35
+ mutates.updateUniforms(shader.uniforms, state);
36
+ };
@@ -0,0 +1,118 @@
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import { DEFAULT_BASE_STATE, updateState } from "./state";
4
+ import { sdfRadiusFor } from "./types";
5
+
6
+ describe("sdfTextBaseEnhancer / state", () => {
7
+ describe("updateState", () => {
8
+ it("initializes state from props with defaults", () => {
9
+ const state = updateState({ fontSize: 24 }, DEFAULT_BASE_STATE);
10
+ expect(state.fontSize).toBe(24);
11
+ expect(state.center).toEqual([0.5, 0.0]);
12
+ expect(state.sizeInMeters).toBe(true);
13
+ });
14
+
15
+ it("preserves immutable fields (useRTE) from currentState", () => {
16
+ const currentState = { ...DEFAULT_BASE_STATE, useRTE: true };
17
+ const state = updateState({ useRTE: false }, currentState);
18
+ expect(state.useRTE).toBe(true);
19
+ });
20
+
21
+ it("updates color from hex to RGB tuple", () => {
22
+ const state = updateState({ color: 0xff0000 }, DEFAULT_BASE_STATE);
23
+ expect(state.color.getHex()).toBe(0xff0000);
24
+ });
25
+
26
+ it("updates fontSize", () => {
27
+ const state = updateState({ fontSize: 32 }, DEFAULT_BASE_STATE);
28
+ expect(state.fontSize).toBe(32);
29
+ });
30
+
31
+ it("updates center", () => {
32
+ const state = updateState({ center: [0.0, 0.5] }, DEFAULT_BASE_STATE);
33
+ expect(state.center).toEqual([0.0, 0.5]);
34
+ });
35
+
36
+ it("updates sizeInMeters", () => {
37
+ const state = updateState({ sizeInMeters: true }, DEFAULT_BASE_STATE);
38
+ expect(state.sizeInMeters).toBe(true);
39
+ });
40
+
41
+ it("updates addHeight", () => {
42
+ const state = updateState({ addHeight: 100 }, DEFAULT_BASE_STATE);
43
+ expect(state.addHeight).toBe(100);
44
+ });
45
+
46
+ it("updates offsetDepth", () => {
47
+ const state = updateState({ offsetDepth: false }, DEFAULT_BASE_STATE);
48
+ expect(state.offsetDepth).toBe(false);
49
+ });
50
+
51
+ it("converts outlineWidth using the current quality's range (SDF default)", () => {
52
+ const state = updateState({ outlineWidth: 2.0 }, DEFAULT_BASE_STATE);
53
+ expect(state.outlineWidth).toBeCloseTo(
54
+ 2.0 / sdfRadiusFor(DEFAULT_BASE_STATE.useMsdf),
55
+ );
56
+ });
57
+
58
+ it("updates outlineColor from hex", () => {
59
+ const state = updateState({ outlineColor: 0x00ff00 }, DEFAULT_BASE_STATE);
60
+ expect(state.outlineColor.getHex()).toBe(0x00ff00);
61
+ });
62
+
63
+ it("updates outlineOpacity", () => {
64
+ const state = updateState({ outlineOpacity: 0.5 }, DEFAULT_BASE_STATE);
65
+ expect(state.outlineOpacity).toBe(0.5);
66
+ });
67
+
68
+ it("updates showBackground", () => {
69
+ const state = updateState({ showBackground: true }, DEFAULT_BASE_STATE);
70
+ expect(state.showBackground).toBe(true);
71
+ });
72
+
73
+ it("updates backgroundColor from hex", () => {
74
+ const state = updateState(
75
+ { backgroundColor: 0x0000ff },
76
+ DEFAULT_BASE_STATE,
77
+ );
78
+ expect(state.backgroundColor.getHex()).toBe(0x0000ff);
79
+ });
80
+
81
+ it("updates backgroundOutlineColor from hex", () => {
82
+ const state = updateState(
83
+ { backgroundOutlineColor: 0xffff00 },
84
+ DEFAULT_BASE_STATE,
85
+ );
86
+ expect(state.backgroundOutlineColor.getHex()).toBe(0xffff00);
87
+ });
88
+
89
+ it("updates backgroundOutlineWidth", () => {
90
+ const state = updateState(
91
+ { backgroundOutlineWidth: 0.5 },
92
+ DEFAULT_BASE_STATE,
93
+ );
94
+ expect(state.backgroundOutlineWidth).toBe(0.5);
95
+ });
96
+
97
+ it("updates pickable", () => {
98
+ const state = updateState({ pickable: true }, DEFAULT_BASE_STATE);
99
+ expect(state.pickable).toBe(true);
100
+ });
101
+
102
+ it("updates depthTest", () => {
103
+ const state = updateState({ depthTest: false }, DEFAULT_BASE_STATE);
104
+ expect(state.depthTest).toBe(false);
105
+ });
106
+
107
+ it("falls back to currentState for missing props", () => {
108
+ const currentState = {
109
+ ...DEFAULT_BASE_STATE,
110
+ fontSize: 42,
111
+ center: [1, 2] as [number, number],
112
+ };
113
+ const state = updateState({}, currentState);
114
+ expect(state.fontSize).toBe(42);
115
+ expect(state.center).toEqual([1, 2]);
116
+ });
117
+ });
118
+ });
@@ -0,0 +1,107 @@
1
+ import { Color } from "three";
2
+
3
+ import {
4
+ sdfRadiusFor,
5
+ type SdfTextBaseProps,
6
+ type SdfTextBaseState,
7
+ } from "./types";
8
+
9
+ const hexToColor = (hex: number): Color => {
10
+ return new Color().setHex(hex);
11
+ };
12
+
13
+ export const DEFAULT_BASE_PROPS: Required<
14
+ Omit<SdfTextBaseProps, "atlasTexture" | "rtcCenter">
15
+ > = {
16
+ useRTE: false,
17
+ useMsdf: false,
18
+ color: 0xffffff,
19
+ opacity: 1.0,
20
+ fontSize: 16.0,
21
+ center: [0.5, 0.0],
22
+ sizeInMeters: true,
23
+ addHeight: 0.0,
24
+ offsetDepth: true,
25
+ outlineWidth: 0,
26
+ outlineColor: 0x000000,
27
+ outlineOpacity: 1.0,
28
+ showBackground: false,
29
+ backgroundColor: 0xff0000,
30
+ backgroundOutlineColor: 0xff0000,
31
+ backgroundOutlineWidth: 0.1,
32
+ pickable: false,
33
+ depthTest: true,
34
+ transparent: true,
35
+ };
36
+
37
+ /** Default state derived from DEFAULT_BASE_PROPS */
38
+ export const DEFAULT_BASE_STATE: SdfTextBaseState = {
39
+ useRTE: DEFAULT_BASE_PROPS.useRTE,
40
+ useMsdf: DEFAULT_BASE_PROPS.useMsdf,
41
+ color: hexToColor(DEFAULT_BASE_PROPS.color),
42
+ opacity: DEFAULT_BASE_PROPS.opacity,
43
+ fontSize: DEFAULT_BASE_PROPS.fontSize,
44
+ center: DEFAULT_BASE_PROPS.center,
45
+ sizeInMeters: DEFAULT_BASE_PROPS.sizeInMeters,
46
+ addHeight: DEFAULT_BASE_PROPS.addHeight,
47
+ offsetDepth: DEFAULT_BASE_PROPS.offsetDepth,
48
+ outlineWidth:
49
+ DEFAULT_BASE_PROPS.outlineWidth / sdfRadiusFor(DEFAULT_BASE_PROPS.useMsdf),
50
+ outlineColor: hexToColor(DEFAULT_BASE_PROPS.outlineColor),
51
+ outlineOpacity: DEFAULT_BASE_PROPS.outlineOpacity,
52
+ showBackground: DEFAULT_BASE_PROPS.showBackground,
53
+ backgroundColor: hexToColor(DEFAULT_BASE_PROPS.backgroundColor),
54
+ backgroundOutlineColor: hexToColor(DEFAULT_BASE_PROPS.backgroundOutlineColor),
55
+ backgroundOutlineWidth: DEFAULT_BASE_PROPS.backgroundOutlineWidth,
56
+ pickable: DEFAULT_BASE_PROPS.pickable,
57
+ depthTest: DEFAULT_BASE_PROPS.depthTest,
58
+ transparent: DEFAULT_BASE_PROPS.transparent,
59
+ };
60
+
61
+ /**
62
+ * Update mutable state from props.
63
+ * Props override currentState values; missing props fall back to currentState.
64
+ * Pass DEFAULT_BASE_STATE as currentState for initial mount.
65
+ */
66
+ export const updateState = (
67
+ props: SdfTextBaseProps,
68
+ currentState: SdfTextBaseState,
69
+ ): SdfTextBaseState => {
70
+ return {
71
+ // Immutable after mount
72
+ useRTE: currentState.useRTE,
73
+ useMsdf: currentState.useMsdf,
74
+ // Mutable
75
+ color:
76
+ props.color !== undefined ? hexToColor(props.color) : currentState.color,
77
+ opacity: props.opacity ?? currentState.opacity,
78
+ fontSize: props.fontSize ?? currentState.fontSize,
79
+ center: props.center ?? currentState.center,
80
+ sizeInMeters: props.sizeInMeters ?? currentState.sizeInMeters,
81
+ addHeight: props.addHeight ?? currentState.addHeight,
82
+ offsetDepth: props.offsetDepth ?? currentState.offsetDepth,
83
+ outlineWidth:
84
+ props.outlineWidth !== undefined
85
+ ? props.outlineWidth / sdfRadiusFor(currentState.useMsdf)
86
+ : currentState.outlineWidth,
87
+ outlineColor:
88
+ props.outlineColor !== undefined
89
+ ? hexToColor(props.outlineColor)
90
+ : currentState.outlineColor,
91
+ outlineOpacity: props.outlineOpacity ?? currentState.outlineOpacity,
92
+ showBackground: props.showBackground ?? currentState.showBackground,
93
+ backgroundColor:
94
+ props.backgroundColor !== undefined
95
+ ? hexToColor(props.backgroundColor)
96
+ : currentState.backgroundColor,
97
+ backgroundOutlineColor:
98
+ props.backgroundOutlineColor !== undefined
99
+ ? hexToColor(props.backgroundOutlineColor)
100
+ : currentState.backgroundOutlineColor,
101
+ backgroundOutlineWidth:
102
+ props.backgroundOutlineWidth ?? currentState.backgroundOutlineWidth,
103
+ pickable: props.pickable ?? currentState.pickable,
104
+ depthTest: props.depthTest ?? currentState.depthTest,
105
+ transparent: props.transparent ?? currentState.transparent,
106
+ };
107
+ };
@@ -0,0 +1,184 @@
1
+ import { atlasRangePx } from "@navaramap/font";
2
+ import type { Color, DataTexture, Matrix4, Vector2, Vector3 } from "three";
3
+
4
+ import type { UniformValue } from "../../../types";
5
+ import type { Mutates } from "../../MaterialEnhancer";
6
+
7
+ /** Pixel range covered by a quality's atlas distance field; defines how
8
+ * outline-width pixels translate to a distance-value delta. SDF (`useMsdf=false`)
9
+ * uses the classic 35 px radius from `sdf_glyph_renderer`; MSDF uses
10
+ * `MSDF_RANGE_PX` (8 px). See [`atlasRangePx`] in `@navaramap/font`. */
11
+ export const sdfRadiusFor = (useMsdf: boolean): number => atlasRangePx(useMsdf);
12
+
13
+ /**
14
+ * Props for the sdfText base enhancer.
15
+ */
16
+ export type SdfTextBaseProps = {
17
+ // Immutable after mount
18
+ useRTE?: boolean;
19
+ /** When `true` the fragment shader samples the atlas as 4-channel MTSDF
20
+ * (median of RGB + true SDF in alpha) instead of single-channel R8. */
21
+ useMsdf?: boolean;
22
+
23
+ // Mutable state
24
+ color?: number; // hex color
25
+ opacity?: number;
26
+ fontSize?: number;
27
+ center?: [number, number];
28
+ sizeInMeters?: boolean;
29
+ addHeight?: number;
30
+ offsetDepth?: boolean;
31
+ outlineWidth?: number; // raw width, converted in state via sdfRadiusFor(useMsdf)
32
+ outlineColor?: number; // hex
33
+ outlineOpacity?: number;
34
+ showBackground?: boolean;
35
+ backgroundColor?: number; // hex
36
+ backgroundOutlineColor?: number; // hex
37
+ backgroundOutlineWidth?: number;
38
+ pickable?: boolean;
39
+
40
+ // Material properties (set directly on material, not via uniforms)
41
+ depthTest?: boolean;
42
+ transparent?: boolean;
43
+
44
+ // External uniform refs / values (may change over time)
45
+ rtcCenter?: [number, number, number];
46
+ atlasTexture?: UniformValue<DataTexture | null>;
47
+ };
48
+
49
+ /**
50
+ * Immutable state snapshot for the sdfText base enhancer.
51
+ */
52
+ export type SdfTextBaseState = Readonly<{
53
+ // Immutable after mount
54
+ useRTE: boolean;
55
+ useMsdf: boolean;
56
+
57
+ // Mutable
58
+ color: Color;
59
+ opacity: number;
60
+ fontSize: number;
61
+ center: [number, number];
62
+ sizeInMeters: boolean;
63
+ addHeight: number;
64
+ offsetDepth: boolean;
65
+ outlineWidth: number; // pre-converted: raw / sdfRadiusFor(useMsdf)
66
+ outlineColor: Color;
67
+ outlineOpacity: number;
68
+ showBackground: boolean;
69
+ backgroundColor: Color;
70
+ backgroundOutlineColor: Color;
71
+ backgroundOutlineWidth: number;
72
+ pickable: boolean;
73
+
74
+ // Material properties
75
+ depthTest: boolean;
76
+ transparent: boolean;
77
+ }>;
78
+
79
+ /**
80
+ * Mutable references (uniforms) for the sdfText base enhancer.
81
+ * These are shared references with shader.uniforms.
82
+ * Internal type - not exposed externally.
83
+ */
84
+ export type SdfTextBaseRefs = {
85
+ uColor: UniformValue<Color>;
86
+ uOpacity: UniformValue<number>;
87
+ uFontSize: UniformValue<number>;
88
+ uCenter: UniformValue<Vector2>;
89
+ uSizeInMeters: UniformValue<boolean>;
90
+ uAddHeight: UniformValue<number>;
91
+ uOffsetDepth: UniformValue<boolean>;
92
+ uSdfThreshold: UniformValue<number>;
93
+ uOutlineWidth: UniformValue<number>;
94
+ uOutlineColor: UniformValue<Color>;
95
+ uOutlineOpacity: UniformValue<number>;
96
+ uShowBackground: UniformValue<boolean>;
97
+ uBackgroundColor: UniformValue<Color>;
98
+ uBackgroundOutlineColor: UniformValue<Color>;
99
+ uBackgroundOutlineWidth: UniformValue<number>;
100
+ uFovRad: UniformValue<number>;
101
+ uScreenHeightPx: UniformValue<number>;
102
+ uFarPlane: UniformValue<number>;
103
+ uTextWidth: UniformValue<number>;
104
+ uTextHeight: UniformValue<number>;
105
+ uBgYBounds: UniformValue<Vector2>;
106
+ uRTCCenter: UniformValue<Vector3>;
107
+ uRTCCenterView: UniformValue<Vector3>;
108
+ uEyeRTELow: UniformValue<Vector3>;
109
+ uEyeRTEHigh: UniformValue<Vector3>;
110
+ nvr_uBatchId: UniformValue<number>;
111
+ nvr_uPickable: UniformValue<number>;
112
+ uAtlas: UniformValue<DataTexture | null>;
113
+ /** COLRv1 RGBA atlas. `null` when the font has no color glyphs. */
114
+ uColorAtlas: UniformValue<DataTexture | null>;
115
+ /** Current SDF atlas pixel dimensions; updated when the Rust atlas grows. */
116
+ uSdfAtlasSize: UniformValue<Vector2>;
117
+ /** Current color atlas pixel dimensions; updated when the color atlas grows. */
118
+ uColorAtlasSize: UniformValue<Vector2>;
119
+
120
+ // Conditional RTE/RTC position uniforms
121
+ uRTEPositionLOW?: UniformValue<Vector3>;
122
+ uRTEPositionHIGH?: UniformValue<Vector3>;
123
+ uRTCPosition?: UniformValue<Vector3>;
124
+ };
125
+
126
+ export type SdfTextBaseUniforms = Partial<SdfTextBaseRefs>;
127
+
128
+ /**
129
+ * Mutation functions for the sdfText base enhancer.
130
+ */
131
+ export type SdfTextBaseMutates = Mutates<
132
+ SdfTextBaseState,
133
+ SdfTextBaseUniforms,
134
+ {
135
+ /**
136
+ * Update per-frame camera uniforms (FOV, screen height, far plane, RTE eye).
137
+ */
138
+ updatePerFrame: (
139
+ fovRad: number,
140
+ screenHeightPx: number,
141
+ farPlane: number,
142
+ cameraX: number,
143
+ cameraY: number,
144
+ cameraZ: number,
145
+ viewMatrix: Matrix4,
146
+ state: SdfTextBaseState,
147
+ ) => void;
148
+ /**
149
+ * Update text dimension uniforms after text shaping.
150
+ */
151
+ updateTextDimensions: (
152
+ textWidth: number,
153
+ textHeight: number,
154
+ bgMinY: number,
155
+ bgMaxY: number,
156
+ ) => void;
157
+ /**
158
+ * Set the SDF atlas texture external ref.
159
+ */
160
+ setAtlasTexture: (texture: UniformValue<DataTexture | null>) => void;
161
+ /**
162
+ * Set the COLRv1 color atlas texture external ref.
163
+ */
164
+ setColorAtlasTexture: (texture: UniformValue<DataTexture | null>) => void;
165
+ /**
166
+ * Sync the atlas-size uniforms with the currently-bound atlas textures.
167
+ * Cheap to call every frame; the shader divides glyph pixel rects by these
168
+ * to derive UVs, so this is how atlas resizes propagate to existing meshes.
169
+ */
170
+ updateAtlasSizes: () => void;
171
+ /**
172
+ * Update position uniforms (RTE or RTC).
173
+ */
174
+ setPosition: (
175
+ position: Float32Array | { high: Float32Array; low: Float32Array },
176
+ useRTE: boolean,
177
+ rtcCenter?: [number, number, number],
178
+ ) => void;
179
+ /**
180
+ * Set the batch ID uniform (immutable after mount, but needed for batch creation).
181
+ */
182
+ setBatchId: (batchId: number) => void;
183
+ }
184
+ >;
@@ -0,0 +1,100 @@
1
+ /**
2
+ * SdfText Material Enhancer - Currently just the Base enhancer
3
+ *
4
+ * This module provides sdfText material functionality using the base enhancer.
5
+ * Structured for future composition if additional enhancers are needed.
6
+ */
7
+
8
+ import type { MaterialEnhancer } from "../MaterialEnhancer";
9
+
10
+ import {
11
+ createSdfTextBaseEnhancer,
12
+ type SdfTextBaseMutates,
13
+ type SdfTextBaseProps,
14
+ type SdfTextBaseState,
15
+ type SupportedMaterial,
16
+ } from "./sdfTextBaseEnhancer";
17
+
18
+ /**
19
+ * Props for the sdfText material enhancer.
20
+ * Currently just wraps the base props, but structured for future composition.
21
+ */
22
+ export type SdfTextMaterialProps = {
23
+ base?: SdfTextBaseProps;
24
+ };
25
+
26
+ // Shaders this enhancer supports (custom ShaderMaterial via the "shader" shader name)
27
+ const AVAILABLE_SHADERS = ["shader"] as const;
28
+ type AVAILABLE_SHADERS = typeof AVAILABLE_SHADERS;
29
+
30
+ /**
31
+ * Factory function to create the sdfText material enhancer.
32
+ *
33
+ * This creates a new enhancer instance with its own internal state.
34
+ *
35
+ * @param material - The Three.js ShaderMaterial to enhance
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const material = new ShaderMaterial({ transparent: true });
40
+ * const enhancer = createSdfTextMaterialEnhancer(material);
41
+ *
42
+ * // Mount with base props
43
+ * enhancer.mount({
44
+ * base: { color: 0xffffff, fontSize: 16, useRTE: true },
45
+ * });
46
+ *
47
+ * // Get state directly via states() - refresh after updates
48
+ * const state = enhancer.states();
49
+ *
50
+ * // Update per-frame via mutates()
51
+ * const mutates = enhancer.mutates();
52
+ * mutates.updatePerFrame(fov, screenHeight, farPlane, camX, camY, camZ, state);
53
+ *
54
+ * // Update props (then call states() again to get fresh state)
55
+ * enhancer.update({ base: { color: 0xff0000 } });
56
+ *
57
+ * // Use transformShader for onBeforeCompile
58
+ * material.onBeforeCompile = enhancer.transformShader;
59
+ * material.customProgramCacheKey = enhancer.programCacheKey;
60
+ * ```
61
+ */
62
+ export function createSdfTextMaterialEnhancer(
63
+ material: SupportedMaterial,
64
+ ): MaterialEnhancer<
65
+ SupportedMaterial,
66
+ SdfTextMaterialProps,
67
+ SdfTextBaseState,
68
+ SdfTextBaseMutates,
69
+ AVAILABLE_SHADERS
70
+ > {
71
+ const baseEnhancer = createSdfTextBaseEnhancer(material);
72
+
73
+ return {
74
+ material,
75
+ availableShaders: AVAILABLE_SHADERS,
76
+
77
+ transformShader: (shader) => {
78
+ baseEnhancer.transformShader(shader);
79
+ },
80
+
81
+ mount: (props) => {
82
+ baseEnhancer.mount(props.base ?? {});
83
+ },
84
+
85
+ update: (props) => {
86
+ if (props.base) {
87
+ baseEnhancer.update(props.base);
88
+ }
89
+ },
90
+
91
+ states: () => baseEnhancer.states(),
92
+
93
+ mutates: () => baseEnhancer.mutates(),
94
+
95
+ programCacheKey: () => baseEnhancer.programCacheKey(),
96
+ };
97
+ }
98
+
99
+ // Re-export types for convenience
100
+ export type { SdfTextBaseMutates, SdfTextBaseProps, SdfTextBaseState };
@@ -0,0 +1,7 @@
1
+ export {
2
+ createShadowMapDepthEnhancer,
3
+ type ShadowMapDepthMutates,
4
+ type ShadowMapDepthProps,
5
+ type ShadowMapDepthState,
6
+ type SupportedMaterial as ShadowMapDepthSupportedMaterial,
7
+ } from "./shadowMapDepthEnhancer";
@@ -0,0 +1,97 @@
1
+ import { defaults } from "lodash-es";
2
+ import type { WebGLProgramParametersWithUniforms } from "three";
3
+ import invariant from "tiny-invariant";
4
+
5
+ import type { MaterialEnhancer } from "../../MaterialEnhancer";
6
+
7
+ import { AVAILABLE_SHADERS, type SupportedMaterial } from "./material";
8
+ import { createShadowMapDepthMutates } from "./mutates";
9
+ import { transformShader } from "./shader";
10
+ import {
11
+ DEFAULT_SHADOW_MAP_DEPTH_PROPS,
12
+ DEFAULT_SHADOW_MAP_DEPTH_STATE,
13
+ updateState,
14
+ } from "./state";
15
+ import type {
16
+ ShadowMapDepthMutates,
17
+ ShadowMapDepthProps,
18
+ ShadowMapDepthState,
19
+ } from "./types";
20
+
21
+ /**
22
+ * Factory function to create a shadow map depth enhancer.
23
+ *
24
+ * This enhancer handles shadow map depth shader injection.
25
+ * It's designed to be used with customDepthMaterial for shadow map generation.
26
+ *
27
+ * @param material - The Three.js material to enhance
28
+ */
29
+ export function createShadowMapDepthEnhancer(
30
+ material: SupportedMaterial,
31
+ ): MaterialEnhancer<
32
+ SupportedMaterial,
33
+ ShadowMapDepthProps,
34
+ ShadowMapDepthState,
35
+ ShadowMapDepthMutates,
36
+ typeof AVAILABLE_SHADERS
37
+ > {
38
+ // Internal state - immutable, always replaced as a whole
39
+ let state: ShadowMapDepthState | null = null;
40
+ // Internal mutates object (refs are external, set via props)
41
+ let mutates: ShadowMapDepthMutates | null = null;
42
+
43
+ return {
44
+ material,
45
+ availableShaders: AVAILABLE_SHADERS,
46
+
47
+ transformShader: (shader: WebGLProgramParametersWithUniforms): void => {
48
+ invariant(
49
+ state && mutates,
50
+ "mount() must be called before transformShader",
51
+ );
52
+ transformShader(shader, state, mutates);
53
+ },
54
+
55
+ mount: (props: ShadowMapDepthProps): void => {
56
+ const mergedProps = defaults({}, props, DEFAULT_SHADOW_MAP_DEPTH_PROPS);
57
+ state = updateState(mergedProps, DEFAULT_SHADOW_MAP_DEPTH_STATE);
58
+ // Create mutates
59
+ mutates = createShadowMapDepthMutates();
60
+ mutates.update(state);
61
+ },
62
+
63
+ update: (props: ShadowMapDepthProps): void => {
64
+ invariant(state && mutates, "mount() must be called before update");
65
+ state = updateState(props, state);
66
+ mutates.update(state);
67
+ },
68
+
69
+ states: (): ShadowMapDepthState => {
70
+ invariant(state, "mount() must be called before states");
71
+ return state;
72
+ },
73
+
74
+ mutates: (): ShadowMapDepthMutates => {
75
+ invariant(mutates, "mount() must be called before mutates");
76
+ return mutates;
77
+ },
78
+
79
+ programCacheKey: (): string => {
80
+ invariant(state, "mount() must be called before programCacheKey");
81
+ // RTE is always enabled for this enhancer
82
+ return JSON.stringify({});
83
+ },
84
+ };
85
+ }
86
+
87
+ // Re-export public types
88
+ export type { ShadowMapDepthMutates, ShadowMapDepthProps, ShadowMapDepthState };
89
+
90
+ // Re-export SupportedMaterial
91
+ export type { SupportedMaterial } from "./material";
92
+
93
+ // Re-export marker types for composing enhancers
94
+ export {
95
+ SHADOW_MAP_DEPTH_SHADER_MARKERS,
96
+ createShadowMapDepthShaderReplacer,
97
+ } from "./markers";
@@ -0,0 +1,10 @@
1
+ import { type ShaderMarkers, createShaderReplacer } from "../../ShaderReplacer";
2
+
3
+ export const SHADOW_MAP_DEPTH_SHADER_MARKERS = {
4
+ vertex: {},
5
+ fragment: {},
6
+ } as const satisfies ShaderMarkers;
7
+
8
+ export function createShadowMapDepthShaderReplacer(source: string) {
9
+ return createShaderReplacer<typeof SHADOW_MAP_DEPTH_SHADER_MARKERS>(source);
10
+ }
@@ -0,0 +1,31 @@
1
+ import type {
2
+ MeshBasicMaterial,
3
+ MeshLambertMaterial,
4
+ MeshPhongMaterial,
5
+ MeshPhysicalMaterial,
6
+ MeshStandardMaterial,
7
+ } from "three";
8
+
9
+ import type { ShaderName } from "../../MaterialEnhancer";
10
+
11
+ /**
12
+ * Material types that can be enhanced by this enhancer.
13
+ * Supports all standard mesh materials for depth/shadow rendering.
14
+ */
15
+ export type SupportedMaterial =
16
+ | MeshBasicMaterial
17
+ | MeshLambertMaterial
18
+ | MeshPhongMaterial
19
+ | MeshStandardMaterial
20
+ | MeshPhysicalMaterial;
21
+
22
+ /**
23
+ * Shader types that this enhancer can transform.
24
+ */
25
+ export const AVAILABLE_SHADERS = [
26
+ "basic",
27
+ "lambert",
28
+ "phong",
29
+ "standard",
30
+ "physical",
31
+ ] satisfies ShaderName[];