@aguacerowx/react-native 0.0.29 → 0.0.31

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 (403) hide show
  1. package/README.md +126 -126
  2. package/aguacerowx-react-native.podspec +38 -38
  3. package/android/build/.transforms/42e9b8fa82d77a1c205db5bf0d0ed519/results.bin +1 -0
  4. package/android/build/.transforms/42e9b8fa82d77a1c205db5bf0d0ed519/transformed/classes/classes_dex/classes.dex +0 -0
  5. package/android/build/.transforms/c8ab78b63f2cc835ac936d58e29a17ab/results.bin +1 -0
  6. package/android/build/.transforms/c8ab78b63f2cc835ac936d58e29a17ab/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/aguacerowx/reactnative/AguaceroPackage.dex +0 -0
  7. package/android/build/.transforms/c8ab78b63f2cc835ac936d58e29a17ab/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/aguacerowx/reactnative/BuildConfig.dex +0 -0
  8. package/android/build/.transforms/c8ab78b63f2cc835ac936d58e29a17ab/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/aguacerowx/reactnative/GridRenderLayer$VertexInfo.dex +0 -0
  9. package/android/build/.transforms/c8ab78b63f2cc835ac936d58e29a17ab/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/aguacerowx/reactnative/GridRenderLayer.dex +0 -0
  10. package/android/build/.transforms/c8ab78b63f2cc835ac936d58e29a17ab/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/aguacerowx/reactnative/GridRenderLayerView.dex +0 -0
  11. package/android/build/.transforms/c8ab78b63f2cc835ac936d58e29a17ab/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/aguacerowx/reactnative/GridRenderManager.dex +0 -0
  12. package/android/build/.transforms/c8ab78b63f2cc835ac936d58e29a17ab/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/aguacerowx/reactnative/InspectorModule.dex +0 -0
  13. package/android/build/.transforms/c8ab78b63f2cc835ac936d58e29a17ab/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/aguacerowx/reactnative/ShaderUtils.dex +0 -0
  14. package/android/build/.transforms/c8ab78b63f2cc835ac936d58e29a17ab/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/aguacerowx/reactnative/WeatherFrameProcessorModule.dex +0 -0
  15. package/android/build/.transforms/c8ab78b63f2cc835ac936d58e29a17ab/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/facebook/react/viewmanagers/GridRenderLayerManagerDelegate.dex +0 -0
  16. package/android/build/.transforms/c8ab78b63f2cc835ac936d58e29a17ab/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/facebook/react/viewmanagers/GridRenderLayerManagerInterface.dex +0 -0
  17. package/android/build/.transforms/c8ab78b63f2cc835ac936d58e29a17ab/transformed/bundleLibRuntimeToDirDebug/desugar_graph.bin +0 -0
  18. package/android/build/generated/source/buildConfig/debug/com/aguacerowx/reactnative/BuildConfig.java +10 -0
  19. package/android/build/generated/source/codegen/java/com/facebook/react/viewmanagers/GridRenderLayerManagerDelegate.java +43 -0
  20. package/android/build/generated/source/codegen/java/com/facebook/react/viewmanagers/GridRenderLayerManagerInterface.java +22 -0
  21. package/android/build/generated/source/codegen/jni/AguaceroWxReactNativeSpec-generated.cpp +22 -0
  22. package/android/build/generated/source/codegen/jni/AguaceroWxReactNativeSpec.h +24 -0
  23. package/android/build/generated/source/codegen/jni/CMakeLists.txt +28 -0
  24. package/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/AguaceroWxReactNativeSpecJSI-generated.cpp +17 -0
  25. package/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/AguaceroWxReactNativeSpecJSI.h +19 -0
  26. package/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/ComponentDescriptors.cpp +22 -0
  27. package/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/ComponentDescriptors.h +24 -0
  28. package/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/EventEmitters.cpp +16 -0
  29. package/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/EventEmitters.h +23 -0
  30. package/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/Props.cpp +62 -0
  31. package/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/Props.h +40 -0
  32. package/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/ShadowNodes.cpp +17 -0
  33. package/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/ShadowNodes.h +32 -0
  34. package/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/States.cpp +16 -0
  35. package/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/States.h +20 -0
  36. package/android/build/generated/source/codegen/schema.json +1 -0
  37. package/android/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml +8 -0
  38. package/android/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/output-metadata.json +18 -0
  39. package/android/build/intermediates/aar_metadata/debug/writeDebugAarMetadata/aar-metadata.properties +6 -0
  40. package/android/build/intermediates/annotation_processor_list/debug/javaPreCompileDebug/annotationProcessors.json +1 -0
  41. package/android/build/intermediates/compile_library_classes_jar/debug/bundleLibCompileToJarDebug/classes.jar +0 -0
  42. package/android/build/intermediates/compile_r_class_jar/debug/generateDebugRFile/R.jar +0 -0
  43. package/android/build/intermediates/compile_symbol_list/debug/generateDebugRFile/R.txt +4 -0
  44. package/android/build/intermediates/compiled_local_resources/debug/compileDebugLibraryResources/out/raw_debug_fragment_shader.glsl.flat +0 -0
  45. package/android/build/intermediates/compiled_local_resources/debug/compileDebugLibraryResources/out/raw_debug_vertex_shader.glsl.flat +0 -0
  46. package/android/build/intermediates/compiled_local_resources/debug/compileDebugLibraryResources/out/raw_fragment_shader.glsl.flat +0 -0
  47. package/android/build/intermediates/compiled_local_resources/debug/compileDebugLibraryResources/out/raw_vertex_shader.glsl.flat +0 -0
  48. package/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +5 -0
  49. package/android/build/intermediates/incremental/debug/packageDebugResources/merger.xml +2 -0
  50. package/android/build/intermediates/incremental/mergeDebugAssets/merger.xml +2 -0
  51. package/android/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +2 -0
  52. package/android/build/intermediates/incremental/mergeDebugShaders/merger.xml +2 -0
  53. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/AguaceroPackage.class +0 -0
  54. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/BuildConfig.class +0 -0
  55. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/GridRenderLayer$VertexInfo.class +0 -0
  56. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/GridRenderLayer.class +0 -0
  57. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/GridRenderLayerView.class +0 -0
  58. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/GridRenderManager.class +0 -0
  59. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/InspectorModule.class +0 -0
  60. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/ShaderUtils.class +0 -0
  61. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/WeatherFrameProcessorModule.class +0 -0
  62. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/facebook/react/viewmanagers/GridRenderLayerManagerDelegate.class +0 -0
  63. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/facebook/react/viewmanagers/GridRenderLayerManagerInterface.class +0 -0
  64. package/android/build/intermediates/local_only_symbol_list/debug/parseDebugLocalResources/R-def.txt +6 -0
  65. package/android/build/intermediates/manifest_merge_blame_file/debug/processDebugManifest/manifest-merger-blame-debug-report.txt +8 -0
  66. package/android/build/intermediates/merged_manifest/debug/processDebugManifest/AndroidManifest.xml +8 -0
  67. package/android/build/intermediates/navigation_json/debug/extractDeepLinksDebug/navigation.json +1 -0
  68. package/android/build/intermediates/nested_resources_validation_report/debug/generateDebugResources/nestedResourcesValidationReport.txt +1 -0
  69. package/android/build/intermediates/packaged_res/debug/packageDebugResources/raw/debug_fragment_shader.glsl +13 -0
  70. package/android/build/intermediates/packaged_res/debug/packageDebugResources/raw/debug_vertex_shader.glsl +13 -0
  71. package/android/build/intermediates/packaged_res/debug/packageDebugResources/raw/fragment_shader.glsl +162 -0
  72. package/android/build/intermediates/packaged_res/debug/packageDebugResources/raw/vertex_shader.glsl +20 -0
  73. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/AguaceroPackage.class +0 -0
  74. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/BuildConfig.class +0 -0
  75. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/GridRenderLayer$VertexInfo.class +0 -0
  76. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/GridRenderLayer.class +0 -0
  77. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/GridRenderLayerView.class +0 -0
  78. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/GridRenderManager.class +0 -0
  79. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/InspectorModule.class +0 -0
  80. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/ShaderUtils.class +0 -0
  81. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/WeatherFrameProcessorModule.class +0 -0
  82. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/facebook/react/viewmanagers/GridRenderLayerManagerDelegate.class +0 -0
  83. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/facebook/react/viewmanagers/GridRenderLayerManagerInterface.class +0 -0
  84. package/android/build/intermediates/runtime_library_classes_jar/debug/bundleLibRuntimeToJarDebug/classes.jar +0 -0
  85. package/android/build/intermediates/symbol_list_with_package_name/debug/generateDebugRFile/package-aware-r.txt +5 -0
  86. package/android/build/outputs/logs/manifest-merger-debug-report.txt +17 -0
  87. package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/GridRenderLayer$VertexInfo.class.uniqueId0 +0 -0
  88. package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/GridRenderLayer.class.uniqueId1 +0 -0
  89. package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/GridRenderLayerView.class.uniqueId2 +0 -0
  90. package/android/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin +0 -0
  91. package/android/build.gradle +107 -107
  92. package/android/src/main/AndroidManifest.xml +6 -6
  93. package/android/src/main/java/com/aguacerowx/reactnative/AguaceroPackage.java +33 -33
  94. package/android/src/main/java/com/aguacerowx/reactnative/GridRenderLayer.java +672 -672
  95. package/android/src/main/java/com/aguacerowx/reactnative/GridRenderLayerView.java +304 -304
  96. package/android/src/main/java/com/aguacerowx/reactnative/GridRenderManager.java +125 -125
  97. package/android/src/main/java/com/aguacerowx/reactnative/InspectorModule.java +71 -71
  98. package/android/src/main/java/com/aguacerowx/reactnative/ShaderUtils.java +106 -106
  99. package/android/src/main/java/com/aguacerowx/reactnative/WeatherFrameProcessorModule.java +151 -151
  100. package/android/src/main/res/raw/debug_fragment_shader.glsl +12 -12
  101. package/android/src/main/res/raw/debug_vertex_shader.glsl +12 -12
  102. package/android/src/main/res/raw/fragment_shader.glsl +161 -161
  103. package/android/src/main/res/raw/vertex_shader.glsl +19 -19
  104. package/index.js +2 -2
  105. package/ios/AguaceroPackage.m +18 -18
  106. package/ios/FragmentUniforms.swift +15 -15
  107. package/ios/GridRenderLayer.swift +986 -1043
  108. package/ios/GridRenderLayerBridge.swift +36 -37
  109. package/ios/GridRenderLayerManager.mm +157 -157
  110. package/ios/GridRenderLayerView.h +30 -30
  111. package/ios/GridRenderLayerView.m +216 -256
  112. package/ios/InspectorDataCache.swift +65 -65
  113. package/ios/InspectorModule.m +9 -9
  114. package/ios/InspectorModule.swift +63 -63
  115. package/ios/Shaders.metal +190 -190
  116. package/ios/WeatherFrameProcessorModule.m +15 -15
  117. package/ios/WeatherFrameProcessorModule.swift +103 -103
  118. package/lib/commonjs/README.md +126 -126
  119. package/lib/commonjs/aguacerowx-react-native.podspec +38 -38
  120. package/lib/commonjs/android/build/generated/source/buildConfig/debug/com/aguacerowx/reactnative/BuildConfig.java +10 -0
  121. package/lib/commonjs/android/build/generated/source/codegen/java/com/facebook/react/viewmanagers/GridRenderLayerManagerDelegate.java +43 -0
  122. package/lib/commonjs/android/build/generated/source/codegen/java/com/facebook/react/viewmanagers/GridRenderLayerManagerInterface.java +22 -0
  123. package/lib/commonjs/android/build/generated/source/codegen/jni/AguaceroWxReactNativeSpec-generated.cpp +22 -0
  124. package/lib/commonjs/android/build/generated/source/codegen/jni/AguaceroWxReactNativeSpec.h +24 -0
  125. package/lib/commonjs/android/build/generated/source/codegen/jni/CMakeLists.txt +28 -0
  126. package/lib/commonjs/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/AguaceroWxReactNativeSpecJSI-generated.cpp +17 -0
  127. package/lib/commonjs/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/AguaceroWxReactNativeSpecJSI.h +19 -0
  128. package/lib/commonjs/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/ComponentDescriptors.cpp +22 -0
  129. package/lib/commonjs/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/ComponentDescriptors.h +24 -0
  130. package/lib/commonjs/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/EventEmitters.cpp +16 -0
  131. package/lib/commonjs/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/EventEmitters.h +23 -0
  132. package/lib/commonjs/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/Props.cpp +62 -0
  133. package/lib/commonjs/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/Props.h +40 -0
  134. package/lib/commonjs/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/ShadowNodes.cpp +17 -0
  135. package/lib/commonjs/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/ShadowNodes.h +32 -0
  136. package/lib/commonjs/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/States.cpp +16 -0
  137. package/lib/commonjs/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/States.h +20 -0
  138. package/lib/commonjs/android/build/generated/source/codegen/schema.json +1 -0
  139. package/lib/commonjs/android/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml +8 -0
  140. package/lib/commonjs/android/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/output-metadata.json +18 -0
  141. package/lib/commonjs/android/build/intermediates/aar_metadata/debug/writeDebugAarMetadata/aar-metadata.properties +6 -0
  142. package/lib/commonjs/android/build/intermediates/annotation_processor_list/debug/javaPreCompileDebug/annotationProcessors.json +1 -0
  143. package/lib/commonjs/android/build/intermediates/compile_library_classes_jar/debug/bundleLibCompileToJarDebug/classes.jar +0 -0
  144. package/lib/commonjs/android/build/intermediates/compile_r_class_jar/debug/generateDebugRFile/R.jar +0 -0
  145. package/lib/commonjs/android/build/intermediates/compile_symbol_list/debug/generateDebugRFile/R.txt +4 -0
  146. package/lib/commonjs/android/build/intermediates/compiled_local_resources/debug/compileDebugLibraryResources/out/raw_debug_fragment_shader.glsl.flat +0 -0
  147. package/lib/commonjs/android/build/intermediates/compiled_local_resources/debug/compileDebugLibraryResources/out/raw_debug_vertex_shader.glsl.flat +0 -0
  148. package/lib/commonjs/android/build/intermediates/compiled_local_resources/debug/compileDebugLibraryResources/out/raw_fragment_shader.glsl.flat +0 -0
  149. package/lib/commonjs/android/build/intermediates/compiled_local_resources/debug/compileDebugLibraryResources/out/raw_vertex_shader.glsl.flat +0 -0
  150. package/lib/commonjs/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +5 -0
  151. package/lib/commonjs/android/build/intermediates/incremental/debug/packageDebugResources/merger.xml +2 -0
  152. package/lib/commonjs/android/build/intermediates/incremental/mergeDebugAssets/merger.xml +2 -0
  153. package/lib/commonjs/android/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +2 -0
  154. package/lib/commonjs/android/build/intermediates/incremental/mergeDebugShaders/merger.xml +2 -0
  155. package/lib/commonjs/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/AguaceroPackage.class +0 -0
  156. package/lib/commonjs/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/BuildConfig.class +0 -0
  157. package/lib/commonjs/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/GridRenderLayer$VertexInfo.class +0 -0
  158. package/lib/commonjs/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/GridRenderLayer.class +0 -0
  159. package/lib/commonjs/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/GridRenderLayerView.class +0 -0
  160. package/lib/commonjs/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/GridRenderManager.class +0 -0
  161. package/lib/commonjs/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/InspectorModule.class +0 -0
  162. package/lib/commonjs/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/ShaderUtils.class +0 -0
  163. package/lib/commonjs/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/WeatherFrameProcessorModule.class +0 -0
  164. package/lib/commonjs/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/facebook/react/viewmanagers/GridRenderLayerManagerDelegate.class +0 -0
  165. package/lib/commonjs/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/facebook/react/viewmanagers/GridRenderLayerManagerInterface.class +0 -0
  166. package/lib/commonjs/android/build/intermediates/local_only_symbol_list/debug/parseDebugLocalResources/R-def.txt +6 -0
  167. package/lib/commonjs/android/build/intermediates/manifest_merge_blame_file/debug/processDebugManifest/manifest-merger-blame-debug-report.txt +8 -0
  168. package/lib/commonjs/android/build/intermediates/merged_manifest/debug/processDebugManifest/AndroidManifest.xml +8 -0
  169. package/lib/commonjs/android/build/intermediates/navigation_json/debug/extractDeepLinksDebug/navigation.json +1 -0
  170. package/lib/commonjs/android/build/intermediates/nested_resources_validation_report/debug/generateDebugResources/nestedResourcesValidationReport.txt +1 -0
  171. package/lib/commonjs/android/build/intermediates/packaged_res/debug/packageDebugResources/raw/debug_fragment_shader.glsl +13 -0
  172. package/lib/commonjs/android/build/intermediates/packaged_res/debug/packageDebugResources/raw/debug_vertex_shader.glsl +13 -0
  173. package/lib/commonjs/android/build/intermediates/packaged_res/debug/packageDebugResources/raw/fragment_shader.glsl +162 -0
  174. package/lib/commonjs/android/build/intermediates/packaged_res/debug/packageDebugResources/raw/vertex_shader.glsl +20 -0
  175. package/lib/commonjs/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/AguaceroPackage.class +0 -0
  176. package/lib/commonjs/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/BuildConfig.class +0 -0
  177. package/lib/commonjs/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/GridRenderLayer$VertexInfo.class +0 -0
  178. package/lib/commonjs/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/GridRenderLayer.class +0 -0
  179. package/lib/commonjs/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/GridRenderLayerView.class +0 -0
  180. package/lib/commonjs/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/GridRenderManager.class +0 -0
  181. package/lib/commonjs/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/InspectorModule.class +0 -0
  182. package/lib/commonjs/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/ShaderUtils.class +0 -0
  183. package/lib/commonjs/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/WeatherFrameProcessorModule.class +0 -0
  184. package/lib/commonjs/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/facebook/react/viewmanagers/GridRenderLayerManagerDelegate.class +0 -0
  185. package/lib/commonjs/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/facebook/react/viewmanagers/GridRenderLayerManagerInterface.class +0 -0
  186. package/lib/commonjs/android/build/intermediates/runtime_library_classes_jar/debug/bundleLibRuntimeToJarDebug/classes.jar +0 -0
  187. package/lib/commonjs/android/build/intermediates/symbol_list_with_package_name/debug/generateDebugRFile/package-aware-r.txt +5 -0
  188. package/lib/commonjs/android/build/outputs/logs/manifest-merger-debug-report.txt +17 -0
  189. package/lib/commonjs/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/GridRenderLayer$VertexInfo.class.uniqueId0 +0 -0
  190. package/lib/commonjs/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/GridRenderLayer.class.uniqueId1 +0 -0
  191. package/lib/commonjs/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/GridRenderLayerView.class.uniqueId2 +0 -0
  192. package/lib/commonjs/android/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin +0 -0
  193. package/lib/commonjs/android/build.gradle +107 -107
  194. package/lib/commonjs/android/src/main/AndroidManifest.xml +6 -6
  195. package/lib/commonjs/android/src/main/java/com/aguacerowx/reactnative/AguaceroPackage.java +33 -33
  196. package/lib/commonjs/android/src/main/java/com/aguacerowx/reactnative/GridRenderLayer.java +672 -672
  197. package/lib/commonjs/android/src/main/java/com/aguacerowx/reactnative/GridRenderLayerView.java +304 -304
  198. package/lib/commonjs/android/src/main/java/com/aguacerowx/reactnative/GridRenderManager.java +125 -125
  199. package/lib/commonjs/android/src/main/java/com/aguacerowx/reactnative/InspectorModule.java +71 -71
  200. package/lib/commonjs/android/src/main/java/com/aguacerowx/reactnative/ShaderUtils.java +106 -106
  201. package/lib/commonjs/android/src/main/java/com/aguacerowx/reactnative/WeatherFrameProcessorModule.java +151 -151
  202. package/lib/commonjs/android/src/main/res/raw/debug_fragment_shader.glsl +12 -12
  203. package/lib/commonjs/android/src/main/res/raw/debug_vertex_shader.glsl +12 -12
  204. package/lib/commonjs/android/src/main/res/raw/fragment_shader.glsl +161 -161
  205. package/lib/commonjs/android/src/main/res/raw/vertex_shader.glsl +19 -19
  206. package/lib/commonjs/babel.config.js.map +1 -1
  207. package/lib/commonjs/index.js.map +1 -1
  208. package/lib/commonjs/ios/AguaceroPackage.m +18 -18
  209. package/lib/commonjs/ios/FragmentUniforms.swift +15 -15
  210. package/lib/commonjs/ios/GridRenderLayer.swift +986 -1043
  211. package/lib/commonjs/ios/GridRenderLayerBridge.swift +36 -37
  212. package/lib/commonjs/ios/GridRenderLayerManager.mm +157 -157
  213. package/lib/commonjs/ios/GridRenderLayerView.h +30 -30
  214. package/lib/commonjs/ios/GridRenderLayerView.m +216 -256
  215. package/lib/commonjs/ios/InspectorDataCache.swift +65 -65
  216. package/lib/commonjs/ios/InspectorModule.m +9 -9
  217. package/lib/commonjs/ios/InspectorModule.swift +63 -63
  218. package/lib/commonjs/ios/Shaders.metal +190 -190
  219. package/lib/commonjs/ios/WeatherFrameProcessorModule.m +15 -15
  220. package/lib/commonjs/ios/WeatherFrameProcessorModule.swift +103 -103
  221. package/lib/commonjs/package.json +72 -72
  222. package/lib/commonjs/react-native-builder-bob.config.js.map +1 -1
  223. package/lib/commonjs/scripts/compile-shaders.js.map +1 -1
  224. package/lib/commonjs/scripts/compile-shaders.sh +38 -38
  225. package/lib/commonjs/src/AguaceroContext.js.map +1 -1
  226. package/lib/commonjs/src/GridRenderLayer.js +0 -2
  227. package/lib/commonjs/src/GridRenderLayer.js.map +1 -1
  228. package/lib/commonjs/src/GridRenderLayerNativeComponent.js.map +1 -1
  229. package/lib/commonjs/src/MapManager.js +2 -2
  230. package/lib/commonjs/src/MapManager.js.map +1 -1
  231. package/lib/commonjs/src/MapRegistry.js.map +1 -1
  232. package/lib/commonjs/src/StyleApplicator.js +6 -6
  233. package/lib/commonjs/src/StyleApplicator.js.map +1 -1
  234. package/lib/commonjs/src/WeatherLayerManager.js +127 -79
  235. package/lib/commonjs/src/WeatherLayerManager.js.map +1 -1
  236. package/lib/commonjs/tsconfig.json +23 -23
  237. package/lib/module/README.md +126 -126
  238. package/lib/module/aguacerowx-react-native.podspec +38 -38
  239. package/lib/module/android/build/generated/source/buildConfig/debug/com/aguacerowx/reactnative/BuildConfig.java +10 -0
  240. package/lib/module/android/build/generated/source/codegen/java/com/facebook/react/viewmanagers/GridRenderLayerManagerDelegate.java +43 -0
  241. package/lib/module/android/build/generated/source/codegen/java/com/facebook/react/viewmanagers/GridRenderLayerManagerInterface.java +22 -0
  242. package/lib/module/android/build/generated/source/codegen/jni/AguaceroWxReactNativeSpec-generated.cpp +22 -0
  243. package/lib/module/android/build/generated/source/codegen/jni/AguaceroWxReactNativeSpec.h +24 -0
  244. package/lib/module/android/build/generated/source/codegen/jni/CMakeLists.txt +28 -0
  245. package/lib/module/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/AguaceroWxReactNativeSpecJSI-generated.cpp +17 -0
  246. package/lib/module/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/AguaceroWxReactNativeSpecJSI.h +19 -0
  247. package/lib/module/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/ComponentDescriptors.cpp +22 -0
  248. package/lib/module/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/ComponentDescriptors.h +24 -0
  249. package/lib/module/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/EventEmitters.cpp +16 -0
  250. package/lib/module/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/EventEmitters.h +23 -0
  251. package/lib/module/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/Props.cpp +62 -0
  252. package/lib/module/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/Props.h +40 -0
  253. package/lib/module/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/ShadowNodes.cpp +17 -0
  254. package/lib/module/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/ShadowNodes.h +32 -0
  255. package/lib/module/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/States.cpp +16 -0
  256. package/lib/module/android/build/generated/source/codegen/jni/react/renderer/components/AguaceroWxReactNativeSpec/States.h +20 -0
  257. package/lib/module/android/build/generated/source/codegen/schema.json +1 -0
  258. package/lib/module/android/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml +8 -0
  259. package/lib/module/android/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/output-metadata.json +18 -0
  260. package/lib/module/android/build/intermediates/aar_metadata/debug/writeDebugAarMetadata/aar-metadata.properties +6 -0
  261. package/lib/module/android/build/intermediates/annotation_processor_list/debug/javaPreCompileDebug/annotationProcessors.json +1 -0
  262. package/lib/module/android/build/intermediates/compile_library_classes_jar/debug/bundleLibCompileToJarDebug/classes.jar +0 -0
  263. package/lib/module/android/build/intermediates/compile_r_class_jar/debug/generateDebugRFile/R.jar +0 -0
  264. package/lib/module/android/build/intermediates/compile_symbol_list/debug/generateDebugRFile/R.txt +4 -0
  265. package/lib/module/android/build/intermediates/compiled_local_resources/debug/compileDebugLibraryResources/out/raw_debug_fragment_shader.glsl.flat +0 -0
  266. package/lib/module/android/build/intermediates/compiled_local_resources/debug/compileDebugLibraryResources/out/raw_debug_vertex_shader.glsl.flat +0 -0
  267. package/lib/module/android/build/intermediates/compiled_local_resources/debug/compileDebugLibraryResources/out/raw_fragment_shader.glsl.flat +0 -0
  268. package/lib/module/android/build/intermediates/compiled_local_resources/debug/compileDebugLibraryResources/out/raw_vertex_shader.glsl.flat +0 -0
  269. package/lib/module/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +5 -0
  270. package/lib/module/android/build/intermediates/incremental/debug/packageDebugResources/merger.xml +2 -0
  271. package/lib/module/android/build/intermediates/incremental/mergeDebugAssets/merger.xml +2 -0
  272. package/lib/module/android/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +2 -0
  273. package/lib/module/android/build/intermediates/incremental/mergeDebugShaders/merger.xml +2 -0
  274. package/lib/module/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/AguaceroPackage.class +0 -0
  275. package/lib/module/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/BuildConfig.class +0 -0
  276. package/lib/module/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/GridRenderLayer$VertexInfo.class +0 -0
  277. package/lib/module/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/GridRenderLayer.class +0 -0
  278. package/lib/module/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/GridRenderLayerView.class +0 -0
  279. package/lib/module/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/GridRenderManager.class +0 -0
  280. package/lib/module/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/InspectorModule.class +0 -0
  281. package/lib/module/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/ShaderUtils.class +0 -0
  282. package/lib/module/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/aguacerowx/reactnative/WeatherFrameProcessorModule.class +0 -0
  283. package/lib/module/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/facebook/react/viewmanagers/GridRenderLayerManagerDelegate.class +0 -0
  284. package/lib/module/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/facebook/react/viewmanagers/GridRenderLayerManagerInterface.class +0 -0
  285. package/lib/module/android/build/intermediates/local_only_symbol_list/debug/parseDebugLocalResources/R-def.txt +6 -0
  286. package/lib/module/android/build/intermediates/manifest_merge_blame_file/debug/processDebugManifest/manifest-merger-blame-debug-report.txt +8 -0
  287. package/lib/module/android/build/intermediates/merged_manifest/debug/processDebugManifest/AndroidManifest.xml +8 -0
  288. package/lib/module/android/build/intermediates/navigation_json/debug/extractDeepLinksDebug/navigation.json +1 -0
  289. package/lib/module/android/build/intermediates/nested_resources_validation_report/debug/generateDebugResources/nestedResourcesValidationReport.txt +1 -0
  290. package/lib/module/android/build/intermediates/packaged_res/debug/packageDebugResources/raw/debug_fragment_shader.glsl +13 -0
  291. package/lib/module/android/build/intermediates/packaged_res/debug/packageDebugResources/raw/debug_vertex_shader.glsl +13 -0
  292. package/lib/module/android/build/intermediates/packaged_res/debug/packageDebugResources/raw/fragment_shader.glsl +162 -0
  293. package/lib/module/android/build/intermediates/packaged_res/debug/packageDebugResources/raw/vertex_shader.glsl +20 -0
  294. package/lib/module/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/AguaceroPackage.class +0 -0
  295. package/lib/module/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/BuildConfig.class +0 -0
  296. package/lib/module/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/GridRenderLayer$VertexInfo.class +0 -0
  297. package/lib/module/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/GridRenderLayer.class +0 -0
  298. package/lib/module/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/GridRenderLayerView.class +0 -0
  299. package/lib/module/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/GridRenderManager.class +0 -0
  300. package/lib/module/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/InspectorModule.class +0 -0
  301. package/lib/module/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/ShaderUtils.class +0 -0
  302. package/lib/module/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/aguacerowx/reactnative/WeatherFrameProcessorModule.class +0 -0
  303. package/lib/module/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/facebook/react/viewmanagers/GridRenderLayerManagerDelegate.class +0 -0
  304. package/lib/module/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/facebook/react/viewmanagers/GridRenderLayerManagerInterface.class +0 -0
  305. package/lib/module/android/build/intermediates/runtime_library_classes_jar/debug/bundleLibRuntimeToJarDebug/classes.jar +0 -0
  306. package/lib/module/android/build/intermediates/symbol_list_with_package_name/debug/generateDebugRFile/package-aware-r.txt +5 -0
  307. package/lib/module/android/build/outputs/logs/manifest-merger-debug-report.txt +17 -0
  308. package/lib/module/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/GridRenderLayer$VertexInfo.class.uniqueId0 +0 -0
  309. package/lib/module/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/GridRenderLayer.class.uniqueId1 +0 -0
  310. package/lib/module/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/GridRenderLayerView.class.uniqueId2 +0 -0
  311. package/lib/module/android/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin +0 -0
  312. package/lib/module/android/build.gradle +107 -107
  313. package/lib/module/android/src/main/AndroidManifest.xml +6 -6
  314. package/lib/module/android/src/main/java/com/aguacerowx/reactnative/AguaceroPackage.java +33 -33
  315. package/lib/module/android/src/main/java/com/aguacerowx/reactnative/GridRenderLayer.java +672 -672
  316. package/lib/module/android/src/main/java/com/aguacerowx/reactnative/GridRenderLayerView.java +304 -304
  317. package/lib/module/android/src/main/java/com/aguacerowx/reactnative/GridRenderManager.java +125 -125
  318. package/lib/module/android/src/main/java/com/aguacerowx/reactnative/InspectorModule.java +71 -71
  319. package/lib/module/android/src/main/java/com/aguacerowx/reactnative/ShaderUtils.java +106 -106
  320. package/lib/module/android/src/main/java/com/aguacerowx/reactnative/WeatherFrameProcessorModule.java +151 -151
  321. package/lib/module/android/src/main/res/raw/debug_fragment_shader.glsl +12 -12
  322. package/lib/module/android/src/main/res/raw/debug_vertex_shader.glsl +12 -12
  323. package/lib/module/android/src/main/res/raw/fragment_shader.glsl +161 -161
  324. package/lib/module/android/src/main/res/raw/vertex_shader.glsl +19 -19
  325. package/lib/module/babel.config.js.map +1 -1
  326. package/lib/module/index.js.map +1 -1
  327. package/lib/module/ios/AguaceroPackage.m +18 -18
  328. package/lib/module/ios/FragmentUniforms.swift +15 -15
  329. package/lib/module/ios/GridRenderLayer.swift +986 -1043
  330. package/lib/module/ios/GridRenderLayerBridge.swift +36 -37
  331. package/lib/module/ios/GridRenderLayerManager.mm +157 -157
  332. package/lib/module/ios/GridRenderLayerView.h +30 -30
  333. package/lib/module/ios/GridRenderLayerView.m +216 -256
  334. package/lib/module/ios/InspectorDataCache.swift +65 -65
  335. package/lib/module/ios/InspectorModule.m +9 -9
  336. package/lib/module/ios/InspectorModule.swift +63 -63
  337. package/lib/module/ios/Shaders.metal +190 -190
  338. package/lib/module/ios/WeatherFrameProcessorModule.m +15 -15
  339. package/lib/module/ios/WeatherFrameProcessorModule.swift +103 -103
  340. package/lib/module/lib/commonjs/README.md +126 -126
  341. package/lib/module/lib/commonjs/aguacerowx-react-native.podspec +38 -38
  342. package/lib/module/lib/commonjs/android/build.gradle +108 -0
  343. package/lib/module/lib/commonjs/android/src/main/AndroidManifest.xml +7 -0
  344. package/lib/module/lib/commonjs/babel.config.js.map +1 -1
  345. package/lib/module/lib/commonjs/index.js.map +1 -1
  346. package/lib/module/lib/commonjs/ios/AguaceroPackage.m +19 -0
  347. package/lib/module/lib/commonjs/ios/FragmentUniforms.swift +16 -0
  348. package/lib/module/lib/commonjs/ios/GridRenderLayer.swift +986 -0
  349. package/lib/module/lib/commonjs/ios/GridRenderLayerBridge.swift +37 -0
  350. package/lib/module/lib/commonjs/ios/GridRenderLayerManager.mm +158 -0
  351. package/lib/module/lib/commonjs/ios/GridRenderLayerView.h +31 -0
  352. package/lib/module/lib/commonjs/ios/GridRenderLayerView.m +217 -0
  353. package/lib/module/lib/commonjs/ios/InspectorDataCache.swift +66 -0
  354. package/lib/module/lib/commonjs/ios/InspectorModule.m +10 -0
  355. package/lib/module/lib/commonjs/ios/InspectorModule.swift +64 -0
  356. package/lib/module/lib/commonjs/ios/Shaders.metal +191 -0
  357. package/lib/module/lib/commonjs/ios/WeatherFrameProcessorModule.m +16 -0
  358. package/lib/module/lib/commonjs/ios/WeatherFrameProcessorModule.swift +104 -0
  359. package/lib/module/lib/commonjs/ios/compiled-shaders/Shaders-device.metallib +0 -0
  360. package/lib/module/lib/commonjs/ios/compiled-shaders/Shaders-simulator.metallib +0 -0
  361. package/lib/module/lib/commonjs/ios/generated/AguaceroWxReactNativeSpec-generated.mm +0 -0
  362. package/lib/module/lib/commonjs/package.json +72 -72
  363. package/lib/module/lib/commonjs/react-native-builder-bob.config.js.map +1 -1
  364. package/lib/module/lib/commonjs/scripts/compile-shaders.js.map +1 -1
  365. package/lib/module/lib/commonjs/scripts/compile-shaders.sh +39 -0
  366. package/lib/module/lib/commonjs/src/AguaceroContext.js.map +1 -1
  367. package/lib/module/lib/commonjs/src/GridRenderLayer.js +0 -2
  368. package/lib/module/lib/commonjs/src/GridRenderLayer.js.map +1 -1
  369. package/lib/module/lib/commonjs/src/GridRenderLayerNativeComponent.js.map +1 -1
  370. package/lib/module/lib/commonjs/src/MapManager.js +2 -2
  371. package/lib/module/lib/commonjs/src/MapManager.js.map +1 -1
  372. package/lib/module/lib/commonjs/src/MapRegistry.js.map +1 -1
  373. package/lib/module/lib/commonjs/src/StyleApplicator.js +6 -6
  374. package/lib/module/lib/commonjs/src/StyleApplicator.js.map +1 -1
  375. package/lib/module/lib/commonjs/src/WeatherLayerManager.js +127 -79
  376. package/lib/module/lib/commonjs/src/WeatherLayerManager.js.map +1 -1
  377. package/lib/module/lib/commonjs/tsconfig.json +23 -23
  378. package/lib/module/package.json +72 -72
  379. package/lib/module/react-native-builder-bob.config.js.map +1 -1
  380. package/lib/module/scripts/compile-shaders.js.map +1 -1
  381. package/lib/module/scripts/compile-shaders.sh +38 -38
  382. package/lib/module/src/AguaceroContext.js.map +1 -1
  383. package/lib/module/src/GridRenderLayer.js +0 -2
  384. package/lib/module/src/GridRenderLayer.js.map +1 -1
  385. package/lib/module/src/GridRenderLayerNativeComponent.js.map +1 -1
  386. package/lib/module/src/MapManager.js +2 -2
  387. package/lib/module/src/MapManager.js.map +1 -1
  388. package/lib/module/src/MapRegistry.js.map +1 -1
  389. package/lib/module/src/StyleApplicator.js +6 -6
  390. package/lib/module/src/StyleApplicator.js.map +1 -1
  391. package/lib/module/src/WeatherLayerManager.js +127 -79
  392. package/lib/module/src/WeatherLayerManager.js.map +1 -1
  393. package/lib/module/tsconfig.json +23 -23
  394. package/lib/typescript/src/GridRenderLayer.d.ts.map +1 -1
  395. package/lib/typescript/src/WeatherLayerManager.d.ts.map +1 -1
  396. package/package.json +72 -72
  397. package/src/AguaceroContext.js +3 -3
  398. package/src/GridRenderLayer.js +215 -217
  399. package/src/GridRenderLayerNativeComponent.ts +15 -15
  400. package/src/MapManager.js +218 -218
  401. package/src/MapRegistry.js +34 -34
  402. package/src/StyleApplicator.js +240 -240
  403. package/src/WeatherLayerManager.js +1076 -1028
@@ -1,1043 +1,986 @@
1
- import Foundation
2
- import MapboxMaps
3
- import Metal
4
- import libzstd
5
- import simd
6
-
7
- // MARK: - Swift-only wrapper for CustomLayerHost conformance
8
- @objc internal final class GridRenderLayerHost: NSObject, CustomLayerHost {
9
- weak var layer: GridRenderLayer?
10
-
11
- init(layer: GridRenderLayer) {
12
- self.layer = layer
13
- super.init()
14
- }
15
-
16
- func renderingWillStart(_ metalDevice: MTLDevice, colorPixelFormat: UInt, depthStencilPixelFormat: UInt) {
17
- layer?.internalRenderingWillStart(metalDevice, colorPixelFormat: colorPixelFormat, depthStencilPixelFormat: depthStencilPixelFormat)
18
- }
19
-
20
- func render(_ parameters: CustomLayerRenderParameters, mtlCommandBuffer: MTLCommandBuffer, mtlRenderPassDescriptor: MTLRenderPassDescriptor) {
21
- layer?.internalRender(parameters, mtlCommandBuffer: mtlCommandBuffer, mtlRenderPassDescriptor: mtlRenderPassDescriptor)
22
- }
23
-
24
- func renderingWillEnd() {
25
- layer?.internalRenderingWillEnd()
26
- }
27
- }
28
-
29
- @objc(GridRenderLayer)
30
- public class GridRenderLayer: NSObject {
31
-
32
- // MARK: - Properties
33
-
34
- public var id: String
35
- @objc internal var hostWrapper: GridRenderLayerHost!
36
-
37
- // Metal objects
38
- private var device: MTLDevice!
39
- private var commandQueue: MTLCommandQueue!
40
- private var pipelineState: MTLRenderPipelineState!
41
- private var vertexBuffer: MTLBuffer?
42
- private var indexBuffer: MTLBuffer?
43
- private var dataTexture: MTLTexture?
44
- private var colormapTexture: MTLTexture?
45
- private var dataSamplerState: MTLSamplerState!
46
- private var colormapSamplerState: MTLSamplerState!
47
- private var isDataSamplerLinear: Bool = false
48
-
49
- private var pendingColormapUpdate: String?
50
- private var pendingDataUpdate: (data: String, nx: NSNumber, ny: NSNumber, scale: NSNumber, offset: NSNumber, missing: NSNumber, scaleType: String)?
51
- private var pendingGeometryUpdate: (corners: [String: Any], gridDef: [String: Any])?
52
-
53
- // Layer state
54
- private var indexCount: Int = 0
55
- private var uniforms = FragmentUniforms(
56
- opacity: 1.0,
57
- dataRange: SIMD2<Float>(0.0, 1.0),
58
- scale: 1.0,
59
- offset: 0.0,
60
- missingQuantized: 127.0,
61
- textureSize: SIMD2<Float>(0.0, 0.0),
62
- smoothing: 1,
63
- scaleType: 0,
64
- isPtype: 0,
65
- isMRMS: 0
66
- )
67
- private var isVisible = false
68
- private var pendingActiveFrameKey: String?
69
- private let inspectorCache = InspectorDataCache.shared
70
- private struct FrameMetadata {
71
- let texture: MTLTexture
72
- let scale: Float
73
- let offset: Float
74
- let missing: Float
75
- let scaleType: Int
76
- let nx: Float
77
- let ny: Float
78
- let filePath: String
79
- let originalScale: Float
80
- let originalOffset: Float
81
- }
82
- private var frameCache: [String: FrameMetadata] = [:]
83
- private let frameProcessingQueue = DispatchQueue(label: "com.aguacero.frame-processing", qos: .userInitiated, attributes: .concurrent)
84
- private let semaphore = DispatchSemaphore(value: 8)
85
-
86
- private struct VertexInfo {
87
- var mercX: Float
88
- var mercY: Float
89
- var texU: Float
90
- var texV: Float
91
- var index: UInt16
92
- }
93
- @objc
94
- public init(id: String) {
95
- self.id = id
96
- super.init()
97
- self.hostWrapper = GridRenderLayerHost(layer: self)
98
- print("🟢 [GridRenderLayer] Initialized with ID: \(id)")
99
- }
100
-
101
- @objc public func getHostWrapper() -> Any {
102
- return self.hostWrapper as Any
103
- }
104
-
105
- // MARK: - Public Methods (called from Manager)
106
-
107
- @objc public func setOpacity(value: Float) {
108
- self.uniforms.opacity = value
109
- print("🟢 [GridRenderLayer] Set opacity: \(value)")
110
- // ADD THIS: Force the map to repaint to show the opacity change immediately.
111
- NotificationCenter.default.post(name: NSNotification.Name("TriggerMapRepaint"), object: nil)
112
- }
113
-
114
- @objc public func setDataRange(value: [NSNumber]) {
115
- self.uniforms.dataRange = SIMD2<Float>(value[0].floatValue, value[1].floatValue)
116
- print("🟢 [GridRenderLayer] Set data range: \(value)")
117
- // ADD THIS: Force the map to repaint to show the data range change immediately.
118
- NotificationCenter.default.post(name: NSNotification.Name("TriggerMapRepaint"), object: nil)
119
- }
120
-
121
- @objc public func setSmoothing(value: Bool) {
122
- self.uniforms.smoothing = value ? 1 : 0
123
- print("🟢 [GridRenderLayer] Set smoothing: \(value)")
124
- // ADD THIS: Force the map to repaint to show the smoothing change immediately.
125
- NotificationCenter.default.post(name: NSNotification.Name("TriggerMapRepaint"), object: nil)
126
- }
127
-
128
- @objc(setIsMRMSWithIsMRMS:)
129
- public func setIsMRMS(isMRMS: Bool) {
130
- self.uniforms.isMRMS = isMRMS ? 1 : 0
131
- print("🟢 [GridRenderLayer] Set isMRMS: \(isMRMS)")
132
- NotificationCenter.default.post(name: NSNotification.Name("TriggerMapRepaint"), object: nil)
133
- }
134
-
135
- // ADD THIS METHOD
136
- @objc(setVariableWithVariable:)
137
- public func setVariable(variable: String) {
138
- let isPtypeVar = (variable == "ptypeRefl" || variable == "ptypeRate")
139
- self.uniforms.isPtype = isPtypeVar ? 1 : 0
140
- print("🟢 [GridRenderLayer] Set variable: \(variable), isPtype set to: \(self.uniforms.isPtype)")
141
- NotificationCenter.default.post(name: NSNotification.Name("TriggerMapRepaint"), object: nil)
142
- }
143
-
144
- @objc public func clear() {
145
- self.isVisible = false
146
- self.inspectorCache.clear()
147
- print("🟢 [GridRenderLayer] Cleared")
148
- }
149
-
150
- @objc public func updateDataParameters(scale: NSNumber, offset: NSNumber, missing: NSNumber, scaleType: NSNumber) { // ADD scaleType parameter
151
- // Update both the inspector cache AND the rendering uniforms
152
- self.uniforms.scale = scale.floatValue
153
- self.uniforms.offset = offset.floatValue
154
- self.uniforms.missingQuantized = missing.floatValue
155
- self.uniforms.scaleType = Int32(scaleType.intValue) // ADD THIS
156
-
157
- inspectorCache.update(
158
- data: inspectorCache.lastDecompressedData,
159
- nx: inspectorCache.nx,
160
- ny: inspectorCache.ny,
161
- scale: scale.floatValue,
162
- offset: offset.floatValue,
163
- missing: missing.floatValue,
164
- scaleType: scaleType.intValue // ADD THIS
165
- )
166
-
167
- print("🟢 [GridRenderLayer] Updated data parameters - scale: \(scale), offset: \(offset), missing: \(missing), scaleType: \(scaleType)")
168
- }
169
-
170
- @objc public func updateColormapTexture(colormapAsBase64: String) {
171
- guard let device = self.device else {
172
- pendingColormapUpdate = colormapAsBase64
173
- return
174
- }
175
- guard let data = Data(base64Encoded: colormapAsBase64) else { return }
176
- let textureDescriptor = MTLTextureDescriptor()
177
- textureDescriptor.pixelFormat = .rgba8Unorm
178
- textureDescriptor.width = 256
179
- textureDescriptor.height = 1
180
- textureDescriptor.usage = .shaderRead
181
- guard let texture = device.makeTexture(descriptor: textureDescriptor) else { return }
182
- texture.replace(
183
- region: MTLRegionMake2D(0, 0, 256, 1),
184
- mipmapLevel: 0,
185
- withBytes: (data as NSData).bytes,
186
- bytesPerRow: 256 * 4
187
- )
188
- self.colormapTexture = texture
189
- }
190
-
191
- @objc(clearGpuCache)
192
- public func clearGpuCache() {
193
- frameProcessingQueue.async { [weak self] in
194
- self?.frameCache.removeAll()
195
- }
196
- }
197
-
198
- private func processRawData(fileData: Data) -> Data? {
199
- guard let decompressedDeltas = self.decompressZstd(data: fileData) else {
200
- print("❌ [GridRenderLayer] Failed to decompress zstd data")
201
- return nil
202
- }
203
- let reconstructedData = self.reconstructData(decompressedDeltas: decompressedDeltas)
204
- let finalTextureBytes = self.transformData(finalData: reconstructedData)
205
- return finalTextureBytes
206
- }
207
-
208
- private func createTextureFromBytes(bytes: Data, nx: Int, ny: Int) -> MTLTexture? {
209
- guard let device = self.device else { return nil }
210
- let textureDescriptor = MTLTextureDescriptor()
211
- textureDescriptor.pixelFormat = .r8Unorm
212
- textureDescriptor.width = nx
213
- textureDescriptor.height = ny
214
- textureDescriptor.usage = .shaderRead
215
-
216
- guard let texture = device.makeTexture(descriptor: textureDescriptor) else { return nil }
217
- texture.replace(
218
- region: MTLRegionMake2D(0, 0, nx, ny),
219
- mipmapLevel: 0,
220
- withBytes: (bytes as NSData).bytes,
221
- bytesPerRow: nx
222
- )
223
- return texture
224
- }
225
-
226
- private func updateInspectorCache(filePath: String, nx: Int, ny: Int, scale: Float, offset: Float, missing: Float, scaleType: Int) {
227
- // This is now called from frameProcessingQueue, so we can do the work synchronously
228
- guard let fileData = try? Data(contentsOf: URL(fileURLWithPath: filePath)) else {
229
- print("❌ [Inspector] FATAL: Failed to read file data from path.")
230
- self.inspectorCache.clear()
231
- return
232
- }
233
- print("💡 [Inspector] 2. Successfully read \(fileData.count) bytes from file.")
234
-
235
- guard let decompressedDeltas = self.decompressZstd(data: fileData) else {
236
- print("❌ [Inspector] FATAL: Failed to decompress Zstd data.")
237
- self.inspectorCache.clear()
238
- return
239
- }
240
- print("💡 [Inspector] 3. Successfully decompressed data.")
241
-
242
- let reconstructedData = self.reconstructData(decompressedDeltas: decompressedDeltas)
243
- print("💡 [Inspector] 4. Reconstructed data with \(reconstructedData.count) bytes.")
244
-
245
- self.inspectorCache.update(
246
- data: reconstructedData,
247
- nx: nx,
248
- ny: ny,
249
- scale: scale,
250
- offset: offset,
251
- missing: missing,
252
- scaleType: scaleType
253
- )
254
-
255
- print("💡 [Inspector] 5. Cache updated successfully with scaleType=\(scaleType)")
256
- }
257
-
258
- @objc(setActiveFrameWithCacheKey:)
259
- public func setActiveFrame(cacheKey: String) {
260
- if let frame = frameCache[cacheKey] {
261
- print("⚡️ [GridRenderLayer] Cache HIT for key: \(cacheKey). Swapping texture.")
262
-
263
- self.dataTexture = frame.texture
264
- self.uniforms.scale = frame.scale
265
- self.uniforms.offset = frame.offset
266
- self.uniforms.missingQuantized = frame.missing
267
- self.uniforms.textureSize = SIMD2<Float>(frame.nx, frame.ny)
268
- self.uniforms.scaleType = Int32(frame.scaleType)
269
-
270
- self.isVisible = true
271
- self.pendingActiveFrameKey = nil
272
- NotificationCenter.default.post(name: NSNotification.Name("TriggerMapRepaint"), object: nil)
273
-
274
- // Update inspector cache on background thread since we already have the frame data
275
- frameProcessingQueue.async { [weak self] in
276
- self?.updateInspectorCache(
277
- filePath: frame.filePath,
278
- nx: Int(frame.nx),
279
- ny: Int(frame.ny),
280
- scale: frame.scale,
281
- offset: frame.offset,
282
- missing: frame.missing,
283
- scaleType: frame.scaleType
284
- )
285
- }
286
-
287
- } else {
288
- print("⚠️ [GridRenderLayer] setActiveFrame cache MISS for key: \(cacheKey). Will apply when primed.")
289
- self.pendingActiveFrameKey = cacheKey
290
- self.isVisible = false
291
- }
292
- }
293
- @objc(primeGpuCacheWithFrameInfo:)
294
- public func primeGpuCache(frameInfo: [String: [String: Any]]) {
295
- let group = DispatchGroup()
296
-
297
- if (frameInfo.count > 1) {
298
- print("🟡 [GridRenderLayer] Starting to prime \(frameInfo.count) textures with concurrent processing...")
299
- }
300
-
301
- for (cacheKey, info) in frameInfo {
302
- group.enter()
303
-
304
- frameProcessingQueue.async { [weak self] in
305
- guard let self = self else {
306
- group.leave()
307
- return
308
- }
309
-
310
- self.semaphore.wait()
311
- defer {
312
- self.semaphore.signal()
313
- group.leave()
314
- }
315
-
316
- if self.frameCache[cacheKey] != nil { return }
317
-
318
- guard let filePath = info["filePath"] as? String,
319
- let nx = info["nx"] as? NSNumber,
320
- let ny = info["ny"] as? NSNumber,
321
- let scale = info["scale"] as? NSNumber,
322
- let offset = info["offset"] as? NSNumber,
323
- let missing = info["missing"] as? NSNumber,
324
- let scaleTypeStr = info["scaleType"] as? String,
325
- let originalScale = info["originalScale"] as? NSNumber,
326
- let originalOffset = info["originalOffset"] as? NSNumber
327
- else {
328
- print("❌ [GridRenderLayer] Skipping prime for \(cacheKey), missing data.")
329
- return
330
- }
331
-
332
- // Process data OFF the main thread
333
- guard let fileData = try? Data(contentsOf: URL(fileURLWithPath: filePath)),
334
- let finalTextureBytes = self.processRawData(fileData: fileData)
335
- else {
336
- print("❌ [GridRenderLayer] Failed to process data for \(cacheKey)")
337
- return
338
- }
339
-
340
- // Create texture on main thread
341
- DispatchQueue.main.async { [weak self] in
342
- guard let self = self else { return }
343
-
344
- if let texture = self.createTextureFromBytes(bytes: finalTextureBytes, nx: nx.intValue, ny: ny.intValue) {
345
- let metadata = FrameMetadata(
346
- texture: texture,
347
- scale: scale.floatValue,
348
- offset: offset.floatValue,
349
- missing: missing.floatValue,
350
- scaleType: (scaleTypeStr == "sqrt") ? 1 : 0,
351
- nx: nx.floatValue,
352
- ny: ny.floatValue,
353
- filePath: filePath,
354
- originalScale: originalScale.floatValue,
355
- originalOffset: originalOffset.floatValue
356
- )
357
- self.frameCache[cacheKey] = metadata
358
-
359
- if let pendingKey = self.pendingActiveFrameKey, pendingKey == cacheKey {
360
- print("👍 [GridRenderLayer] The pending frame is now ready. Activating it.")
361
- self.setActiveFrame(cacheKey: pendingKey)
362
- }
363
- }
364
- }
365
- }
366
- }
367
-
368
- group.notify(queue: .main) {
369
- if (frameInfo.count > 1) {
370
- print("🎉 [GridRenderLayer] All \(frameInfo.count) frames have been processed and cached.")
371
- }
372
- }
373
- }
374
-
375
- @objc public func updateDataTexture(data: String, nx: NSNumber, ny: NSNumber, scale: NSNumber, offset: NSNumber, missing: NSNumber, scaleType: String) {
376
- print("🚀 [GridRenderLayer] FAST LANE: updateDataTexture called for initial frame...")
377
-
378
- let filePath = data
379
-
380
- frameProcessingQueue.async { [weak self] in
381
- guard let self = self else { return }
382
-
383
- guard let fileData = try? Data(contentsOf: URL(fileURLWithPath: filePath)),
384
- let finalTextureBytes = self.processRawData(fileData: fileData)
385
- else {
386
- print("❌ [GridRenderLayer] FAST LANE: Failed to process initial frame data.")
387
- return
388
- }
389
-
390
- DispatchQueue.main.async { [weak self] in
391
- guard let self = self, let texture = self.createTextureFromBytes(bytes: finalTextureBytes, nx: nx.intValue, ny: ny.intValue) else {
392
- return
393
- }
394
-
395
- self.dataTexture = texture
396
- self.uniforms.scale = scale.floatValue
397
- self.uniforms.offset = offset.floatValue
398
- self.uniforms.missingQuantized = missing.floatValue
399
- self.uniforms.scaleType = Int32((scaleType == "sqrt") ? 1 : 0)
400
- self.uniforms.textureSize = SIMD2<Float>(nx.floatValue, ny.floatValue)
401
-
402
- self.isVisible = true
403
- print("✅ [GridRenderLayer] FAST LANE: Initial frame processed and displayed.")
404
- NotificationCenter.default.post(name: NSNotification.Name("TriggerMapRepaint"), object: nil)
405
-
406
- self.updateInspectorCache(
407
- filePath: filePath,
408
- nx: nx.intValue,
409
- ny: ny.intValue,
410
- scale: scale.floatValue,
411
- offset: offset.floatValue,
412
- missing: missing.floatValue,
413
- scaleType: (scaleType == "sqrt") ? 1 : 0
414
- )
415
- }
416
- }
417
- }
418
-
419
- @objc public func updateGeometry(corners: [String: Any], gridDef: [String: Any]) {
420
- guard self.device != nil else {
421
- print("⚠️ [GridRenderLayer] Device not ready yet, storing geometry for later")
422
- pendingGeometryUpdate = (corners: corners, gridDef: gridDef)
423
- return
424
- }
425
-
426
- print(" Device is ready, processing geometry immediately")
427
-
428
- DispatchQueue.global(qos: .userInitiated).async {
429
- print(" 🔄 Generating geometry on background thread")
430
-
431
- var vertices: [Float] = []
432
- var indices: [UInt16] = []
433
-
434
- self.generateGeometryData(gridDef: gridDef, vertices: &vertices, indices: &indices)
435
-
436
- if vertices.isEmpty || indices.isEmpty {
437
- print("❌ [GridRenderLayer] No geometry generated")
438
- return
439
- }
440
-
441
- self.indexCount = indices.count
442
-
443
- DispatchQueue.main.async {
444
- print(" 🎨 Creating buffers on main thread")
445
-
446
- self.vertexBuffer = self.device.makeBuffer(bytes: vertices, length: vertices.count * MemoryLayout<Float>.size, options: [])
447
- self.indexBuffer = self.device.makeBuffer(bytes: indices, length: indices.count * MemoryLayout<UInt16>.size, options: [])
448
-
449
- print("🟢 [GridRenderLayer] Geometry updated: \(vertices.count/4) vertices, \(indices.count/3) triangles")
450
- print(" vertexBuffer: \(self.vertexBuffer != nil)")
451
- print(" indexBuffer: \(self.indexBuffer != nil)")
452
- print(" indexCount: \(self.indexCount)")
453
-
454
- NotificationCenter.default.post(name: NSNotification.Name("TriggerMapRepaint"), object: nil)
455
- }
456
- }
457
- }
458
-
459
- private func decompressZstd(data: Data) -> Data? {
460
- let decompressedSize = data.withUnsafeBytes { ptr in
461
- ZSTD_getFrameContentSize(ptr.baseAddress, data.count)
462
- }
463
-
464
- guard Int64(bitPattern: decompressedSize) > 0 else {
465
- print("❌ [GridRenderLayer] Could not determine decompressed size")
466
- return nil
467
- }
468
-
469
- var decompressedData = Data(count: Int(decompressedSize))
470
-
471
- let result = decompressedData.withUnsafeMutableBytes { decompressedPtr -> Int in
472
- data.withUnsafeBytes { compressedPtr -> Int in
473
- let returnValue = ZSTD_decompress(
474
- decompressedPtr.baseAddress,
475
- Int(decompressedSize),
476
- compressedPtr.baseAddress,
477
- data.count
478
- )
479
- return Int(returnValue)
480
- }
481
- }
482
-
483
- guard result > 0 && result == decompressedData.count else {
484
- if result > 0 {
485
- let size_t_result = size_t(result)
486
- if let errorName = ZSTD_getErrorName(size_t_result) {
487
- let errorString = String(cString: errorName)
488
- print("❌ [GridRenderLayer] Zstd decompression failed: \(errorString)")
489
- }
490
- }
491
- return nil
492
- }
493
- return decompressedData
494
- }
495
-
496
- // MARK: - Private Helper Methods
497
-
498
- private func reconstructData(decompressedDeltas: Data) -> Data {
499
- guard !decompressedDeltas.isEmpty else { return Data() }
500
- var reconstructedData = Data(count: decompressedDeltas.count)
501
- reconstructedData[0] = decompressedDeltas[0]
502
- for i in 1..<decompressedDeltas.count {
503
- reconstructedData[i] = UInt8(Int8(bitPattern: reconstructedData[i-1]) &+ Int8(bitPattern: decompressedDeltas[i]))
504
- }
505
- return reconstructedData
506
- }
507
-
508
- private func transformData(finalData: Data) -> Data {
509
- var transformedData = Data(count: finalData.count)
510
- for i in 0..<finalData.count {
511
- transformedData[i] = UInt8(Int16(Int8(bitPattern: finalData[i])) + 128)
512
- }
513
- return transformedData
514
- }
515
-
516
- private func isLCCType(gridDef: [String: Any]) -> Bool {
517
- if let type = gridDef["type"] as? String {
518
- return type == "lambert_conformal_conic"
519
- }
520
- return false
521
- }
522
-
523
- private func generateLCCGeometry(gridDef: [String: Any], vertices: inout [Float], indices: inout [UInt16]) {
524
- guard let gridParams = gridDef["grid_params"] as? [String: Any],
525
- let projParams = gridDef["proj_params"] as? [String: Any],
526
- let nx = gridParams["nx"] as? Int,
527
- let ny = gridParams["ny"] as? Int,
528
- let dx = gridParams["dx"] as? Double,
529
- let dy = gridParams["dy"] as? Double,
530
- let x_origin = gridParams["x_origin"] as? Double,
531
- let y_origin = gridParams["y_origin"] as? Double else {
532
- return
533
- }
534
-
535
- let subdivisions = 60
536
- let TILE_SIZE: Double = 512.0
537
-
538
- let x_min = x_origin
539
- let y_max = y_origin
540
- let x_max = x_origin + Double(nx - 1) * dx
541
- let y_min = y_origin + Double(ny - 1) * dy
542
-
543
- var vertexGrid: [[VertexInfo?]] = Array(repeating: Array(repeating: nil, count: subdivisions + 1), count: subdivisions + 1)
544
- var validVertexCount: UInt16 = 0
545
-
546
- // Generate vertices
547
- for row in 0...subdivisions {
548
- for col in 0...subdivisions {
549
- let t_x = Double(col) / Double(subdivisions)
550
- let t_y = Double(row) / Double(subdivisions)
551
-
552
- let proj_x = x_min + t_x * (x_max - x_min)
553
- let proj_y = y_max + t_y * (y_min - y_max)
554
-
555
- // Convert LCC projection coordinates to lat/lon
556
- if let (lon, lat) = lccToLonLat(i: proj_x, j: proj_y, gridDef: gridDef) {
557
- // Convert lat/lon to Mercator
558
- let mercX_normalized = (lon + 180.0) / 360.0
559
- let clampedLat = max(-85.05112878, min(85.05112878, lat))
560
- let sinLatitude = sin(clampedLat * .pi / 180.0)
561
- let mercY_normalized = 0.5 - log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * .pi)
562
-
563
- let mercX = mercX_normalized * TILE_SIZE
564
- let mercY = mercY_normalized * TILE_SIZE
565
-
566
- // Check for invalid values
567
- if !mercX.isFinite || !mercY.isFinite {
568
- vertexGrid[row][col] = nil
569
- continue
570
- }
571
-
572
- let tex_u = Float(t_x)
573
- let tex_v = Float(t_y)
574
-
575
- let vInfo = VertexInfo(
576
- mercX: Float(mercX),
577
- mercY: Float(mercY),
578
- texU: tex_u,
579
- texV: tex_v,
580
- index: validVertexCount
581
- )
582
-
583
- vertexGrid[row][col] = vInfo
584
-
585
- vertices.append(Float(mercX))
586
- vertices.append(Float(mercY))
587
- vertices.append(tex_u)
588
- vertices.append(tex_v)
589
-
590
- validVertexCount += 1
591
- } else {
592
- vertexGrid[row][col] = nil
593
- }
594
- }
595
- }
596
-
597
- if vertices.isEmpty {
598
- print("❌ [LCC Geometry] No valid vertices generated")
599
- return
600
- }
601
-
602
- // Generate indices
603
- for row in 0..<subdivisions {
604
- for col in 0..<subdivisions {
605
- guard let topLeft = vertexGrid[row][col],
606
- let topRight = vertexGrid[row][col + 1],
607
- let bottomLeft = vertexGrid[row + 1][col],
608
- let bottomRight = vertexGrid[row + 1][col + 1] else {
609
- continue
610
- }
611
-
612
- indices.append(topLeft.index)
613
- indices.append(bottomLeft.index)
614
- indices.append(topRight.index)
615
-
616
- indices.append(topRight.index)
617
- indices.append(bottomLeft.index)
618
- indices.append(bottomRight.index)
619
- }
620
- }
621
- }
622
-
623
- private func lccToLonLat(i: Double, j: Double, gridDef: [String: Any]) -> (lon: Double, lat: Double)? {
624
- guard let projParams = gridDef["proj_params"] as? [String: Any],
625
- let lat_0 = (projParams["lat_0"] as? NSNumber)?.doubleValue,
626
- let lon_0 = (projParams["lon_0"] as? NSNumber)?.doubleValue,
627
- let lat_1 = (projParams["lat_1"] as? NSNumber)?.doubleValue,
628
- let lat_2 = (projParams["lat_2"] as? NSNumber)?.doubleValue,
629
- let r_earth = (projParams["R"] as? NSNumber)?.doubleValue else {
630
- print("❌ [LCC Geometry] Failed to extract LCC parameters.")
631
- return nil
632
- }
633
-
634
- let π = Double.pi
635
- let toRad = π / 180.0
636
- let toDeg = 180.0 / π
637
-
638
- let lat1_rad = lat_1 * toRad
639
- let lat2_rad = lat_2 * toRad
640
- let lat0_rad = lat_0 * toRad
641
- let lon0_rad = lon_0 * toRad
642
-
643
- let n: Double
644
- if abs(lat_1 - lat_2) < 1e-10 {
645
- n = sin(lat1_rad)
646
- } else {
647
- n = log(cos(lat1_rad) / cos(lat2_rad)) / log(tan(π/4.0 + lat2_rad/2.0) / tan(π/4.0 + lat1_rad/2.0))
648
- }
649
-
650
- let F = cos(lat1_rad) * pow(tan(π/4.0 + lat1_rad/2.0), n) / n
651
- let rho_0 = r_earth * F * pow(tan(π/4.0 + lat0_rad/2.0), -n)
652
-
653
- let x = i
654
- let y = j
655
-
656
- let rho = sqrt(x * x + (rho_0 - y) * (rho_0 - y))
657
- if rho < 1e-10 {
658
- return (lon: lon_0, lat: lat_0)
659
- }
660
-
661
- let theta = atan2(x, rho_0 - y)
662
-
663
- let lon = lon0_rad + theta / n
664
- let lat = 2.0 * atan(pow(r_earth * F / rho, 1.0 / n)) - π/2.0
665
-
666
- let lonDeg = lon * toDeg
667
- let latDeg = lat * toDeg
668
-
669
- if !lonDeg.isFinite || !latDeg.isFinite {
670
- return nil
671
- }
672
-
673
- return (lon: lonDeg, lat: latDeg)
674
- }
675
-
676
- private func generateGeometryData(gridDef: [String: Any], vertices: inout [Float], indices: inout [UInt16]) {
677
- guard let gridParams = gridDef["grid_params"] as? [String: Any] else {
678
- print("❌ [generateGeometryData] No grid_params found")
679
- return
680
- }
681
-
682
- // Check grid type
683
- let isGFS = isGFSType(gridParams: gridParams)
684
- let isLCC = isLCCType(gridDef: gridDef)
685
-
686
- if isGFS {
687
- // GFS path remains unchanged
688
- let subdivisions = 120
689
- let verticesPerRow = (subdivisions * 3) + 1
690
- let TILE_SIZE: Double = 512.0
691
-
692
- for row in 0...subdivisions {
693
- for col in 0...(subdivisions * 3) {
694
- let v_interp = Float(row) / Float(subdivisions)
695
- let u_interp = Float(col) / Float(subdivisions)
696
- let lon = -540.0 + Double(u_interp) * 1080.0
697
- let lat = -90.0 + Double(v_interp) * 180.0
698
-
699
- let merc = lonLatToMercator(lon: lon, lat: lat, tileSize: TILE_SIZE)
700
- vertices.append(contentsOf: [merc.x, merc.y])
701
-
702
- let tex_u = Float((lon + 180.0) / 360.0)
703
- let tex_v = 1.0 - v_interp
704
- vertices.append(contentsOf: [tex_u, tex_v])
705
- }
706
- }
707
-
708
- for row in 0..<subdivisions {
709
- for col in 0..<(subdivisions * 3) {
710
- let tl = UInt16(row * verticesPerRow + col)
711
- let tr = tl + 1
712
- let bl = UInt16((row + 1) * verticesPerRow + col)
713
- let br = bl + 1
714
- indices.append(contentsOf: [tl, bl, tr, tr, bl, br])
715
- }
716
- }
717
- return
718
- }
719
-
720
- if isLCC {
721
- print("🗺️ [generateGeometryData] Using LCC projection path")
722
- generateLCCGeometry(gridDef: gridDef, vertices: &vertices, indices: &indices)
723
- return
724
- }
725
-
726
- // Generic Grid Path (MRMS, regional models, etc.)
727
- print("🗺️ [generateGeometryData] Using generic regional grid path")
728
-
729
- let nx = gridParams["nx"] as? Int ?? 0
730
- let ny = gridParams["ny"] as? Int ?? 0
731
- let lon_first = gridParams["lon_first"] as? Double ?? 0.0
732
- let lat_first = gridParams["lat_first"] as? Double ?? 90.0
733
- let dx = gridParams["dx_degrees"] as? Double ?? 0.0
734
- let dy = gridParams["dy_degrees"] as? Double ?? 0.0
735
- let lon_last = gridParams["lon_last"] as? Double ?? (lon_first + Double(nx - 1) * dx)
736
- let lat_last = gridParams["lat_last"] as? Double ?? (lat_first + Double(ny - 1) * dy)
737
-
738
- let lat_span = lat_last - lat_first
739
- let isSouthToNorth = lat_span > 0
740
-
741
- let data_lon_first_180 = lon_first > 180 ? lon_first - 360 : lon_first
742
- let data_lon_last_180 = lon_last > 180 ? lon_last - 360 : lon_last
743
- let data_lon_range = data_lon_last_180 - data_lon_first_180
744
-
745
- let subdivisions_x = 120
746
- let subdivisions_y = 60
747
- let verticesPerRow = subdivisions_x + 1
748
- let TILE_SIZE: Double = 512.0
749
-
750
- let worldCopies = (data_lon_range > 300) ? [-1, 0, 1] : [0]
751
-
752
- for world_copy in worldCopies {
753
- let vertexStartIndex = UInt16(vertices.count / 4)
754
- let lon_offset = Double(world_copy) * 360.0
755
-
756
- for row in 0...subdivisions_y {
757
- for col in 0...subdivisions_x {
758
- let v_interp = Float(row) / Float(subdivisions_y)
759
- let u_interp = Float(col) / Float(subdivisions_x)
760
-
761
- let vertex_lon = data_lon_first_180 + (Double(u_interp) * data_lon_range)
762
- let vertex_lat = lat_first + (Double(v_interp) * lat_span)
763
-
764
- let mercX_normalized = ((vertex_lon + lon_offset) + 180.0) / 360.0
765
- let clampedLat = max(-85.05112878, min(85.05112878, vertex_lat))
766
- let sinLatitude = sin(clampedLat * .pi / 180.0)
767
- let mercY_normalized = 0.5 - log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * .pi)
768
- let mercX = mercX_normalized * TILE_SIZE
769
- let mercY = mercY_normalized * TILE_SIZE
770
-
771
- vertices.append(contentsOf: [Float(mercX), Float(mercY)])
772
-
773
- let tex_u = u_interp
774
- let tex_v = isSouthToNorth ? (1.0 - v_interp) : v_interp
775
-
776
- vertices.append(contentsOf: [tex_u, tex_v])
777
- }
778
- }
779
-
780
- for row in 0..<UInt16(subdivisions_y) {
781
- for col in 0..<UInt16(subdivisions_x) {
782
- let tl = vertexStartIndex + row * UInt16(verticesPerRow) + col
783
- let tr = tl + 1
784
- let bl = vertexStartIndex + (row + 1) * UInt16(verticesPerRow) + col
785
- let br = bl + 1
786
-
787
- if isSouthToNorth {
788
- indices.append(contentsOf: [tl, bl, tr, tr, bl, br])
789
- } else {
790
- indices.append(contentsOf: [tl, tr, bl, bl, tr, br])
791
- }
792
- }
793
- }
794
- }
795
- }
796
-
797
- private func isGFSType(gridParams: [String: Any]) -> Bool {
798
- return (gridParams["lon_first"] as? Double) == 0.0 &&
799
- abs((gridParams["lat_first"] as? Double) ?? -1) == 90.0
800
- }
801
-
802
- private func lonLatToMercator(lon: Double, lat: Double, tileSize: Double) -> (x: Float, y: Float) {
803
- let mercX_normalized = (lon + 180.0) / 360.0
804
- let clampedLat = max(-85.05112878, min(85.05112878, lat))
805
- let sinLatitude = sin(clampedLat * .pi / 180.0)
806
- let mercY_normalized = 0.5 - log((1.0 + sinLatitude) / (1.0 - sinLatitude)) / (4.0 * .pi)
807
-
808
- return (x: Float(mercX_normalized * tileSize), y: Float(mercY_normalized * tileSize))
809
- }
810
-
811
- // MARK: - Internal methods for CustomLayerHost (called by wrapper)
812
-
813
- internal func internalRenderingWillStart(_ metalDevice: MTLDevice, colorPixelFormat: UInt, depthStencilPixelFormat: UInt) {
814
- print("🟢 [GridRenderLayer] renderingWillStart called")
815
- self.device = metalDevice
816
- self.commandQueue = metalDevice.makeCommandQueue()
817
-
818
- let bundle = Bundle(for: GridRenderLayer.self)
819
-
820
- // Determine if we're running on simulator or device
821
- #if targetEnvironment(simulator)
822
- let metallibName = "Shaders-simulator"
823
- #else
824
- let metallibName = "Shaders-device"
825
- #endif
826
-
827
- // Try to load pre-compiled metallib for the current platform
828
- let defaultLibrary: MTLLibrary?
829
- if let metallibUrl = bundle.url(forResource: metallibName, withExtension: "metallib"),
830
- let library = try? metalDevice.makeLibrary(URL: metallibUrl) {
831
- print("✅ [GridRenderLayer] Loaded pre-compiled metallib (\(metallibName))")
832
- defaultLibrary = library
833
- }
834
- // Fall back to compiling from .metal source (for development with npm link)
835
- else if let metalUrl = bundle.url(forResource: "Shaders", withExtension: "metal"),
836
- let source = try? String(contentsOf: metalUrl),
837
- let library = try? metalDevice.makeLibrary(source: source, options: nil) {
838
- print("✅ [GridRenderLayer] Compiled Metal shader from source")
839
- defaultLibrary = library
840
- }
841
- // Neither worked
842
- else {
843
- print("❌ [GridRenderLayer] Could not find or compile Metal shaders")
844
- print(" Bundle path: \(bundle.bundlePath)")
845
- return
846
- }
847
-
848
- guard let library = defaultLibrary else {
849
- print("❌ [GridRenderLayer] Failed to create Metal library")
850
- return
851
- }
852
-
853
- let vertexFunction = library.makeFunction(name: "vertex_main")
854
- let fragmentFunction = library.makeFunction(name: "fragment_main")
855
-
856
- // Set up vertex descriptor
857
- let vertexDescriptor = MTLVertexDescriptor()
858
- vertexDescriptor.attributes[0].format = .float2 // position (x, y)
859
- vertexDescriptor.attributes[0].offset = 0
860
- vertexDescriptor.attributes[0].bufferIndex = 0
861
-
862
- vertexDescriptor.attributes[1].format = .float2 // texCoord (u, v)
863
- vertexDescriptor.attributes[1].offset = MemoryLayout<Float>.size * 2
864
- vertexDescriptor.attributes[1].bufferIndex = 0
865
-
866
- vertexDescriptor.layouts[0].stride = MemoryLayout<Float>.size * 4 // 2 floats for pos + 2 for texCoord
867
- vertexDescriptor.layouts[0].stepFunction = .perVertex
868
-
869
- let pipelineDescriptor = MTLRenderPipelineDescriptor()
870
- pipelineDescriptor.vertexDescriptor = vertexDescriptor
871
- pipelineDescriptor.vertexFunction = vertexFunction
872
- pipelineDescriptor.fragmentFunction = fragmentFunction
873
-
874
- pipelineDescriptor.colorAttachments[0].pixelFormat = MTLPixelFormat(rawValue: colorPixelFormat) ?? .bgra8Unorm
875
- pipelineDescriptor.depthAttachmentPixelFormat = MTLPixelFormat(rawValue: depthStencilPixelFormat) ?? .depth32Float_stencil8
876
- pipelineDescriptor.stencilAttachmentPixelFormat = MTLPixelFormat(rawValue: depthStencilPixelFormat) ?? .depth32Float_stencil8
877
-
878
- pipelineDescriptor.colorAttachments[0].isBlendingEnabled = true
879
- pipelineDescriptor.colorAttachments[0].rgbBlendOperation = .add
880
- pipelineDescriptor.colorAttachments[0].alphaBlendOperation = .add
881
- pipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = .sourceAlpha
882
- pipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .sourceAlpha
883
- pipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = .oneMinusSourceAlpha
884
- pipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .oneMinusSourceAlpha
885
-
886
- do {
887
- self.pipelineState = try metalDevice.makeRenderPipelineState(descriptor: pipelineDescriptor)
888
- } catch {
889
- print("❌ [GridRenderLayer] Failed to create pipeline state: \(error)")
890
- return
891
- }
892
-
893
- let dataSamplerDesc = MTLSamplerDescriptor()
894
- dataSamplerDesc.minFilter = .nearest
895
- dataSamplerDesc.magFilter = .nearest
896
- self.dataSamplerState = metalDevice.makeSamplerState(descriptor: dataSamplerDesc)
897
-
898
- let colormapSamplerDesc = MTLSamplerDescriptor()
899
- colormapSamplerDesc.minFilter = .nearest
900
- colormapSamplerDesc.magFilter = .nearest
901
- colormapSamplerDesc.sAddressMode = .clampToEdge
902
- self.colormapSamplerState = metalDevice.makeSamplerState(descriptor: colormapSamplerDesc)
903
-
904
- print("🟢 [GridRenderLayer] Metal setup complete")
905
-
906
- // Process any pending updates that came in before Metal was ready
907
- if let pendingGeometry = pendingGeometryUpdate {
908
- print("🟡 [GridRenderLayer] Processing pending geometry update")
909
- updateGeometry(corners: pendingGeometry.corners, gridDef: pendingGeometry.gridDef)
910
- pendingGeometryUpdate = nil
911
- }
912
-
913
- if let pendingColormap = pendingColormapUpdate {
914
- print("🟡 [GridRenderLayer] Processing pending colormap update")
915
- updateColormapTexture(colormapAsBase64: pendingColormap)
916
- pendingColormapUpdate = nil
917
- }
918
-
919
- if let pendingData = pendingDataUpdate {
920
- print("🟡 [GridRenderLayer] Processing pending data update")
921
- updateDataTexture(data: pendingData.data, nx: pendingData.nx, ny: pendingData.ny,
922
- scale: pendingData.scale, offset: pendingData.offset,
923
- missing: pendingData.missing, scaleType: pendingData.scaleType)
924
- pendingDataUpdate = nil
925
- }
926
- }
927
- internal func internalRender(_ parameters: CustomLayerRenderParameters, mtlCommandBuffer: MTLCommandBuffer, mtlRenderPassDescriptor: MTLRenderPassDescriptor) {
928
- guard isVisible,
929
- let pipeline = pipelineState,
930
- let vertices = vertexBuffer,
931
- let indices = indexBuffer,
932
- let dataTex = dataTexture,
933
- let colormapTex = colormapTexture,
934
- indexCount > 0,
935
- let encoder = mtlCommandBuffer.makeRenderCommandEncoder(descriptor: mtlRenderPassDescriptor) else {
936
-
937
- // OPTIMIZATION: Change log message to be more informative and less alarming.
938
- // This is an expected state during initial load.
939
- if (pipelineState != nil) { // Only log if Metal is set up
940
- print("🟡 [GridRenderLayer] internalRender: Waiting for all resources to be ready before drawing.")
941
- }
942
- return
943
- }
944
-
945
- let needsLinear = (uniforms.smoothing != 0)
946
- if isDataSamplerLinear != needsLinear {
947
- let samplerDesc = MTLSamplerDescriptor()
948
- samplerDesc.minFilter = needsLinear ? .linear : .nearest
949
- samplerDesc.magFilter = needsLinear ? .linear : .nearest
950
- dataSamplerState = device.makeSamplerState(descriptor: samplerDesc)
951
- isDataSamplerLinear = needsLinear
952
- }
953
-
954
- // Apply zoom scale transformation
955
- let zoom = parameters.zoom
956
- let scale = Float(pow(2.0, zoom))
957
-
958
- let matrixArray = parameters.projectionMatrix
959
- var floatArray = matrixArray.map { $0.floatValue }
960
-
961
- floatArray[0] *= scale // X scale
962
- floatArray[1] *= scale // X rotation
963
- floatArray[2] *= scale // X Z-component
964
- floatArray[3] *= scale // X translation
965
- floatArray[4] *= scale // Y rotation
966
- floatArray[5] *= scale // Y scale
967
- floatArray[6] *= scale // Y Z-component
968
- floatArray[7] *= scale // Y translation
969
- floatArray[8] *= scale // Z X-component
970
- floatArray[9] *= scale // Z Y-component
971
- floatArray[10] *= scale // Z scale
972
- floatArray[11] *= scale // Z translation
973
-
974
- let mvp = matrix_float4x4(
975
- SIMD4<Float>(floatArray[0], floatArray[1], floatArray[2], floatArray[3]),
976
- SIMD4<Float>(floatArray[4], floatArray[5], floatArray[6], floatArray[7]),
977
- SIMD4<Float>(floatArray[8], floatArray[9], floatArray[10], floatArray[11]),
978
- SIMD4<Float>(floatArray[12], floatArray[13], floatArray[14], floatArray[15])
979
- )
980
-
981
- // Add depth state
982
- let depthStencilDescriptor = MTLDepthStencilDescriptor()
983
- depthStencilDescriptor.depthCompareFunction = .always
984
- depthStencilDescriptor.isDepthWriteEnabled = false
985
- let depthStencilState = device.makeDepthStencilState(descriptor: depthStencilDescriptor)
986
-
987
- encoder.setRenderPipelineState(pipeline)
988
- encoder.setDepthStencilState(depthStencilState!)
989
- encoder.setVertexBuffer(vertices, offset: 0, index: 0)
990
- encoder.setVertexBytes([mvp], length: MemoryLayout<matrix_float4x4>.size, index: 1)
991
-
992
- var mutableUniforms = uniforms
993
- encoder.setFragmentBytes(&mutableUniforms, length: MemoryLayout<FragmentUniforms>.stride, index: 0)
994
- encoder.setFragmentTexture(dataTex, index: 0)
995
- encoder.setFragmentTexture(colormapTex, index: 1)
996
- encoder.setFragmentSamplerState(dataSamplerState, index: 0)
997
- encoder.setFragmentSamplerState(colormapSamplerState, index: 1)
998
-
999
- encoder.drawIndexedPrimitives(type: .triangle, indexCount: indexCount, indexType: .uint16, indexBuffer: indices, indexBufferOffset: 0)
1000
-
1001
- encoder.endEncoding()
1002
- }
1003
-
1004
- deinit {
1005
- print("🔴 [GridRenderLayer] deinit called for layer: \(id)")
1006
-
1007
- // Clean up all resources
1008
- frameCache.removeAll()
1009
- vertexBuffer = nil
1010
- indexBuffer = nil
1011
- dataTexture = nil
1012
- colormapTexture = nil
1013
- device = nil
1014
- commandQueue = nil
1015
- pipelineState = nil
1016
- dataSamplerState = nil
1017
- colormapSamplerState = nil
1018
-
1019
- // Break the reference cycle
1020
- hostWrapper = nil
1021
- }
1022
-
1023
- internal func internalRenderingWillEnd() {
1024
- print("🟢 [GridRenderLayer] renderingWillEnd called")
1025
- vertexBuffer = nil
1026
- indexBuffer = nil
1027
- dataTexture = nil
1028
- colormapTexture = nil
1029
- }
1030
- }
1031
-
1032
- extension GridRenderLayer {
1033
- // Override to prevent KVC crashes during cleanup
1034
- open override func value(forUndefinedKey key: String) -> Any? {
1035
- print("⚠️ [GridRenderLayer] Attempted to access undefined key: \(key)")
1036
- return nil
1037
- }
1038
-
1039
- open override func setValue(_ value: Any?, forUndefinedKey key: String) {
1040
- print("⚠️ [GridRenderLayer] Attempted to set undefined key: \(key)")
1041
- // Silently ignore instead of crashing
1042
- }
1043
- }
1
+ import Foundation
2
+ import MapboxMaps
3
+ import Metal
4
+ import libzstd
5
+ import simd
6
+
7
+ // MARK: - Swift-only wrapper for CustomLayerHost conformance
8
+ @objc internal final class GridRenderLayerHost: NSObject, CustomLayerHost {
9
+ weak var layer: GridRenderLayer?
10
+
11
+ init(layer: GridRenderLayer) {
12
+ self.layer = layer
13
+ super.init()
14
+ }
15
+
16
+ func renderingWillStart(_ metalDevice: MTLDevice, colorPixelFormat: UInt, depthStencilPixelFormat: UInt) {
17
+ layer?.internalRenderingWillStart(metalDevice, colorPixelFormat: colorPixelFormat, depthStencilPixelFormat: depthStencilPixelFormat)
18
+ }
19
+
20
+ func render(_ parameters: CustomLayerRenderParameters, mtlCommandBuffer: MTLCommandBuffer, mtlRenderPassDescriptor: MTLRenderPassDescriptor) {
21
+ layer?.internalRender(parameters, mtlCommandBuffer: mtlCommandBuffer, mtlRenderPassDescriptor: mtlRenderPassDescriptor)
22
+ }
23
+
24
+ func renderingWillEnd() {
25
+ layer?.internalRenderingWillEnd()
26
+ }
27
+ }
28
+
29
+ @objc(GridRenderLayer)
30
+ public class GridRenderLayer: NSObject {
31
+
32
+ // MARK: - Properties
33
+
34
+ public var id: String
35
+ @objc internal var hostWrapper: GridRenderLayerHost!
36
+
37
+ // Metal objects
38
+ private var device: MTLDevice!
39
+ private var commandQueue: MTLCommandQueue!
40
+ private var pipelineState: MTLRenderPipelineState!
41
+ private var vertexBuffer: MTLBuffer?
42
+ private var indexBuffer: MTLBuffer?
43
+ private var dataTexture: MTLTexture?
44
+ private var colormapTexture: MTLTexture?
45
+ private var dataSamplerState: MTLSamplerState!
46
+ private var colormapSamplerState: MTLSamplerState!
47
+ private var isDataSamplerLinear: Bool = false
48
+
49
+ private var pendingColormapUpdate: String?
50
+ private var pendingDataUpdate: (data: String, nx: NSNumber, ny: NSNumber, scale: NSNumber, offset: NSNumber, missing: NSNumber, scaleType: String)?
51
+ private var pendingGeometryUpdate: (corners: [String: Any], gridDef: [String: Any])?
52
+
53
+ // Layer state
54
+ private var indexCount: Int = 0
55
+ private var uniforms = FragmentUniforms(
56
+ opacity: 1.0,
57
+ dataRange: SIMD2<Float>(0.0, 1.0),
58
+ scale: 1.0,
59
+ offset: 0.0,
60
+ missingQuantized: 127.0,
61
+ textureSize: SIMD2<Float>(0.0, 0.0),
62
+ smoothing: 1,
63
+ scaleType: 0,
64
+ isPtype: 0,
65
+ isMRMS: 0
66
+ )
67
+ private var isVisible = false
68
+ private var pendingActiveFrameKey: String?
69
+ private let inspectorCache = InspectorDataCache.shared
70
+ private struct FrameMetadata {
71
+ let scale: Float
72
+ let offset: Float
73
+ let missing: Float
74
+ let scaleType: Int
75
+ let nx: Float
76
+ let ny: Float
77
+ let filePath: String
78
+ let originalScale: Float
79
+ let originalOffset: Float
80
+ }
81
+ private var frameCache: [String: FrameMetadata] = [:]
82
+ private let frameProcessingQueue = DispatchQueue(label: "com.aguacero.frame-processing", qos: .userInitiated, attributes: .concurrent)
83
+ private let semaphore = DispatchSemaphore(value: 8)
84
+
85
+ private struct VertexInfo {
86
+ var mercX: Float
87
+ var mercY: Float
88
+ var texU: Float
89
+ var texV: Float
90
+ var index: UInt16
91
+ }
92
+ @objc
93
+ public init(id: String) {
94
+ self.id = id
95
+ super.init()
96
+ self.hostWrapper = GridRenderLayerHost(layer: self)
97
+ }
98
+
99
+ @objc public func getHostWrapper() -> Any {
100
+ return self.hostWrapper as Any
101
+ }
102
+
103
+ // MARK: - Public Methods (called from Manager)
104
+
105
+ @objc public func setOpacity(value: Float) {
106
+ self.uniforms.opacity = value
107
+ NotificationCenter.default.post(name: NSNotification.Name("TriggerMapRepaint"), object: nil)
108
+ }
109
+
110
+ @objc public func setDataRange(value: [NSNumber]) {
111
+ self.uniforms.dataRange = SIMD2<Float>(value[0].floatValue, value[1].floatValue)
112
+ NotificationCenter.default.post(name: NSNotification.Name("TriggerMapRepaint"), object: nil)
113
+ }
114
+
115
+ @objc public func setSmoothing(value: Bool) {
116
+ self.uniforms.smoothing = value ? 1 : 0
117
+ NotificationCenter.default.post(name: NSNotification.Name("TriggerMapRepaint"), object: nil)
118
+ }
119
+
120
+ @objc(setIsMRMSWithIsMRMS:)
121
+ public func setIsMRMS(isMRMS: Bool) {
122
+ self.uniforms.isMRMS = isMRMS ? 1 : 0
123
+ NotificationCenter.default.post(name: NSNotification.Name("TriggerMapRepaint"), object: nil)
124
+ }
125
+
126
+ // ADD THIS METHOD
127
+ @objc(setVariableWithVariable:)
128
+ public func setVariable(variable: String) {
129
+ let isPtypeVar = (variable == "ptypeRefl" || variable == "ptypeRate")
130
+ self.uniforms.isPtype = isPtypeVar ? 1 : 0
131
+ NotificationCenter.default.post(name: NSNotification.Name("TriggerMapRepaint"), object: nil)
132
+ }
133
+
134
+ @objc public func clear() {
135
+ self.isVisible = false
136
+ self.inspectorCache.clear()
137
+ }
138
+
139
+ @objc public func updateDataParameters(scale: NSNumber, offset: NSNumber, missing: NSNumber, scaleType: NSNumber) { // ADD scaleType parameter
140
+ // Update both the inspector cache AND the rendering uniforms
141
+ self.uniforms.scale = scale.floatValue
142
+ self.uniforms.offset = offset.floatValue
143
+ self.uniforms.missingQuantized = missing.floatValue
144
+ self.uniforms.scaleType = Int32(scaleType.intValue) // ADD THIS
145
+
146
+ inspectorCache.update(
147
+ data: inspectorCache.lastDecompressedData,
148
+ nx: inspectorCache.nx,
149
+ ny: inspectorCache.ny,
150
+ scale: scale.floatValue,
151
+ offset: offset.floatValue,
152
+ missing: missing.floatValue,
153
+ scaleType: scaleType.intValue // ADD THIS
154
+ )
155
+ }
156
+
157
+ @objc public func updateColormapTexture(colormapAsBase64: String) {
158
+ guard let device = self.device else {
159
+ pendingColormapUpdate = colormapAsBase64
160
+ return
161
+ }
162
+ guard let data = Data(base64Encoded: colormapAsBase64) else { return }
163
+ let textureDescriptor = MTLTextureDescriptor()
164
+ textureDescriptor.pixelFormat = .rgba8Unorm
165
+ textureDescriptor.width = 256
166
+ textureDescriptor.height = 1
167
+ textureDescriptor.usage = .shaderRead
168
+ guard let texture = device.makeTexture(descriptor: textureDescriptor) else { return }
169
+ texture.replace(
170
+ region: MTLRegionMake2D(0, 0, 256, 1),
171
+ mipmapLevel: 0,
172
+ withBytes: (data as NSData).bytes,
173
+ bytesPerRow: 256 * 4
174
+ )
175
+ self.colormapTexture = texture
176
+ }
177
+
178
+ @objc(clearGpuCache)
179
+ public func clearGpuCache() {
180
+ frameProcessingQueue.async { [weak self] in
181
+ self?.frameCache.removeAll()
182
+ }
183
+ }
184
+
185
+ private func processRawData(fileData: Data) -> Data? {
186
+ guard let decompressedDeltas = self.decompressZstd(data: fileData) else {
187
+ print("❌ [GridRenderLayer] Failed to decompress zstd data")
188
+ return nil
189
+ }
190
+ let reconstructedData = self.reconstructData(decompressedDeltas: decompressedDeltas)
191
+ let finalTextureBytes = self.transformData(finalData: reconstructedData)
192
+ return finalTextureBytes
193
+ }
194
+
195
+ private func createTextureFromBytes(bytes: Data, nx: Int, ny: Int) -> MTLTexture? {
196
+ guard let device = self.device else { return nil }
197
+ let textureDescriptor = MTLTextureDescriptor()
198
+ textureDescriptor.pixelFormat = .r8Unorm
199
+ textureDescriptor.width = nx
200
+ textureDescriptor.height = ny
201
+ textureDescriptor.usage = .shaderRead
202
+
203
+ guard let texture = device.makeTexture(descriptor: textureDescriptor) else { return nil }
204
+ texture.replace(
205
+ region: MTLRegionMake2D(0, 0, nx, ny),
206
+ mipmapLevel: 0,
207
+ withBytes: (bytes as NSData).bytes,
208
+ bytesPerRow: nx
209
+ )
210
+ return texture
211
+ }
212
+
213
+ private func updateInspectorCache(filePath: String, nx: Int, ny: Int, scale: Float, offset: Float, missing: Float, scaleType: Int) {
214
+ // This is now called from frameProcessingQueue, so we can do the work synchronously
215
+ guard let fileData = try? Data(contentsOf: URL(fileURLWithPath: filePath)) else {
216
+ print("❌ [Inspector] FATAL: Failed to read file data from path.")
217
+ self.inspectorCache.clear()
218
+ return
219
+ }
220
+
221
+ guard let decompressedDeltas = self.decompressZstd(data: fileData) else {
222
+ print("❌ [Inspector] FATAL: Failed to decompress Zstd data.")
223
+ self.inspectorCache.clear()
224
+ return
225
+ }
226
+
227
+ let reconstructedData = self.reconstructData(decompressedDeltas: decompressedDeltas)
228
+
229
+ self.inspectorCache.update(
230
+ data: reconstructedData,
231
+ nx: nx,
232
+ ny: ny,
233
+ scale: scale,
234
+ offset: offset,
235
+ missing: missing,
236
+ scaleType: scaleType
237
+ )
238
+ }
239
+
240
+ @objc(setActiveFrameWithCacheKey:)
241
+ public func setActiveFrame(cacheKey: String) {
242
+ if let frame = frameCache[cacheKey] {
243
+ frameProcessingQueue.async { [weak self] in
244
+ guard let self = self else { return }
245
+
246
+ guard let fileData = try? Data(contentsOf: URL(fileURLWithPath: frame.filePath)),
247
+ let finalTextureBytes = self.processRawData(fileData: fileData)
248
+ else {
249
+ print("❌ [GridRenderLayer] Failed to load texture data for active frame")
250
+ return
251
+ }
252
+
253
+ DispatchQueue.main.async { [weak self] in
254
+ guard let self = self,
255
+ let texture = self.createTextureFromBytes(bytes: finalTextureBytes, nx: Int(frame.nx), ny: Int(frame.ny))
256
+ else { return }
257
+
258
+ self.dataTexture = texture
259
+ self.uniforms.scale = frame.scale
260
+ self.uniforms.offset = frame.offset
261
+ self.uniforms.missingQuantized = frame.missing
262
+ self.uniforms.textureSize = SIMD2<Float>(frame.nx, frame.ny)
263
+ self.uniforms.scaleType = Int32(frame.scaleType)
264
+
265
+ self.isVisible = true
266
+ self.pendingActiveFrameKey = nil
267
+ NotificationCenter.default.post(name: NSNotification.Name("TriggerMapRepaint"), object: nil)
268
+
269
+ // Update inspector cache
270
+ self.frameProcessingQueue.async { [weak self] in
271
+ self?.updateInspectorCache(
272
+ filePath: frame.filePath,
273
+ nx: Int(frame.nx),
274
+ ny: Int(frame.ny),
275
+ scale: frame.scale,
276
+ offset: frame.offset,
277
+ missing: frame.missing,
278
+ scaleType: frame.scaleType
279
+ )
280
+ }
281
+ }
282
+ }
283
+
284
+ } else {
285
+ print("⚠️ [GridRenderLayer] setActiveFrame cache MISS for key: \(cacheKey). Will apply when primed.")
286
+ self.pendingActiveFrameKey = cacheKey
287
+ self.isVisible = false
288
+ }
289
+ }
290
+
291
+ @objc(primeGpuCacheWithFrameInfo:)
292
+ public func primeGpuCache(frameInfo: [String: [String: Any]]) {
293
+ let group = DispatchGroup()
294
+
295
+ for (cacheKey, info) in frameInfo {
296
+ group.enter()
297
+
298
+ frameProcessingQueue.async { [weak self] in
299
+ guard let self = self else {
300
+ group.leave()
301
+ return
302
+ }
303
+
304
+ self.semaphore.wait()
305
+ defer {
306
+ self.semaphore.signal()
307
+ group.leave()
308
+ }
309
+
310
+ if self.frameCache[cacheKey] != nil { return }
311
+
312
+ guard let filePath = info["filePath"] as? String,
313
+ let nx = info["nx"] as? NSNumber,
314
+ let ny = info["ny"] as? NSNumber,
315
+ let scale = info["scale"] as? NSNumber,
316
+ let offset = info["offset"] as? NSNumber,
317
+ let missing = info["missing"] as? NSNumber,
318
+ let scaleTypeStr = info["scaleType"] as? String,
319
+ let originalScale = info["originalScale"] as? NSNumber,
320
+ let originalOffset = info["originalOffset"] as? NSNumber
321
+ else {
322
+ print("❌ [GridRenderLayer] Skipping prime for \(cacheKey), missing data.")
323
+ return
324
+ }
325
+
326
+ let metadata = FrameMetadata(
327
+ scale: scale.floatValue,
328
+ offset: offset.floatValue,
329
+ missing: missing.floatValue,
330
+ scaleType: (scaleTypeStr == "sqrt") ? 1 : 0,
331
+ nx: nx.floatValue,
332
+ ny: ny.floatValue,
333
+ filePath: filePath,
334
+ originalScale: originalScale.floatValue,
335
+ originalOffset: originalOffset.floatValue
336
+ )
337
+ self.frameCache[cacheKey] = metadata
338
+
339
+ if let pendingKey = self.pendingActiveFrameKey, pendingKey == cacheKey {
340
+ DispatchQueue.main.async {
341
+ self.setActiveFrame(cacheKey: pendingKey)
342
+ }
343
+ }
344
+ }
345
+ }
346
+ }
347
+
348
+ @objc public func updateDataTexture(data: String, nx: NSNumber, ny: NSNumber, scale: NSNumber, offset: NSNumber, missing: NSNumber, scaleType: String) {
349
+ let filePath = data
350
+
351
+ frameProcessingQueue.async { [weak self] in
352
+ guard let self = self else { return }
353
+
354
+ guard let fileData = try? Data(contentsOf: URL(fileURLWithPath: filePath)),
355
+ let finalTextureBytes = self.processRawData(fileData: fileData)
356
+ else {
357
+ print("❌ [GridRenderLayer] FAST LANE: Failed to process initial frame data.")
358
+ return
359
+ }
360
+
361
+ DispatchQueue.main.async { [weak self] in
362
+ guard let self = self, let texture = self.createTextureFromBytes(bytes: finalTextureBytes, nx: nx.intValue, ny: ny.intValue) else {
363
+ print("❌ [GridRenderLayer] FAST LANE: Failed to create texture")
364
+ return
365
+ }
366
+
367
+ self.dataTexture = texture
368
+ self.uniforms.scale = scale.floatValue
369
+ self.uniforms.offset = offset.floatValue
370
+ self.uniforms.missingQuantized = missing.floatValue
371
+ self.uniforms.scaleType = Int32((scaleType == "sqrt") ? 1 : 0)
372
+ self.uniforms.textureSize = SIMD2<Float>(nx.floatValue, ny.floatValue)
373
+
374
+ self.isVisible = true
375
+ NotificationCenter.default.post(name: NSNotification.Name("TriggerMapRepaint"), object: nil)
376
+
377
+ self.updateInspectorCache(
378
+ filePath: filePath,
379
+ nx: nx.intValue,
380
+ ny: ny.intValue,
381
+ scale: scale.floatValue,
382
+ offset: offset.floatValue,
383
+ missing: missing.floatValue,
384
+ scaleType: (scaleType == "sqrt") ? 1 : 0
385
+ )
386
+ }
387
+ }
388
+ }
389
+
390
+ @objc public func updateGeometry(corners: [String: Any], gridDef: [String: Any]) {
391
+ guard self.device != nil else {
392
+ print("⚠️ [GridRenderLayer] Device not ready yet, storing geometry for later")
393
+ pendingGeometryUpdate = (corners: corners, gridDef: gridDef)
394
+ return
395
+ }
396
+
397
+ DispatchQueue.global(qos: .userInitiated).async {
398
+
399
+ var vertices: [Float] = []
400
+ var indices: [UInt16] = []
401
+
402
+ self.generateGeometryData(gridDef: gridDef, vertices: &vertices, indices: &indices)
403
+
404
+ if vertices.isEmpty || indices.isEmpty {
405
+ print("❌ [GridRenderLayer] No geometry generated")
406
+ return
407
+ }
408
+
409
+ self.indexCount = indices.count
410
+
411
+ DispatchQueue.main.async {
412
+ self.vertexBuffer = self.device.makeBuffer(bytes: vertices, length: vertices.count * MemoryLayout<Float>.size, options: [])
413
+ self.indexBuffer = self.device.makeBuffer(bytes: indices, length: indices.count * MemoryLayout<UInt16>.size, options: [])
414
+
415
+ NotificationCenter.default.post(name: NSNotification.Name("TriggerMapRepaint"), object: nil)
416
+ }
417
+ }
418
+ }
419
+
420
+ private func decompressZstd(data: Data) -> Data? {
421
+ let decompressedSize = data.withUnsafeBytes { ptr in
422
+ ZSTD_getFrameContentSize(ptr.baseAddress, data.count)
423
+ }
424
+
425
+ guard Int64(bitPattern: decompressedSize) > 0 else {
426
+ print(" [GridRenderLayer] Could not determine decompressed size")
427
+ return nil
428
+ }
429
+
430
+ var decompressedData = Data(count: Int(decompressedSize))
431
+
432
+ let result = decompressedData.withUnsafeMutableBytes { decompressedPtr -> Int in
433
+ data.withUnsafeBytes { compressedPtr -> Int in
434
+ let returnValue = ZSTD_decompress(
435
+ decompressedPtr.baseAddress,
436
+ Int(decompressedSize),
437
+ compressedPtr.baseAddress,
438
+ data.count
439
+ )
440
+ return Int(returnValue)
441
+ }
442
+ }
443
+
444
+ guard result > 0 && result == decompressedData.count else {
445
+ if result > 0 {
446
+ let size_t_result = size_t(result)
447
+ if let errorName = ZSTD_getErrorName(size_t_result) {
448
+ let errorString = String(cString: errorName)
449
+ print(" [GridRenderLayer] Zstd decompression failed: \(errorString)")
450
+ }
451
+ }
452
+ return nil
453
+ }
454
+ return decompressedData
455
+ }
456
+
457
+ // MARK: - Private Helper Methods
458
+
459
+ private func reconstructData(decompressedDeltas: Data) -> Data {
460
+ guard !decompressedDeltas.isEmpty else { return Data() }
461
+ var reconstructedData = Data(count: decompressedDeltas.count)
462
+ reconstructedData[0] = decompressedDeltas[0]
463
+ for i in 1..<decompressedDeltas.count {
464
+ reconstructedData[i] = UInt8(Int8(bitPattern: reconstructedData[i-1]) &+ Int8(bitPattern: decompressedDeltas[i]))
465
+ }
466
+ return reconstructedData
467
+ }
468
+
469
+ private func transformData(finalData: Data) -> Data {
470
+ var transformedData = Data(count: finalData.count)
471
+ for i in 0..<finalData.count {
472
+ transformedData[i] = UInt8(Int16(Int8(bitPattern: finalData[i])) + 128)
473
+ }
474
+ return transformedData
475
+ }
476
+
477
+ private func isLCCType(gridDef: [String: Any]) -> Bool {
478
+ if let type = gridDef["type"] as? String {
479
+ return type == "lambert_conformal_conic"
480
+ }
481
+ return false
482
+ }
483
+
484
+ private func generateLCCGeometry(gridDef: [String: Any], vertices: inout [Float], indices: inout [UInt16]) {
485
+ guard let gridParams = gridDef["grid_params"] as? [String: Any],
486
+ let projParams = gridDef["proj_params"] as? [String: Any],
487
+ let nx = gridParams["nx"] as? Int,
488
+ let ny = gridParams["ny"] as? Int,
489
+ let dx = gridParams["dx"] as? Double,
490
+ let dy = gridParams["dy"] as? Double,
491
+ let x_origin = gridParams["x_origin"] as? Double,
492
+ let y_origin = gridParams["y_origin"] as? Double else {
493
+ return
494
+ }
495
+
496
+ let subdivisions = 60
497
+ let TILE_SIZE: Double = 512.0
498
+
499
+ let x_min = x_origin
500
+ let y_max = y_origin
501
+ let x_max = x_origin + Double(nx - 1) * dx
502
+ let y_min = y_origin + Double(ny - 1) * dy
503
+
504
+ var vertexGrid: [[VertexInfo?]] = Array(repeating: Array(repeating: nil, count: subdivisions + 1), count: subdivisions + 1)
505
+ var validVertexCount: UInt16 = 0
506
+
507
+ // Generate vertices
508
+ for row in 0...subdivisions {
509
+ for col in 0...subdivisions {
510
+ let t_x = Double(col) / Double(subdivisions)
511
+ let t_y = Double(row) / Double(subdivisions)
512
+
513
+ let proj_x = x_min + t_x * (x_max - x_min)
514
+ let proj_y = y_max + t_y * (y_min - y_max)
515
+
516
+ // Convert LCC projection coordinates to lat/lon
517
+ if let (lon, lat) = lccToLonLat(i: proj_x, j: proj_y, gridDef: gridDef) {
518
+ // Convert lat/lon to Mercator
519
+ let mercX_normalized = (lon + 180.0) / 360.0
520
+ let clampedLat = max(-85.05112878, min(85.05112878, lat))
521
+ let sinLatitude = sin(clampedLat * .pi / 180.0)
522
+ let mercY_normalized = 0.5 - log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * .pi)
523
+
524
+ let mercX = mercX_normalized * TILE_SIZE
525
+ let mercY = mercY_normalized * TILE_SIZE
526
+
527
+ // Check for invalid values
528
+ if !mercX.isFinite || !mercY.isFinite {
529
+ vertexGrid[row][col] = nil
530
+ continue
531
+ }
532
+
533
+ let tex_u = Float(t_x)
534
+ let tex_v = Float(t_y)
535
+
536
+ let vInfo = VertexInfo(
537
+ mercX: Float(mercX),
538
+ mercY: Float(mercY),
539
+ texU: tex_u,
540
+ texV: tex_v,
541
+ index: validVertexCount
542
+ )
543
+
544
+ vertexGrid[row][col] = vInfo
545
+
546
+ vertices.append(Float(mercX))
547
+ vertices.append(Float(mercY))
548
+ vertices.append(tex_u)
549
+ vertices.append(tex_v)
550
+
551
+ validVertexCount += 1
552
+ } else {
553
+ vertexGrid[row][col] = nil
554
+ }
555
+ }
556
+ }
557
+
558
+ if vertices.isEmpty {
559
+ print("❌ [LCC Geometry] No valid vertices generated")
560
+ return
561
+ }
562
+
563
+ // Generate indices
564
+ for row in 0..<subdivisions {
565
+ for col in 0..<subdivisions {
566
+ guard let topLeft = vertexGrid[row][col],
567
+ let topRight = vertexGrid[row][col + 1],
568
+ let bottomLeft = vertexGrid[row + 1][col],
569
+ let bottomRight = vertexGrid[row + 1][col + 1] else {
570
+ continue
571
+ }
572
+
573
+ indices.append(topLeft.index)
574
+ indices.append(bottomLeft.index)
575
+ indices.append(topRight.index)
576
+
577
+ indices.append(topRight.index)
578
+ indices.append(bottomLeft.index)
579
+ indices.append(bottomRight.index)
580
+ }
581
+ }
582
+ }
583
+
584
+ private func lccToLonLat(i: Double, j: Double, gridDef: [String: Any]) -> (lon: Double, lat: Double)? {
585
+ guard let projParams = gridDef["proj_params"] as? [String: Any],
586
+ let lat_0 = (projParams["lat_0"] as? NSNumber)?.doubleValue,
587
+ let lon_0 = (projParams["lon_0"] as? NSNumber)?.doubleValue,
588
+ let lat_1 = (projParams["lat_1"] as? NSNumber)?.doubleValue,
589
+ let lat_2 = (projParams["lat_2"] as? NSNumber)?.doubleValue,
590
+ let r_earth = (projParams["R"] as? NSNumber)?.doubleValue else {
591
+ print("❌ [LCC Geometry] Failed to extract LCC parameters.")
592
+ return nil
593
+ }
594
+
595
+ let π = Double.pi
596
+ let toRad = π / 180.0
597
+ let toDeg = 180.0 / π
598
+
599
+ let lat1_rad = lat_1 * toRad
600
+ let lat2_rad = lat_2 * toRad
601
+ let lat0_rad = lat_0 * toRad
602
+ let lon0_rad = lon_0 * toRad
603
+
604
+ let n: Double
605
+ if abs(lat_1 - lat_2) < 1e-10 {
606
+ n = sin(lat1_rad)
607
+ } else {
608
+ n = log(cos(lat1_rad) / cos(lat2_rad)) / log(tan(π/4.0 + lat2_rad/2.0) / tan(π/4.0 + lat1_rad/2.0))
609
+ }
610
+
611
+ let F = cos(lat1_rad) * pow(tan(π/4.0 + lat1_rad/2.0), n) / n
612
+ let rho_0 = r_earth * F * pow(tan(π/4.0 + lat0_rad/2.0), -n)
613
+
614
+ let x = i
615
+ let y = j
616
+
617
+ let rho = sqrt(x * x + (rho_0 - y) * (rho_0 - y))
618
+ if rho < 1e-10 {
619
+ return (lon: lon_0, lat: lat_0)
620
+ }
621
+
622
+ let theta = atan2(x, rho_0 - y)
623
+
624
+ let lon = lon0_rad + theta / n
625
+ let lat = 2.0 * atan(pow(r_earth * F / rho, 1.0 / n)) - π/2.0
626
+
627
+ let lonDeg = lon * toDeg
628
+ let latDeg = lat * toDeg
629
+
630
+ if !lonDeg.isFinite || !latDeg.isFinite {
631
+ return nil
632
+ }
633
+
634
+ return (lon: lonDeg, lat: latDeg)
635
+ }
636
+
637
+ private func generateGeometryData(gridDef: [String: Any], vertices: inout [Float], indices: inout [UInt16]) {
638
+ guard let gridParams = gridDef["grid_params"] as? [String: Any] else {
639
+ print("❌ [generateGeometryData] No grid_params found")
640
+ return
641
+ }
642
+
643
+ // Check grid type
644
+ let isGFS = isGFSType(gridParams: gridParams)
645
+ let isLCC = isLCCType(gridDef: gridDef)
646
+
647
+ if isGFS {
648
+ // GFS path remains unchanged
649
+ let subdivisions = 120
650
+ let verticesPerRow = (subdivisions * 3) + 1
651
+ let TILE_SIZE: Double = 512.0
652
+
653
+ for row in 0...subdivisions {
654
+ for col in 0...(subdivisions * 3) {
655
+ let v_interp = Float(row) / Float(subdivisions)
656
+ let u_interp = Float(col) / Float(subdivisions)
657
+ let lon = -540.0 + Double(u_interp) * 1080.0
658
+ let lat = -90.0 + Double(v_interp) * 180.0
659
+
660
+ let merc = lonLatToMercator(lon: lon, lat: lat, tileSize: TILE_SIZE)
661
+ vertices.append(contentsOf: [merc.x, merc.y])
662
+
663
+ let tex_u = Float((lon + 180.0) / 360.0)
664
+ let tex_v = 1.0 - v_interp
665
+ vertices.append(contentsOf: [tex_u, tex_v])
666
+ }
667
+ }
668
+
669
+ for row in 0..<subdivisions {
670
+ for col in 0..<(subdivisions * 3) {
671
+ let tl = UInt16(row * verticesPerRow + col)
672
+ let tr = tl + 1
673
+ let bl = UInt16((row + 1) * verticesPerRow + col)
674
+ let br = bl + 1
675
+ indices.append(contentsOf: [tl, bl, tr, tr, bl, br])
676
+ }
677
+ }
678
+ return
679
+ }
680
+
681
+ if isLCC {
682
+ generateLCCGeometry(gridDef: gridDef, vertices: &vertices, indices: &indices)
683
+ return
684
+ }
685
+
686
+ let nx = gridParams["nx"] as? Int ?? 0
687
+ let ny = gridParams["ny"] as? Int ?? 0
688
+ let lon_first = gridParams["lon_first"] as? Double ?? 0.0
689
+ let lat_first = gridParams["lat_first"] as? Double ?? 90.0
690
+ let dx = gridParams["dx_degrees"] as? Double ?? 0.0
691
+ let dy = gridParams["dy_degrees"] as? Double ?? 0.0
692
+ let lon_last = gridParams["lon_last"] as? Double ?? (lon_first + Double(nx - 1) * dx)
693
+ let lat_last = gridParams["lat_last"] as? Double ?? (lat_first + Double(ny - 1) * dy)
694
+
695
+ let lat_span = lat_last - lat_first
696
+ let isSouthToNorth = lat_span > 0
697
+
698
+ let data_lon_first_180 = lon_first > 180 ? lon_first - 360 : lon_first
699
+ let data_lon_last_180 = lon_last > 180 ? lon_last - 360 : lon_last
700
+ let data_lon_range = data_lon_last_180 - data_lon_first_180
701
+
702
+ let subdivisions_x = 120
703
+ let subdivisions_y = 60
704
+ let verticesPerRow = subdivisions_x + 1
705
+ let TILE_SIZE: Double = 512.0
706
+
707
+ let worldCopies = (data_lon_range > 300) ? [-1, 0, 1] : [0]
708
+
709
+ for world_copy in worldCopies {
710
+ let vertexStartIndex = UInt16(vertices.count / 4)
711
+ let lon_offset = Double(world_copy) * 360.0
712
+
713
+ for row in 0...subdivisions_y {
714
+ for col in 0...subdivisions_x {
715
+ let v_interp = Float(row) / Float(subdivisions_y)
716
+ let u_interp = Float(col) / Float(subdivisions_x)
717
+
718
+ let vertex_lon = data_lon_first_180 + (Double(u_interp) * data_lon_range)
719
+ let vertex_lat = lat_first + (Double(v_interp) * lat_span)
720
+
721
+ let mercX_normalized = ((vertex_lon + lon_offset) + 180.0) / 360.0
722
+ let clampedLat = max(-85.05112878, min(85.05112878, vertex_lat))
723
+ let sinLatitude = sin(clampedLat * .pi / 180.0)
724
+ let mercY_normalized = 0.5 - log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * .pi)
725
+ let mercX = mercX_normalized * TILE_SIZE
726
+ let mercY = mercY_normalized * TILE_SIZE
727
+
728
+ vertices.append(contentsOf: [Float(mercX), Float(mercY)])
729
+
730
+ let tex_u = u_interp
731
+ let tex_v = isSouthToNorth ? (1.0 - v_interp) : v_interp
732
+
733
+ vertices.append(contentsOf: [tex_u, tex_v])
734
+ }
735
+ }
736
+
737
+ for row in 0..<UInt16(subdivisions_y) {
738
+ for col in 0..<UInt16(subdivisions_x) {
739
+ let tl = vertexStartIndex + row * UInt16(verticesPerRow) + col
740
+ let tr = tl + 1
741
+ let bl = vertexStartIndex + (row + 1) * UInt16(verticesPerRow) + col
742
+ let br = bl + 1
743
+
744
+ if isSouthToNorth {
745
+ indices.append(contentsOf: [tl, bl, tr, tr, bl, br])
746
+ } else {
747
+ indices.append(contentsOf: [tl, tr, bl, bl, tr, br])
748
+ }
749
+ }
750
+ }
751
+ }
752
+ }
753
+
754
+ private func isGFSType(gridParams: [String: Any]) -> Bool {
755
+ return (gridParams["lon_first"] as? Double) == 0.0 &&
756
+ abs((gridParams["lat_first"] as? Double) ?? -1) == 90.0
757
+ }
758
+
759
+ private func lonLatToMercator(lon: Double, lat: Double, tileSize: Double) -> (x: Float, y: Float) {
760
+ let mercX_normalized = (lon + 180.0) / 360.0
761
+ let clampedLat = max(-85.05112878, min(85.05112878, lat))
762
+ let sinLatitude = sin(clampedLat * .pi / 180.0)
763
+ let mercY_normalized = 0.5 - log((1.0 + sinLatitude) / (1.0 - sinLatitude)) / (4.0 * .pi)
764
+
765
+ return (x: Float(mercX_normalized * tileSize), y: Float(mercY_normalized * tileSize))
766
+ }
767
+
768
+ // MARK: - Internal methods for CustomLayerHost (called by wrapper)
769
+
770
+ internal func internalRenderingWillStart(_ metalDevice: MTLDevice, colorPixelFormat: UInt, depthStencilPixelFormat: UInt) {
771
+ self.device = metalDevice
772
+ self.commandQueue = metalDevice.makeCommandQueue()
773
+
774
+ let bundle = Bundle(for: GridRenderLayer.self)
775
+
776
+ // Determine if we're running on simulator or device
777
+ #if targetEnvironment(simulator)
778
+ let metallibName = "Shaders-simulator"
779
+ #else
780
+ let metallibName = "Shaders-device"
781
+ #endif
782
+
783
+ // Try to load pre-compiled metallib for the current platform
784
+ let defaultLibrary: MTLLibrary?
785
+ if let metallibUrl = bundle.url(forResource: metallibName, withExtension: "metallib"),
786
+ let library = try? metalDevice.makeLibrary(URL: metallibUrl) {
787
+ defaultLibrary = library
788
+ }
789
+ // Fall back to compiling from .metal source (for development with npm link)
790
+ else if let metalUrl = bundle.url(forResource: "Shaders", withExtension: "metal"),
791
+ let source = try? String(contentsOf: metalUrl),
792
+ let library = try? metalDevice.makeLibrary(source: source, options: nil) {
793
+ defaultLibrary = library
794
+ }
795
+ // Neither worked
796
+ else {
797
+ print("❌ [GridRenderLayer] Could not find or compile Metal shaders")
798
+ print(" Bundle path: \(bundle.bundlePath)")
799
+ return
800
+ }
801
+
802
+ guard let library = defaultLibrary else {
803
+ print("❌ [GridRenderLayer] Failed to create Metal library")
804
+ return
805
+ }
806
+
807
+ let vertexFunction = library.makeFunction(name: "vertex_main")
808
+ let fragmentFunction = library.makeFunction(name: "fragment_main")
809
+
810
+ // Set up vertex descriptor
811
+ let vertexDescriptor = MTLVertexDescriptor()
812
+ vertexDescriptor.attributes[0].format = .float2 // position (x, y)
813
+ vertexDescriptor.attributes[0].offset = 0
814
+ vertexDescriptor.attributes[0].bufferIndex = 0
815
+
816
+ vertexDescriptor.attributes[1].format = .float2 // texCoord (u, v)
817
+ vertexDescriptor.attributes[1].offset = MemoryLayout<Float>.size * 2
818
+ vertexDescriptor.attributes[1].bufferIndex = 0
819
+
820
+ vertexDescriptor.layouts[0].stride = MemoryLayout<Float>.size * 4 // 2 floats for pos + 2 for texCoord
821
+ vertexDescriptor.layouts[0].stepFunction = .perVertex
822
+
823
+ let pipelineDescriptor = MTLRenderPipelineDescriptor()
824
+ pipelineDescriptor.vertexDescriptor = vertexDescriptor
825
+ pipelineDescriptor.vertexFunction = vertexFunction
826
+ pipelineDescriptor.fragmentFunction = fragmentFunction
827
+
828
+ pipelineDescriptor.colorAttachments[0].pixelFormat = MTLPixelFormat(rawValue: colorPixelFormat) ?? .bgra8Unorm
829
+ pipelineDescriptor.depthAttachmentPixelFormat = MTLPixelFormat(rawValue: depthStencilPixelFormat) ?? .depth32Float_stencil8
830
+ pipelineDescriptor.stencilAttachmentPixelFormat = MTLPixelFormat(rawValue: depthStencilPixelFormat) ?? .depth32Float_stencil8
831
+
832
+ pipelineDescriptor.colorAttachments[0].isBlendingEnabled = true
833
+ pipelineDescriptor.colorAttachments[0].rgbBlendOperation = .add
834
+ pipelineDescriptor.colorAttachments[0].alphaBlendOperation = .add
835
+ pipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = .sourceAlpha
836
+ pipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .sourceAlpha
837
+ pipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = .oneMinusSourceAlpha
838
+ pipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .oneMinusSourceAlpha
839
+
840
+ do {
841
+ self.pipelineState = try metalDevice.makeRenderPipelineState(descriptor: pipelineDescriptor)
842
+ } catch {
843
+ print("❌ [GridRenderLayer] Failed to create pipeline state: \(error)")
844
+ return
845
+ }
846
+
847
+ let dataSamplerDesc = MTLSamplerDescriptor()
848
+ dataSamplerDesc.minFilter = .nearest
849
+ dataSamplerDesc.magFilter = .nearest
850
+ self.dataSamplerState = metalDevice.makeSamplerState(descriptor: dataSamplerDesc)
851
+
852
+ let colormapSamplerDesc = MTLSamplerDescriptor()
853
+ colormapSamplerDesc.minFilter = .nearest
854
+ colormapSamplerDesc.magFilter = .nearest
855
+ colormapSamplerDesc.sAddressMode = .clampToEdge
856
+ self.colormapSamplerState = metalDevice.makeSamplerState(descriptor: colormapSamplerDesc)
857
+
858
+ // Process any pending updates that came in before Metal was ready
859
+ if let pendingGeometry = pendingGeometryUpdate {
860
+ updateGeometry(corners: pendingGeometry.corners, gridDef: pendingGeometry.gridDef)
861
+ pendingGeometryUpdate = nil
862
+ }
863
+
864
+ if let pendingColormap = pendingColormapUpdate {
865
+ updateColormapTexture(colormapAsBase64: pendingColormap)
866
+ pendingColormapUpdate = nil
867
+ }
868
+
869
+ if let pendingData = pendingDataUpdate {
870
+ updateDataTexture(data: pendingData.data, nx: pendingData.nx, ny: pendingData.ny,
871
+ scale: pendingData.scale, offset: pendingData.offset,
872
+ missing: pendingData.missing, scaleType: pendingData.scaleType)
873
+ pendingDataUpdate = nil
874
+ }
875
+ }
876
+ internal func internalRender(_ parameters: CustomLayerRenderParameters, mtlCommandBuffer: MTLCommandBuffer, mtlRenderPassDescriptor: MTLRenderPassDescriptor) {
877
+ guard isVisible,
878
+ let pipeline = pipelineState,
879
+ let vertices = vertexBuffer,
880
+ let indices = indexBuffer,
881
+ let dataTex = dataTexture,
882
+ let colormapTex = colormapTexture,
883
+ indexCount > 0,
884
+ let encoder = mtlCommandBuffer.makeRenderCommandEncoder(descriptor: mtlRenderPassDescriptor) else {
885
+
886
+ return
887
+ }
888
+
889
+ let needsLinear = (uniforms.smoothing != 0)
890
+ if isDataSamplerLinear != needsLinear {
891
+ let samplerDesc = MTLSamplerDescriptor()
892
+ samplerDesc.minFilter = needsLinear ? .linear : .nearest
893
+ samplerDesc.magFilter = needsLinear ? .linear : .nearest
894
+ dataSamplerState = device.makeSamplerState(descriptor: samplerDesc)
895
+ isDataSamplerLinear = needsLinear
896
+ }
897
+
898
+ // Apply zoom scale transformation
899
+ let zoom = parameters.zoom
900
+ let scale = Float(pow(2.0, zoom))
901
+
902
+ let matrixArray = parameters.projectionMatrix
903
+ var floatArray = matrixArray.map { $0.floatValue }
904
+
905
+ floatArray[0] *= scale // X scale
906
+ floatArray[1] *= scale // X rotation
907
+ floatArray[2] *= scale // X Z-component
908
+ floatArray[3] *= scale // X translation
909
+ floatArray[4] *= scale // Y rotation
910
+ floatArray[5] *= scale // Y scale
911
+ floatArray[6] *= scale // Y Z-component
912
+ floatArray[7] *= scale // Y translation
913
+ floatArray[8] *= scale // Z X-component
914
+ floatArray[9] *= scale // Z Y-component
915
+ floatArray[10] *= scale // Z scale
916
+ floatArray[11] *= scale // Z translation
917
+
918
+ let mvp = matrix_float4x4(
919
+ SIMD4<Float>(floatArray[0], floatArray[1], floatArray[2], floatArray[3]),
920
+ SIMD4<Float>(floatArray[4], floatArray[5], floatArray[6], floatArray[7]),
921
+ SIMD4<Float>(floatArray[8], floatArray[9], floatArray[10], floatArray[11]),
922
+ SIMD4<Float>(floatArray[12], floatArray[13], floatArray[14], floatArray[15])
923
+ )
924
+
925
+ // Add depth state
926
+ let depthStencilDescriptor = MTLDepthStencilDescriptor()
927
+ depthStencilDescriptor.depthCompareFunction = .always
928
+ depthStencilDescriptor.isDepthWriteEnabled = false
929
+ let depthStencilState = device.makeDepthStencilState(descriptor: depthStencilDescriptor)
930
+
931
+ encoder.setRenderPipelineState(pipeline)
932
+ encoder.setDepthStencilState(depthStencilState!)
933
+ encoder.setVertexBuffer(vertices, offset: 0, index: 0)
934
+ encoder.setVertexBytes([mvp], length: MemoryLayout<matrix_float4x4>.size, index: 1)
935
+
936
+ var mutableUniforms = uniforms
937
+ encoder.setFragmentBytes(&mutableUniforms, length: MemoryLayout<FragmentUniforms>.stride, index: 0)
938
+ encoder.setFragmentTexture(dataTex, index: 0)
939
+ encoder.setFragmentTexture(colormapTex, index: 1)
940
+ encoder.setFragmentSamplerState(dataSamplerState, index: 0)
941
+ encoder.setFragmentSamplerState(colormapSamplerState, index: 1)
942
+
943
+ encoder.drawIndexedPrimitives(type: .triangle, indexCount: indexCount, indexType: .uint16, indexBuffer: indices, indexBufferOffset: 0)
944
+
945
+ encoder.endEncoding()
946
+ }
947
+
948
+ deinit {
949
+ print("🔴 [GridRenderLayer] deinit called for layer: \(id)")
950
+
951
+ // Clean up all resources
952
+ frameCache.removeAll()
953
+ vertexBuffer = nil
954
+ indexBuffer = nil
955
+ dataTexture = nil
956
+ colormapTexture = nil
957
+ device = nil
958
+ commandQueue = nil
959
+ pipelineState = nil
960
+ dataSamplerState = nil
961
+ colormapSamplerState = nil
962
+
963
+ // Break the reference cycle
964
+ hostWrapper = nil
965
+ }
966
+
967
+ internal func internalRenderingWillEnd() {
968
+ vertexBuffer = nil
969
+ indexBuffer = nil
970
+ dataTexture = nil
971
+ colormapTexture = nil
972
+ }
973
+ }
974
+
975
+ extension GridRenderLayer {
976
+ // Override to prevent KVC crashes during cleanup
977
+ open override func value(forUndefinedKey key: String) -> Any? {
978
+ print("⚠️ [GridRenderLayer] Attempted to access undefined key: \(key)")
979
+ return nil
980
+ }
981
+
982
+ open override func setValue(_ value: Any?, forUndefinedKey key: String) {
983
+ print("⚠️ [GridRenderLayer] Attempted to set undefined key: \(key)")
984
+ // Silently ignore instead of crashing
985
+ }
986
+ }