@nice2dev/game-engine 1.3.14 → 1.3.16

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 (434) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/accessibility/Accessibility.js +152 -165
  3. package/dist/cjs/ai/AI.js +292 -294
  4. package/dist/cjs/ai/BehaviorTree.js +1029 -1113
  5. package/dist/cjs/ai/StateMachine.js +694 -756
  6. package/dist/cjs/animation/Animation.js +232 -241
  7. package/dist/cjs/audio/AudioAdvanced.js +221 -236
  8. package/dist/cjs/audio/AudioBridge.js +441 -435
  9. package/dist/cjs/audio/AudioManager.js +242 -259
  10. package/dist/cjs/build-cloud/BuildOrchestration.js +1059 -1098
  11. package/dist/cjs/build-cloud/GodotBuildCloud.js +641 -670
  12. package/dist/cjs/build-cloud/UnityBuildCloud.js +563 -610
  13. package/dist/cjs/build-cloud/UnrealBuildCloud.js +610 -635
  14. package/dist/cjs/core/EventBus.js +51 -56
  15. package/dist/cjs/core/GameClock.js +62 -66
  16. package/dist/cjs/core/GameConfig.js +72 -79
  17. package/dist/cjs/core/GameLoop.js +80 -89
  18. package/dist/cjs/core/ServiceLocator.js +61 -65
  19. package/dist/cjs/core/Validation.js +72 -82
  20. package/dist/cjs/core/math.js +108 -112
  21. package/dist/cjs/devtools/DevTools.js +542 -563
  22. package/dist/cjs/devtools/DeveloperExperience.js +521 -559
  23. package/dist/cjs/devtools/GameplayAnalytics.js +636 -646
  24. package/dist/cjs/dialogue/DialogueSystem.js +984 -986
  25. package/dist/cjs/docs/DocGenerator.js +339 -364
  26. package/dist/cjs/ecs/World.js +355 -371
  27. package/dist/cjs/editor/AchievementEditor.js +580 -636
  28. package/dist/cjs/editor/AdvancedEditor.js +184 -191
  29. package/dist/cjs/editor/AnimationRetargeting.js +696 -741
  30. package/dist/cjs/editor/AssetBrowser.js +1072 -1160
  31. package/dist/cjs/editor/AssetManager.js +187 -192
  32. package/dist/cjs/editor/ConsolePro.js +971 -1061
  33. package/dist/cjs/editor/CraftingEditor.js +680 -730
  34. package/dist/cjs/editor/DebugTools.js +187 -185
  35. package/dist/cjs/editor/DialogueSystem.js +844 -901
  36. package/dist/cjs/editor/LeaderboardSystem.js +429 -483
  37. package/dist/cjs/editor/NiceGameEditor.js +1903 -1201
  38. package/dist/cjs/editor/PrefabSystem.js +772 -838
  39. package/dist/cjs/editor/ProfilerPanel.js +649 -700
  40. package/dist/cjs/editor/QuestEditor.js +792 -839
  41. package/dist/cjs/editor/ReplaySystem.js +585 -634
  42. package/dist/cjs/editor/SceneEditor.js +176 -200
  43. package/dist/cjs/editor/ScreenshotMode.js +621 -688
  44. package/dist/cjs/editor/ShaderGraph.js +1556 -1582
  45. package/dist/cjs/editor/TimelineEditor.js +715 -778
  46. package/dist/cjs/editor/UndoRedoPro.js +830 -904
  47. package/dist/cjs/editor/VRARMode.js +582 -645
  48. package/dist/cjs/engine/NiceGameEngine.js +141 -164
  49. package/dist/cjs/engine/SaveSystem.js +441 -495
  50. package/dist/cjs/enterprise/Enterprise.js +254 -261
  51. package/dist/cjs/export/BevyExporter.js +927 -967
  52. package/dist/cjs/export/CocosExporter.js +644 -673
  53. package/dist/cjs/export/Construct3Exporter.js +783 -794
  54. package/dist/cjs/export/DefoldExporter.js +1028 -1069
  55. package/dist/cjs/export/GDevelopExporter.js +674 -708
  56. package/dist/cjs/export/GameMakerExporter.js +791 -805
  57. package/dist/cjs/export/GodotExporter.js +1003 -1045
  58. package/dist/cjs/export/MinecraftBedrockExporter.js +573 -578
  59. package/dist/cjs/export/MonoGameExporter.js +1265 -1293
  60. package/dist/cjs/export/Pico8Exporter.js +766 -812
  61. package/dist/cjs/export/PlatformExporter.js +188 -206
  62. package/dist/cjs/export/RPGMakerExporter.js +860 -879
  63. package/dist/cjs/export/RobloxExporter.js +883 -919
  64. package/dist/cjs/export/Solar2DExporter.js +1218 -1256
  65. package/dist/cjs/export/ThreeJSExporter.js +1006 -1073
  66. package/dist/cjs/export/Tic80Exporter.js +1210 -1267
  67. package/dist/cjs/export/UnityExporter.js +1116 -1131
  68. package/dist/cjs/export/UnrealExporter.js +889 -919
  69. package/dist/cjs/export/WebExporter.js +931 -970
  70. package/dist/cjs/export/index.js +42 -65
  71. package/dist/cjs/godot-integration/GodotAssetLibrary.js +659 -692
  72. package/dist/cjs/godot-integration/GodotImport.js +929 -1027
  73. package/dist/cjs/godot-integration/GodotLiveLink.js +915 -945
  74. package/dist/cjs/godot-integration/components/GodotProjectBrowser.js +911 -611
  75. package/dist/cjs/i18n/I18n.js +860 -900
  76. package/dist/cjs/i18n/useTranslation.js +84 -89
  77. package/dist/cjs/import/AsepriteImporter.js +658 -716
  78. package/dist/cjs/import/DragonBonesImporter.js +437 -461
  79. package/dist/cjs/import/GameMakerImporter.js +511 -521
  80. package/dist/cjs/import/GodotSceneImporter.js +788 -822
  81. package/dist/cjs/import/LDtkImporter.js +436 -454
  82. package/dist/cjs/import/Live2DImporter.js +497 -518
  83. package/dist/cjs/import/NdgFormat.js +424 -457
  84. package/dist/cjs/import/OgmoImporter.js +466 -493
  85. package/dist/cjs/import/RPGMakerImporter.js +451 -477
  86. package/dist/cjs/import/SceneImporter.js +378 -423
  87. package/dist/cjs/import/SpineImporter.js +511 -546
  88. package/dist/cjs/import/SpriterImporter.js +590 -613
  89. package/dist/cjs/import/TiledMapImporter.js +811 -846
  90. package/dist/cjs/import/UnitySceneImporter.js +687 -703
  91. package/dist/cjs/import/index.js +206 -251
  92. package/dist/cjs/index.js +275 -278
  93. package/dist/cjs/input/GamepadNavigation.js +185 -205
  94. package/dist/cjs/input/InputManager.js +397 -421
  95. package/dist/cjs/input/useGamepads.js +70 -81
  96. package/dist/cjs/integration/IconSprite.js +129 -256
  97. package/dist/cjs/inventory/InventorySystem.js +920 -995
  98. package/dist/cjs/kids/KidMode.js +997 -1022
  99. package/dist/cjs/kids/KidTools.js +570 -594
  100. package/dist/cjs/monetization/Monetization.js +170 -177
  101. package/dist/cjs/multiplayer/LocalMultiplayer.js +287 -287
  102. package/dist/cjs/multiplayer/MiniGameTypes.js +49 -59
  103. package/dist/cjs/native-engine/AnimationSystem.js +731 -806
  104. package/dist/cjs/native-engine/AssetPipeline.js +454 -515
  105. package/dist/cjs/native-engine/AudioEngine.js +763 -804
  106. package/dist/cjs/native-engine/InputSystem.js +1075 -1145
  107. package/dist/cjs/native-engine/NetworkingSystem.js +733 -793
  108. package/dist/cjs/native-engine/PhysicsEngine.js +583 -607
  109. package/dist/cjs/native-engine/RenderingEngine.js +302 -350
  110. package/dist/cjs/native-engine/SceneGraph.js +769 -808
  111. package/dist/cjs/network/MultiplayerTransport.js +97 -132
  112. package/dist/cjs/network/Networking.js +549 -564
  113. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AbortController.js +21 -29
  114. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +40 -48
  115. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +35 -43
  116. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +10 -15
  117. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Errors.js +103 -135
  118. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +131 -158
  119. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +39 -53
  120. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +5 -8
  121. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +40 -48
  122. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +494 -572
  123. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +826 -953
  124. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +125 -146
  125. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +13 -23
  126. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ILogger.js +11 -25
  127. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ITransport.js +13 -24
  128. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +108 -121
  129. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Loggers.js +10 -14
  130. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +150 -185
  131. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +158 -196
  132. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +90 -105
  133. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Subject.js +30 -35
  134. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +16 -21
  135. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Utils.js +215 -248
  136. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +135 -157
  137. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +76 -85
  138. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/index.js +24 -27
  139. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +3 -4
  140. package/dist/cjs/pathfinding/Pathfinding.js +245 -263
  141. package/dist/cjs/performance/AssetStreaming.js +561 -635
  142. package/dist/cjs/performance/BenchmarkSuite.js +283 -311
  143. package/dist/cjs/performance/DeltaCompression.js +467 -526
  144. package/dist/cjs/performance/DeterministicPhysics.js +450 -498
  145. package/dist/cjs/performance/ECSOptimization.js +644 -695
  146. package/dist/cjs/performance/GameSaveSystem.js +509 -556
  147. package/dist/cjs/performance/HotReload.js +447 -500
  148. package/dist/cjs/performance/InputRecording.js +511 -561
  149. package/dist/cjs/performance/InterestManagement.js +453 -500
  150. package/dist/cjs/performance/LocalizationRuntime.js +376 -423
  151. package/dist/cjs/performance/MemoryManagement.js +410 -470
  152. package/dist/cjs/performance/ModSupport.js +445 -496
  153. package/dist/cjs/performance/MultiThreadedPhysics.js +400 -443
  154. package/dist/cjs/performance/NetworkPrediction.js +424 -482
  155. package/dist/cjs/performance/ObjectPooling.js +569 -617
  156. package/dist/cjs/performance/Performance.js +174 -190
  157. package/dist/cjs/performance/PerformanceAdvanced.js +614 -637
  158. package/dist/cjs/performance/WebGPURenderer.js +656 -683
  159. package/dist/cjs/physics/PhysicsAdvanced.js +345 -379
  160. package/dist/cjs/physics/PhysicsEngine2D.js +391 -427
  161. package/dist/cjs/plugins/PluginSDK.js +432 -466
  162. package/dist/cjs/plugins/PluginTestKit.js +307 -330
  163. package/dist/cjs/procedural/Procedural.js +243 -254
  164. package/dist/cjs/procedural/WorldBuilding.js +297 -314
  165. package/dist/cjs/quest/QuestSystem.js +975 -932
  166. package/dist/cjs/release/MobileExport.js +157 -163
  167. package/dist/cjs/release/Release.js +225 -238
  168. package/dist/cjs/rendering/Camera2D.js +121 -124
  169. package/dist/cjs/rendering/Renderer2D.js +321 -335
  170. package/dist/cjs/rendering/WebGPURenderPipeline.js +632 -651
  171. package/dist/cjs/runtime3d/Runtime3D.js +359 -378
  172. package/dist/cjs/runtime3d/SceneEditor3D.js +252 -263
  173. package/dist/cjs/scene/SceneManager.js +177 -193
  174. package/dist/cjs/scripting/GraphToAST.js +574 -547
  175. package/dist/cjs/scripting/LanguageExporter.js +254 -279
  176. package/dist/cjs/scripting/NodeGraph.js +546 -570
  177. package/dist/cjs/scripting/ScriptAST.js +31 -39
  178. package/dist/cjs/scripting/VisualScripting2.js +1016 -1065
  179. package/dist/cjs/scripting/exporters/CSharpExporter.js +464 -496
  180. package/dist/cjs/scripting/exporters/GDScriptExporter.js +390 -442
  181. package/dist/cjs/scripting/exporters/LuaExporter.js +406 -447
  182. package/dist/cjs/scripting/exporters/PythonExporter.js +484 -549
  183. package/dist/cjs/scripting/exporters/RustExporter.js +459 -512
  184. package/dist/cjs/scripting/exporters/TypeScriptExporter.js +505 -556
  185. package/dist/cjs/social/Social.js +72 -80
  186. package/dist/cjs/systems/LightingSystem.js +844 -931
  187. package/dist/cjs/systems/ParticleSystem2.js +1447 -1451
  188. package/dist/cjs/systems/PhysicsDebugSystem.js +1070 -1141
  189. package/dist/cjs/systems/TerrainSystem.js +985 -1098
  190. package/dist/cjs/templates/ActionTemplates.js +296 -309
  191. package/dist/cjs/templates/FightingTemplate.js +417 -463
  192. package/dist/cjs/templates/MetroidvaniaTemplate.js +353 -405
  193. package/dist/cjs/templates/PartyTemplates.js +190 -202
  194. package/dist/cjs/templates/PuzzleTemplates.js +245 -261
  195. package/dist/cjs/templates/RPGTemplates.js +160 -178
  196. package/dist/cjs/templates/SportsTemplates.js +237 -250
  197. package/dist/cjs/templates/StrategyTemplates.js +143 -153
  198. package/dist/cjs/templates/SurvivalTemplate.js +336 -380
  199. package/dist/cjs/templates/WaveDefense.js +499 -526
  200. package/dist/cjs/tilemap/Tilemap.js +207 -214
  201. package/dist/cjs/tutorials/TutorialBranching.js +396 -417
  202. package/dist/cjs/tutorials/TutorialEngine.js +888 -931
  203. package/dist/cjs/tutorials/TutorialOverlay.js +602 -640
  204. package/dist/cjs/tutorials/content/Tutorials_T05_T08.js +787 -809
  205. package/dist/cjs/tutorials/content/Tutorials_T09_T11.js +736 -756
  206. package/dist/cjs/tutorials/content/Tutorials_T12_T15.js +754 -778
  207. package/dist/cjs/ui/GameUI.js +295 -312
  208. package/dist/cjs/unity-integration/UnityAssetStore.js +700 -741
  209. package/dist/cjs/unity-integration/UnityImport.js +1066 -1176
  210. package/dist/cjs/unity-integration/UnityLiveLink.js +934 -981
  211. package/dist/cjs/unity-integration/components/UnityAssetStoreBrowser.js +1233 -757
  212. package/dist/cjs/unity-integration/components/UnityProjectBrowser.js +1240 -768
  213. package/dist/cjs/unreal-integration/UnrealImport.js +391 -412
  214. package/dist/cjs/unreal-integration/UnrealLiveLink.js +1102 -1137
  215. package/dist/cjs/unreal-integration/UnrealMarketplace.js +436 -473
  216. package/dist/cjs/unreal-integration/components/UnrealProjectBrowser.js +1150 -767
  217. package/dist/cjs/xr/ARVR.js +167 -175
  218. package/dist/esm/accessibility/Accessibility.js +160 -164
  219. package/dist/esm/ai/AI.js +310 -293
  220. package/dist/esm/ai/BehaviorTree.js +1057 -1112
  221. package/dist/esm/ai/StateMachine.js +709 -755
  222. package/dist/esm/animation/Animation.js +237 -240
  223. package/dist/esm/audio/AudioAdvanced.js +239 -235
  224. package/dist/esm/audio/AudioBridge.js +448 -434
  225. package/dist/esm/audio/AudioManager.js +243 -258
  226. package/dist/esm/build-cloud/BuildOrchestration.js +1071 -1097
  227. package/dist/esm/build-cloud/GodotBuildCloud.js +647 -669
  228. package/dist/esm/build-cloud/UnityBuildCloud.js +571 -609
  229. package/dist/esm/build-cloud/UnrealBuildCloud.js +615 -634
  230. package/dist/esm/core/EventBus.js +52 -55
  231. package/dist/esm/core/GameClock.js +63 -65
  232. package/dist/esm/core/GameConfig.js +77 -78
  233. package/dist/esm/core/GameLoop.js +81 -88
  234. package/dist/esm/core/ServiceLocator.js +63 -64
  235. package/dist/esm/core/Validation.js +82 -81
  236. package/dist/esm/core/math.js +109 -111
  237. package/dist/esm/devtools/DevTools.js +546 -562
  238. package/dist/esm/devtools/DeveloperExperience.js +535 -558
  239. package/dist/esm/devtools/GameplayAnalytics.js +647 -645
  240. package/dist/esm/dialogue/DialogueSystem.js +998 -985
  241. package/dist/esm/docs/DocGenerator.js +342 -363
  242. package/dist/esm/ecs/World.js +358 -370
  243. package/dist/esm/editor/AchievementEditor.js +584 -635
  244. package/dist/esm/editor/AdvancedEditor.js +191 -190
  245. package/dist/esm/editor/AnimationRetargeting.js +700 -740
  246. package/dist/esm/editor/AssetBrowser.js +1078 -1159
  247. package/dist/esm/editor/AssetManager.js +188 -191
  248. package/dist/esm/editor/ConsolePro.js +977 -1060
  249. package/dist/esm/editor/CraftingEditor.js +684 -729
  250. package/dist/esm/editor/DebugTools.js +194 -184
  251. package/dist/esm/editor/DialogueSystem.js +849 -900
  252. package/dist/esm/editor/LeaderboardSystem.js +433 -482
  253. package/dist/esm/editor/NiceGameEditor.js +1908 -1200
  254. package/dist/esm/editor/PrefabSystem.js +777 -837
  255. package/dist/esm/editor/ProfilerPanel.js +654 -699
  256. package/dist/esm/editor/QuestEditor.js +795 -838
  257. package/dist/esm/editor/ReplaySystem.js +591 -633
  258. package/dist/esm/editor/SceneEditor.js +189 -199
  259. package/dist/esm/editor/ScreenshotMode.js +628 -687
  260. package/dist/esm/editor/ShaderGraph.js +1565 -1581
  261. package/dist/esm/editor/TimelineEditor.js +733 -777
  262. package/dist/esm/editor/UndoRedoPro.js +835 -903
  263. package/dist/esm/editor/VRARMode.js +586 -644
  264. package/dist/esm/engine/NiceGameEngine.js +142 -163
  265. package/dist/esm/engine/SaveSystem.js +447 -494
  266. package/dist/esm/enterprise/Enterprise.js +265 -260
  267. package/dist/esm/export/BevyExporter.js +929 -966
  268. package/dist/esm/export/CocosExporter.js +646 -672
  269. package/dist/esm/export/Construct3Exporter.js +785 -793
  270. package/dist/esm/export/DefoldExporter.js +1030 -1068
  271. package/dist/esm/export/GDevelopExporter.js +676 -707
  272. package/dist/esm/export/GameMakerExporter.js +793 -804
  273. package/dist/esm/export/GodotExporter.js +1004 -1044
  274. package/dist/esm/export/MinecraftBedrockExporter.js +575 -577
  275. package/dist/esm/export/MonoGameExporter.js +1267 -1292
  276. package/dist/esm/export/Pico8Exporter.js +768 -811
  277. package/dist/esm/export/PlatformExporter.js +193 -205
  278. package/dist/esm/export/RPGMakerExporter.js +862 -878
  279. package/dist/esm/export/RobloxExporter.js +885 -918
  280. package/dist/esm/export/Solar2DExporter.js +1220 -1255
  281. package/dist/esm/export/ThreeJSExporter.js +1007 -1072
  282. package/dist/esm/export/Tic80Exporter.js +1212 -1266
  283. package/dist/esm/export/UnityExporter.js +1117 -1130
  284. package/dist/esm/export/UnrealExporter.js +891 -918
  285. package/dist/esm/export/WebExporter.js +933 -969
  286. package/dist/esm/export/index.js +86 -71
  287. package/dist/esm/godot-integration/GodotAssetLibrary.js +663 -691
  288. package/dist/esm/godot-integration/GodotImport.js +935 -1026
  289. package/dist/esm/godot-integration/GodotLiveLink.js +918 -944
  290. package/dist/esm/godot-integration/components/GodotProjectBrowser.js +912 -610
  291. package/dist/esm/i18n/I18n.js +871 -899
  292. package/dist/esm/i18n/useTranslation.js +88 -88
  293. package/dist/esm/import/AsepriteImporter.js +637 -715
  294. package/dist/esm/import/DragonBonesImporter.js +417 -460
  295. package/dist/esm/import/GameMakerImporter.js +491 -520
  296. package/dist/esm/import/GodotSceneImporter.js +767 -821
  297. package/dist/esm/import/LDtkImporter.js +415 -453
  298. package/dist/esm/import/Live2DImporter.js +477 -517
  299. package/dist/esm/import/NdgFormat.js +410 -456
  300. package/dist/esm/import/OgmoImporter.js +446 -492
  301. package/dist/esm/import/RPGMakerImporter.js +431 -476
  302. package/dist/esm/import/SceneImporter.js +385 -422
  303. package/dist/esm/import/SpineImporter.js +491 -545
  304. package/dist/esm/import/SpriterImporter.js +570 -612
  305. package/dist/esm/import/TiledMapImporter.js +790 -845
  306. package/dist/esm/import/UnitySceneImporter.js +666 -702
  307. package/dist/esm/import/index.js +247 -258
  308. package/dist/esm/index.js +1332 -188
  309. package/dist/esm/input/GamepadNavigation.js +187 -204
  310. package/dist/esm/input/InputManager.js +401 -420
  311. package/dist/esm/input/useGamepads.js +72 -80
  312. package/dist/esm/integration/IconSprite.js +143 -255
  313. package/dist/esm/inventory/InventorySystem.js +925 -994
  314. package/dist/esm/kids/KidMode.js +1003 -1021
  315. package/dist/esm/kids/KidTools.js +573 -593
  316. package/dist/esm/monetization/Monetization.js +180 -176
  317. package/dist/esm/multiplayer/LocalMultiplayer.js +290 -286
  318. package/dist/esm/multiplayer/MiniGameTypes.js +58 -58
  319. package/dist/esm/native-engine/AnimationSystem.js +735 -805
  320. package/dist/esm/native-engine/AssetPipeline.js +456 -514
  321. package/dist/esm/native-engine/AudioEngine.js +765 -803
  322. package/dist/esm/native-engine/InputSystem.js +1079 -1144
  323. package/dist/esm/native-engine/NetworkingSystem.js +740 -792
  324. package/dist/esm/native-engine/PhysicsEngine.js +585 -606
  325. package/dist/esm/native-engine/RenderingEngine.js +304 -349
  326. package/dist/esm/native-engine/SceneGraph.js +773 -807
  327. package/dist/esm/network/MultiplayerTransport.js +99 -131
  328. package/dist/esm/network/Networking.js +556 -563
  329. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AbortController.js +22 -28
  330. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +41 -47
  331. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +36 -42
  332. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +11 -14
  333. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Errors.js +111 -134
  334. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +132 -157
  335. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +40 -52
  336. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +6 -7
  337. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +42 -47
  338. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +496 -571
  339. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +828 -952
  340. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +126 -145
  341. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +14 -23
  342. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ILogger.js +12 -25
  343. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ITransport.js +15 -24
  344. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +109 -120
  345. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Loggers.js +11 -13
  346. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +151 -184
  347. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +159 -195
  348. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +91 -104
  349. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Subject.js +31 -34
  350. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +17 -20
  351. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Utils.js +230 -248
  352. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +136 -156
  353. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +77 -84
  354. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/index.js +31 -12
  355. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +4 -3
  356. package/dist/esm/pathfinding/Pathfinding.js +249 -262
  357. package/dist/esm/performance/AssetStreaming.js +567 -634
  358. package/dist/esm/performance/BenchmarkSuite.js +285 -310
  359. package/dist/esm/performance/DeltaCompression.js +478 -525
  360. package/dist/esm/performance/DeterministicPhysics.js +479 -497
  361. package/dist/esm/performance/ECSOptimization.js +653 -694
  362. package/dist/esm/performance/GameSaveSystem.js +515 -555
  363. package/dist/esm/performance/HotReload.js +454 -499
  364. package/dist/esm/performance/InputRecording.js +520 -560
  365. package/dist/esm/performance/InterestManagement.js +460 -499
  366. package/dist/esm/performance/LocalizationRuntime.js +382 -422
  367. package/dist/esm/performance/MemoryManagement.js +415 -469
  368. package/dist/esm/performance/ModSupport.js +455 -495
  369. package/dist/esm/performance/MultiThreadedPhysics.js +408 -442
  370. package/dist/esm/performance/NetworkPrediction.js +436 -481
  371. package/dist/esm/performance/ObjectPooling.js +582 -616
  372. package/dist/esm/performance/Performance.js +182 -189
  373. package/dist/esm/performance/PerformanceAdvanced.js +621 -636
  374. package/dist/esm/performance/WebGPURenderer.js +660 -682
  375. package/dist/esm/physics/PhysicsAdvanced.js +359 -378
  376. package/dist/esm/physics/PhysicsEngine2D.js +393 -426
  377. package/dist/esm/plugins/PluginSDK.js +435 -465
  378. package/dist/esm/plugins/PluginTestKit.js +315 -329
  379. package/dist/esm/procedural/Procedural.js +248 -253
  380. package/dist/esm/procedural/WorldBuilding.js +316 -313
  381. package/dist/esm/quest/QuestSystem.js +982 -931
  382. package/dist/esm/release/MobileExport.js +163 -162
  383. package/dist/esm/release/Release.js +234 -237
  384. package/dist/esm/rendering/Camera2D.js +122 -123
  385. package/dist/esm/rendering/Renderer2D.js +323 -334
  386. package/dist/esm/rendering/WebGPURenderPipeline.js +647 -650
  387. package/dist/esm/runtime3d/Runtime3D.js +368 -377
  388. package/dist/esm/runtime3d/SceneEditor3D.js +268 -262
  389. package/dist/esm/scene/SceneManager.js +178 -192
  390. package/dist/esm/scripting/GraphToAST.js +576 -546
  391. package/dist/esm/scripting/LanguageExporter.js +263 -278
  392. package/dist/esm/scripting/NodeGraph.js +550 -569
  393. package/dist/esm/scripting/ScriptAST.js +45 -38
  394. package/dist/esm/scripting/VisualScripting2.js +1025 -1064
  395. package/dist/esm/scripting/exporters/CSharpExporter.js +465 -495
  396. package/dist/esm/scripting/exporters/GDScriptExporter.js +391 -441
  397. package/dist/esm/scripting/exporters/LuaExporter.js +407 -446
  398. package/dist/esm/scripting/exporters/PythonExporter.js +485 -548
  399. package/dist/esm/scripting/exporters/RustExporter.js +460 -511
  400. package/dist/esm/scripting/exporters/TypeScriptExporter.js +506 -555
  401. package/dist/esm/social/Social.js +77 -79
  402. package/dist/esm/systems/LightingSystem.js +855 -930
  403. package/dist/esm/systems/ParticleSystem2.js +1453 -1450
  404. package/dist/esm/systems/PhysicsDebugSystem.js +1078 -1140
  405. package/dist/esm/systems/TerrainSystem.js +996 -1097
  406. package/dist/esm/templates/ActionTemplates.js +307 -308
  407. package/dist/esm/templates/FightingTemplate.js +439 -462
  408. package/dist/esm/templates/MetroidvaniaTemplate.js +391 -404
  409. package/dist/esm/templates/PartyTemplates.js +206 -201
  410. package/dist/esm/templates/PuzzleTemplates.js +260 -260
  411. package/dist/esm/templates/RPGTemplates.js +172 -177
  412. package/dist/esm/templates/SportsTemplates.js +251 -249
  413. package/dist/esm/templates/StrategyTemplates.js +158 -152
  414. package/dist/esm/templates/SurvivalTemplate.js +367 -379
  415. package/dist/esm/templates/WaveDefense.js +501 -525
  416. package/dist/esm/tilemap/Tilemap.js +209 -213
  417. package/dist/esm/tutorials/TutorialBranching.js +399 -416
  418. package/dist/esm/tutorials/TutorialEngine.js +893 -930
  419. package/dist/esm/tutorials/TutorialOverlay.js +603 -639
  420. package/dist/esm/tutorials/content/Tutorials_T05_T08.js +792 -808
  421. package/dist/esm/tutorials/content/Tutorials_T09_T11.js +740 -755
  422. package/dist/esm/tutorials/content/Tutorials_T12_T15.js +759 -777
  423. package/dist/esm/ui/GameUI.js +296 -311
  424. package/dist/esm/unity-integration/UnityAssetStore.js +704 -740
  425. package/dist/esm/unity-integration/UnityImport.js +1071 -1175
  426. package/dist/esm/unity-integration/UnityLiveLink.js +938 -980
  427. package/dist/esm/unity-integration/components/UnityAssetStoreBrowser.js +1234 -756
  428. package/dist/esm/unity-integration/components/UnityProjectBrowser.js +1241 -767
  429. package/dist/esm/unreal-integration/UnrealImport.js +395 -411
  430. package/dist/esm/unreal-integration/UnrealLiveLink.js +1105 -1136
  431. package/dist/esm/unreal-integration/UnrealMarketplace.js +442 -472
  432. package/dist/esm/unreal-integration/components/UnrealProjectBrowser.js +1151 -766
  433. package/dist/esm/xr/ARVR.js +181 -174
  434. package/package.json +7 -12
@@ -1,967 +1,892 @@
1
- /**
2
- * @file LightingSystem.ts
3
- * @description Advanced Lighting System with Lightmap Baking and GI
4
- * PRO-1.4: Professional Editor Features
5
- *
6
- * Features:
7
- * - Light types (Directional, Point, Spot, Area)
8
- * - Light probes for indirect lighting
9
- * - Reflection probes
10
- * - Lightmap baking (progressive, GPU-accelerated)
11
- * - Global Illumination preview
12
- * - Shadow configuration
13
- * - Light cookies
14
- * - IES profiles
15
- */
16
1
  function createDirectionalLight(name) {
17
- return {
18
- id: `light_${Date.now()}`,
19
- name,
20
- type: 'directional',
21
- enabled: true,
22
- position: { x: 0, y: 10, z: 0 },
23
- rotation: { x: 50, y: -30, z: 0 },
24
- scale: { x: 1, y: 1, z: 1 },
25
- color: { r: 1, g: 0.96, b: 0.9, a: 1 },
26
- intensity: 1,
27
- indirectMultiplier: 1,
28
- range: Infinity,
29
- mode: 'mixed',
30
- renderMode: 'auto',
31
- spotAngle: 30,
32
- outerSpotAngle: 45,
33
- areaSize: { width: 1, height: 1 },
34
- areaLightType: 'rectangle',
35
- shadows: 'soft',
36
- shadowStrength: 1,
37
- shadowResolution: 2048,
38
- shadowBias: 0.05,
39
- shadowNormalBias: 0.4,
40
- shadowNearPlane: 0.2,
41
- shadowSoftness: 1,
42
- shadowSoftnessFalloff: 1,
43
- cullingMask: 0xffffffff,
44
- renderingLayerMask: 0xffffffff,
45
- cookieSize: 10,
46
- lightmapBakeType: 'mixed',
47
- affectsLightmaps: true,
48
- affectsSpecular: true,
49
- };
2
+ return {
3
+ id: `light_${Date.now()}`,
4
+ name,
5
+ type: "directional",
6
+ enabled: true,
7
+ position: { x: 0, y: 10, z: 0 },
8
+ rotation: { x: 50, y: -30, z: 0 },
9
+ scale: { x: 1, y: 1, z: 1 },
10
+ color: { r: 1, g: 0.96, b: 0.9, a: 1 },
11
+ intensity: 1,
12
+ indirectMultiplier: 1,
13
+ range: Infinity,
14
+ mode: "mixed",
15
+ renderMode: "auto",
16
+ spotAngle: 30,
17
+ outerSpotAngle: 45,
18
+ areaSize: { width: 1, height: 1 },
19
+ areaLightType: "rectangle",
20
+ shadows: "soft",
21
+ shadowStrength: 1,
22
+ shadowResolution: 2048,
23
+ shadowBias: 0.05,
24
+ shadowNormalBias: 0.4,
25
+ shadowNearPlane: 0.2,
26
+ shadowSoftness: 1,
27
+ shadowSoftnessFalloff: 1,
28
+ cullingMask: 4294967295,
29
+ renderingLayerMask: 4294967295,
30
+ cookieSize: 10,
31
+ lightmapBakeType: "mixed",
32
+ affectsLightmaps: true,
33
+ affectsSpecular: true
34
+ };
50
35
  }
51
36
  function createPointLight(name, position) {
52
- return {
53
- id: `light_${Date.now()}`,
54
- name,
55
- type: 'point',
56
- enabled: true,
57
- position,
58
- rotation: { x: 0, y: 0, z: 0 },
59
- scale: { x: 1, y: 1, z: 1 },
60
- color: { r: 1, g: 1, b: 1, a: 1 },
61
- intensity: 1,
62
- indirectMultiplier: 1,
63
- range: 10,
64
- mode: 'realtime',
65
- renderMode: 'auto',
66
- spotAngle: 30,
67
- outerSpotAngle: 45,
68
- areaSize: { width: 1, height: 1 },
69
- areaLightType: 'rectangle',
70
- shadows: 'soft',
71
- shadowStrength: 1,
72
- shadowResolution: 1024,
73
- shadowBias: 0.05,
74
- shadowNormalBias: 0.4,
75
- shadowNearPlane: 0.2,
76
- shadowSoftness: 1,
77
- shadowSoftnessFalloff: 1,
78
- cullingMask: 0xffffffff,
79
- renderingLayerMask: 0xffffffff,
80
- cookieSize: 10,
81
- lightmapBakeType: 'realtime',
82
- affectsLightmaps: false,
83
- affectsSpecular: true,
84
- };
37
+ return {
38
+ id: `light_${Date.now()}`,
39
+ name,
40
+ type: "point",
41
+ enabled: true,
42
+ position,
43
+ rotation: { x: 0, y: 0, z: 0 },
44
+ scale: { x: 1, y: 1, z: 1 },
45
+ color: { r: 1, g: 1, b: 1, a: 1 },
46
+ intensity: 1,
47
+ indirectMultiplier: 1,
48
+ range: 10,
49
+ mode: "realtime",
50
+ renderMode: "auto",
51
+ spotAngle: 30,
52
+ outerSpotAngle: 45,
53
+ areaSize: { width: 1, height: 1 },
54
+ areaLightType: "rectangle",
55
+ shadows: "soft",
56
+ shadowStrength: 1,
57
+ shadowResolution: 1024,
58
+ shadowBias: 0.05,
59
+ shadowNormalBias: 0.4,
60
+ shadowNearPlane: 0.2,
61
+ shadowSoftness: 1,
62
+ shadowSoftnessFalloff: 1,
63
+ cullingMask: 4294967295,
64
+ renderingLayerMask: 4294967295,
65
+ cookieSize: 10,
66
+ lightmapBakeType: "realtime",
67
+ affectsLightmaps: false,
68
+ affectsSpecular: true
69
+ };
85
70
  }
86
71
  function createSpotLight(name, position) {
87
- return {
88
- id: `light_${Date.now()}`,
89
- name,
90
- type: 'spot',
91
- enabled: true,
92
- position,
93
- rotation: { x: 90, y: 0, z: 0 }, // Pointing down
94
- scale: { x: 1, y: 1, z: 1 },
95
- color: { r: 1, g: 1, b: 1, a: 1 },
96
- intensity: 1,
97
- indirectMultiplier: 1,
98
- range: 10,
99
- mode: 'realtime',
100
- renderMode: 'auto',
101
- spotAngle: 30,
102
- outerSpotAngle: 45,
103
- areaSize: { width: 1, height: 1 },
104
- areaLightType: 'rectangle',
105
- shadows: 'soft',
106
- shadowStrength: 1,
107
- shadowResolution: 1024,
108
- shadowBias: 0.05,
109
- shadowNormalBias: 0.4,
110
- shadowNearPlane: 0.2,
111
- shadowSoftness: 1,
112
- shadowSoftnessFalloff: 1,
113
- cullingMask: 0xffffffff,
114
- renderingLayerMask: 0xffffffff,
115
- cookieSize: 10,
116
- lightmapBakeType: 'realtime',
117
- affectsLightmaps: false,
118
- affectsSpecular: true,
119
- };
72
+ return {
73
+ id: `light_${Date.now()}`,
74
+ name,
75
+ type: "spot",
76
+ enabled: true,
77
+ position,
78
+ rotation: { x: 90, y: 0, z: 0 },
79
+ // Pointing down
80
+ scale: { x: 1, y: 1, z: 1 },
81
+ color: { r: 1, g: 1, b: 1, a: 1 },
82
+ intensity: 1,
83
+ indirectMultiplier: 1,
84
+ range: 10,
85
+ mode: "realtime",
86
+ renderMode: "auto",
87
+ spotAngle: 30,
88
+ outerSpotAngle: 45,
89
+ areaSize: { width: 1, height: 1 },
90
+ areaLightType: "rectangle",
91
+ shadows: "soft",
92
+ shadowStrength: 1,
93
+ shadowResolution: 1024,
94
+ shadowBias: 0.05,
95
+ shadowNormalBias: 0.4,
96
+ shadowNearPlane: 0.2,
97
+ shadowSoftness: 1,
98
+ shadowSoftnessFalloff: 1,
99
+ cullingMask: 4294967295,
100
+ renderingLayerMask: 4294967295,
101
+ cookieSize: 10,
102
+ lightmapBakeType: "realtime",
103
+ affectsLightmaps: false,
104
+ affectsSpecular: true
105
+ };
120
106
  }
121
107
  function createAreaLight(name, position) {
122
- return {
123
- id: `light_${Date.now()}`,
124
- name,
125
- type: 'area',
126
- enabled: true,
127
- position,
128
- rotation: { x: 90, y: 0, z: 0 }, // Pointing down
129
- scale: { x: 1, y: 1, z: 1 },
130
- color: { r: 1, g: 1, b: 1, a: 1 },
131
- intensity: 1,
132
- indirectMultiplier: 1,
133
- range: 10,
134
- mode: 'baked',
135
- renderMode: 'auto',
136
- spotAngle: 30,
137
- outerSpotAngle: 45,
138
- areaSize: { width: 2, height: 2 },
139
- areaLightType: 'rectangle',
140
- shadows: 'soft',
141
- shadowStrength: 1,
142
- shadowResolution: 1024,
143
- shadowBias: 0.05,
144
- shadowNormalBias: 0.4,
145
- shadowNearPlane: 0.2,
146
- shadowSoftness: 1,
147
- shadowSoftnessFalloff: 1,
148
- cullingMask: 0xffffffff,
149
- renderingLayerMask: 0xffffffff,
150
- cookieSize: 10,
151
- lightmapBakeType: 'baked',
152
- affectsLightmaps: true,
153
- affectsSpecular: false,
154
- };
108
+ return {
109
+ id: `light_${Date.now()}`,
110
+ name,
111
+ type: "area",
112
+ enabled: true,
113
+ position,
114
+ rotation: { x: 90, y: 0, z: 0 },
115
+ // Pointing down
116
+ scale: { x: 1, y: 1, z: 1 },
117
+ color: { r: 1, g: 1, b: 1, a: 1 },
118
+ intensity: 1,
119
+ indirectMultiplier: 1,
120
+ range: 10,
121
+ mode: "baked",
122
+ renderMode: "auto",
123
+ spotAngle: 30,
124
+ outerSpotAngle: 45,
125
+ areaSize: { width: 2, height: 2 },
126
+ areaLightType: "rectangle",
127
+ shadows: "soft",
128
+ shadowStrength: 1,
129
+ shadowResolution: 1024,
130
+ shadowBias: 0.05,
131
+ shadowNormalBias: 0.4,
132
+ shadowNearPlane: 0.2,
133
+ shadowSoftness: 1,
134
+ shadowSoftnessFalloff: 1,
135
+ cullingMask: 4294967295,
136
+ renderingLayerMask: 4294967295,
137
+ cookieSize: 10,
138
+ lightmapBakeType: "baked",
139
+ affectsLightmaps: true,
140
+ affectsSpecular: false
141
+ };
155
142
  }
156
143
  function createLightProbeGroup(name) {
157
- return {
158
- id: `lpg_${Date.now()}`,
159
- name,
160
- probes: [],
161
- interpolationMode: 'linear',
162
- density: 2, // One probe per 2 units
163
- bounds: {
164
- min: { x: -10, y: 0, z: -10 },
165
- max: { x: 10, y: 5, z: 10 },
166
- },
167
- };
144
+ return {
145
+ id: `lpg_${Date.now()}`,
146
+ name,
147
+ probes: [],
148
+ interpolationMode: "linear",
149
+ density: 2,
150
+ // One probe per 2 units
151
+ bounds: {
152
+ min: { x: -10, y: 0, z: -10 },
153
+ max: { x: 10, y: 5, z: 10 }
154
+ }
155
+ };
168
156
  }
169
157
  function createLightProbe(position) {
170
- return {
171
- id: `lp_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
172
- position,
173
- sh: { coefficients: new Float32Array(27) },
174
- isValid: false,
175
- };
158
+ return {
159
+ id: `lp_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
160
+ position,
161
+ sh: { coefficients: new Float32Array(27) },
162
+ isValid: false
163
+ };
176
164
  }
177
165
  function createReflectionProbe(name, position) {
178
- return {
179
- id: `rp_${Date.now()}`,
180
- name,
181
- position,
182
- rotation: { x: 0, y: 0, z: 0 },
183
- type: 'baked',
184
- refreshMode: 'onAwake',
185
- timeSlicing: 'allFacesAtOnce',
186
- size: { x: 10, y: 10, z: 10 },
187
- center: { x: 0, y: 0, z: 0 },
188
- blendDistance: 1,
189
- boxProjection: false,
190
- resolution: 256,
191
- hdr: true,
192
- shadowDistance: 100,
193
- clearFlags: 'skybox',
194
- backgroundColor: { r: 0.2, g: 0.2, b: 0.2, a: 1 },
195
- cullingMask: 0xffffffff,
196
- nearClip: 0.3,
197
- farClip: 1000,
198
- intensity: 1,
199
- importance: 1,
200
- isValid: false,
201
- };
166
+ return {
167
+ id: `rp_${Date.now()}`,
168
+ name,
169
+ position,
170
+ rotation: { x: 0, y: 0, z: 0 },
171
+ type: "baked",
172
+ refreshMode: "onAwake",
173
+ timeSlicing: "allFacesAtOnce",
174
+ size: { x: 10, y: 10, z: 10 },
175
+ center: { x: 0, y: 0, z: 0 },
176
+ blendDistance: 1,
177
+ boxProjection: false,
178
+ resolution: 256,
179
+ hdr: true,
180
+ shadowDistance: 100,
181
+ clearFlags: "skybox",
182
+ backgroundColor: { r: 0.2, g: 0.2, b: 0.2, a: 1 },
183
+ cullingMask: 4294967295,
184
+ nearClip: 0.3,
185
+ farClip: 1e3,
186
+ intensity: 1,
187
+ importance: 1,
188
+ isValid: false
189
+ };
202
190
  }
203
191
  const DEFAULT_LIGHTMAP_SETTINGS = {
204
- mode: 'directional',
205
- mixedMode: 'bakedIndirect',
206
- lightmapper: 'progressiveGPU',
207
- prioritizeView: false,
208
- multipleImportanceSampling: true,
209
- lightmapResolution: 40,
210
- lightmapPadding: 2,
211
- maxLightmapSize: 2048,
212
- compressLightmaps: true,
213
- directSamples: 32,
214
- indirectSamples: 512,
215
- bounces: 3,
216
- denoiser: 'openImageDenoise',
217
- filteringMode: 'auto',
218
- directFilter: 0.5,
219
- indirectFilter: 5,
220
- ambientOcclusionFilter: 2.5,
221
- ambientOcclusion: true,
222
- aoMaxDistance: 1,
223
- aoIndirectContribution: 1,
224
- aoDirectContribution: 0,
225
- environmentLighting: 'skybox',
226
- skyColor: { r: 0.53, g: 0.81, b: 0.92, a: 1 },
227
- equatorColor: { r: 0.96, g: 0.91, b: 0.77, a: 1 },
228
- groundColor: { r: 0.37, g: 0.33, b: 0.27, a: 1 },
229
- environmentIntensity: 1,
230
- albedoBoost: 1,
231
- indirectIntensity: 1,
232
- extractAO: false,
192
+ mode: "directional",
193
+ mixedMode: "bakedIndirect",
194
+ lightmapper: "progressiveGPU",
195
+ prioritizeView: false,
196
+ multipleImportanceSampling: true,
197
+ lightmapResolution: 40,
198
+ lightmapPadding: 2,
199
+ maxLightmapSize: 2048,
200
+ compressLightmaps: true,
201
+ directSamples: 32,
202
+ indirectSamples: 512,
203
+ bounces: 3,
204
+ denoiser: "openImageDenoise",
205
+ filteringMode: "auto",
206
+ directFilter: 0.5,
207
+ indirectFilter: 5,
208
+ ambientOcclusionFilter: 2.5,
209
+ ambientOcclusion: true,
210
+ aoMaxDistance: 1,
211
+ aoIndirectContribution: 1,
212
+ aoDirectContribution: 0,
213
+ environmentLighting: "skybox",
214
+ skyColor: { r: 0.53, g: 0.81, b: 0.92, a: 1 },
215
+ equatorColor: { r: 0.96, g: 0.91, b: 0.77, a: 1 },
216
+ groundColor: { r: 0.37, g: 0.33, b: 0.27, a: 1 },
217
+ environmentIntensity: 1,
218
+ albedoBoost: 1,
219
+ indirectIntensity: 1,
220
+ extractAO: false
233
221
  };
234
- // ============================================================
235
- // Lighting System Class
236
- // ============================================================
237
222
  class LightingSystem {
238
- constructor() {
239
- this.lights = [];
240
- this.lightProbeGroups = [];
241
- this.reflectionProbes = [];
242
- this.lightmaps = [];
243
- this.lightmapUVs = [];
244
- this.settings = { ...DEFAULT_LIGHTMAP_SETTINGS };
245
- this.bakeProgress = {
246
- phase: 'idle',
247
- progress: 0,
248
- totalProgress: 0,
249
- currentBounce: 0,
250
- totalBounces: 0,
251
- samplesRendered: 0,
252
- totalSamples: 0,
253
- lightmapsCompleted: 0,
254
- totalLightmaps: 0,
255
- probesCompleted: 0,
256
- totalProbes: 0,
257
- reflectionProbesCompleted: 0,
258
- totalReflectionProbes: 0,
259
- elapsedTime: 0,
260
- estimatedRemainingTime: 0,
261
- message: '',
262
- };
263
- this.bakeAbort = false;
264
- this.bakeCallbacks = [];
265
- }
266
- // ─── Light Management ──────────────────────────────────
267
- addLight(light) {
268
- this.lights.push(light);
269
- }
270
- removeLight(lightId) {
271
- this.lights = this.lights.filter((l) => l.id !== lightId);
272
- }
273
- getLight(lightId) {
274
- return this.lights.find((l) => l.id === lightId);
275
- }
276
- getAllLights() {
277
- return [...this.lights];
278
- }
279
- getRealtimeLights() {
280
- return this.lights.filter((l) => l.mode === 'realtime' || l.mode === 'mixed');
281
- }
282
- getBakedLights() {
283
- return this.lights.filter((l) => l.mode === 'baked' || l.mode === 'mixed');
284
- }
285
- // ─── Light Probe Management ────────────────────────────
286
- addLightProbeGroup(group) {
287
- this.lightProbeGroups.push(group);
288
- }
289
- removeLightProbeGroup(groupId) {
290
- this.lightProbeGroups = this.lightProbeGroups.filter((g) => g.id !== groupId);
291
- }
292
- getLightProbeGroup(groupId) {
293
- return this.lightProbeGroups.find((g) => g.id === groupId);
294
- }
295
- getAllLightProbeGroups() {
296
- return [...this.lightProbeGroups];
297
- }
298
- /** Auto-generate probes within bounds */
299
- autoGenerateProbes(groupId) {
300
- const group = this.getLightProbeGroup(groupId);
301
- if (!group) {
302
- return;
303
- }
304
- group.probes = [];
305
- const { min, max } = group.bounds;
306
- const density = group.density;
307
- const stepsX = Math.ceil((max.x - min.x) / density);
308
- const stepsY = Math.ceil((max.y - min.y) / density);
309
- const stepsZ = Math.ceil((max.z - min.z) / density);
310
- for (let y = 0; y <= stepsY; y++) {
311
- for (let z = 0; z <= stepsZ; z++) {
312
- for (let x = 0; x <= stepsX; x++) {
313
- const pos = {
314
- x: min.x + (x / stepsX) * (max.x - min.x),
315
- y: min.y + (y / stepsY) * (max.y - min.y),
316
- z: min.z + (z / stepsZ) * (max.z - min.z),
317
- };
318
- group.probes.push(createLightProbe(pos));
319
- }
320
- }
321
- }
322
- }
323
- /** Get interpolated spherical harmonics at a position */
324
- sampleLightProbes(position) {
325
- // Find contributing probes and interpolate
326
- const allProbes = [];
327
- for (const group of this.lightProbeGroups) {
328
- for (const probe of group.probes) {
329
- if (!probe.isValid) {
330
- continue;
331
- }
332
- const dx = position.x - probe.position.x;
333
- const dy = position.y - probe.position.y;
334
- const dz = position.z - probe.position.z;
335
- const dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
336
- allProbes.push({ probe, distance: dist });
337
- }
338
- }
339
- if (allProbes.length === 0) {
340
- return null;
341
- }
342
- // Sort by distance
343
- allProbes.sort((a, b) => a.distance - b.distance);
344
- // Use tetrahedral interpolation (simplified to 4 nearest)
345
- const nearest = allProbes.slice(0, 4);
346
- const result = new Float32Array(27);
347
- // Calculate weights (inverse distance)
348
- let totalWeight = 0;
349
- const weights = [];
350
- for (const { distance } of nearest) {
351
- const weight = 1 / (distance + 0.001);
352
- weights.push(weight);
353
- totalWeight += weight;
354
- }
355
- // Interpolate SH coefficients
356
- for (let i = 0; i < nearest.length; i++) {
357
- const weight = weights[i] / totalWeight;
358
- const sh = nearest[i].probe.sh.coefficients;
359
- for (let j = 0; j < 27; j++) {
360
- result[j] += sh[j] * weight;
361
- }
362
- }
363
- return { coefficients: result };
364
- }
365
- // ─── Reflection Probe Management ───────────────────────
366
- addReflectionProbe(probe) {
367
- this.reflectionProbes.push(probe);
368
- }
369
- removeReflectionProbe(probeId) {
370
- this.reflectionProbes = this.reflectionProbes.filter((p) => p.id !== probeId);
371
- }
372
- getReflectionProbe(probeId) {
373
- return this.reflectionProbes.find((p) => p.id === probeId);
374
- }
375
- getAllReflectionProbes() {
376
- return [...this.reflectionProbes];
377
- }
378
- /** Get blended reflection at a position */
379
- sampleReflection(position) {
380
- // Find overlapping probes sorted by importance
381
- const overlapping = [];
382
- for (const probe of this.reflectionProbes) {
383
- if (!probe.isValid) {
384
- continue;
385
- }
386
- // Check if position is within probe bounds
387
- const localPos = {
388
- x: position.x - probe.position.x - probe.center.x,
389
- y: position.y - probe.position.y - probe.center.y,
390
- z: position.z - probe.position.z - probe.center.z,
391
- };
392
- const halfSize = {
393
- x: probe.size.x / 2 + probe.blendDistance,
394
- y: probe.size.y / 2 + probe.blendDistance,
395
- z: probe.size.z / 2 + probe.blendDistance,
396
- };
397
- if (Math.abs(localPos.x) <= halfSize.x &&
398
- Math.abs(localPos.y) <= halfSize.y &&
399
- Math.abs(localPos.z) <= halfSize.z) {
400
- overlapping.push(probe);
401
- }
223
+ constructor() {
224
+ this.lights = [];
225
+ this.lightProbeGroups = [];
226
+ this.reflectionProbes = [];
227
+ this.lightmaps = [];
228
+ this.lightmapUVs = [];
229
+ this.settings = { ...DEFAULT_LIGHTMAP_SETTINGS };
230
+ this.bakeProgress = {
231
+ phase: "idle",
232
+ progress: 0,
233
+ totalProgress: 0,
234
+ currentBounce: 0,
235
+ totalBounces: 0,
236
+ samplesRendered: 0,
237
+ totalSamples: 0,
238
+ lightmapsCompleted: 0,
239
+ totalLightmaps: 0,
240
+ probesCompleted: 0,
241
+ totalProbes: 0,
242
+ reflectionProbesCompleted: 0,
243
+ totalReflectionProbes: 0,
244
+ elapsedTime: 0,
245
+ estimatedRemainingTime: 0,
246
+ message: ""
247
+ };
248
+ this.bakeAbort = false;
249
+ this.bakeCallbacks = [];
250
+ }
251
+ // ─── Light Management ──────────────────────────────────
252
+ addLight(light) {
253
+ this.lights.push(light);
254
+ }
255
+ removeLight(lightId) {
256
+ this.lights = this.lights.filter((l) => l.id !== lightId);
257
+ }
258
+ getLight(lightId) {
259
+ return this.lights.find((l) => l.id === lightId);
260
+ }
261
+ getAllLights() {
262
+ return [...this.lights];
263
+ }
264
+ getRealtimeLights() {
265
+ return this.lights.filter((l) => l.mode === "realtime" || l.mode === "mixed");
266
+ }
267
+ getBakedLights() {
268
+ return this.lights.filter((l) => l.mode === "baked" || l.mode === "mixed");
269
+ }
270
+ // ─── Light Probe Management ────────────────────────────
271
+ addLightProbeGroup(group) {
272
+ this.lightProbeGroups.push(group);
273
+ }
274
+ removeLightProbeGroup(groupId) {
275
+ this.lightProbeGroups = this.lightProbeGroups.filter((g) => g.id !== groupId);
276
+ }
277
+ getLightProbeGroup(groupId) {
278
+ return this.lightProbeGroups.find((g) => g.id === groupId);
279
+ }
280
+ getAllLightProbeGroups() {
281
+ return [...this.lightProbeGroups];
282
+ }
283
+ /** Auto-generate probes within bounds */
284
+ autoGenerateProbes(groupId) {
285
+ const group = this.getLightProbeGroup(groupId);
286
+ if (!group) {
287
+ return;
288
+ }
289
+ group.probes = [];
290
+ const { min, max } = group.bounds;
291
+ const density = group.density;
292
+ const stepsX = Math.ceil((max.x - min.x) / density);
293
+ const stepsY = Math.ceil((max.y - min.y) / density);
294
+ const stepsZ = Math.ceil((max.z - min.z) / density);
295
+ for (let y = 0; y <= stepsY; y++) {
296
+ for (let z = 0; z <= stepsZ; z++) {
297
+ for (let x = 0; x <= stepsX; x++) {
298
+ const pos = {
299
+ x: min.x + x / stepsX * (max.x - min.x),
300
+ y: min.y + y / stepsY * (max.y - min.y),
301
+ z: min.z + z / stepsZ * (max.z - min.z)
302
+ };
303
+ group.probes.push(createLightProbe(pos));
402
304
  }
403
- if (overlapping.length === 0) {
404
- return null;
305
+ }
306
+ }
307
+ }
308
+ /** Get interpolated spherical harmonics at a position */
309
+ sampleLightProbes(position) {
310
+ const allProbes = [];
311
+ for (const group of this.lightProbeGroups) {
312
+ for (const probe of group.probes) {
313
+ if (!probe.isValid) {
314
+ continue;
405
315
  }
406
- // Sort by importance
407
- overlapping.sort((a, b) => b.importance - a.importance);
408
- // Return highest importance probe (in real implementation, blend between them)
409
- return overlapping[0].bakedCubemapId ?? null;
410
- }
411
- // ─── Settings ──────────────────────────────────────────
412
- getSettings() {
413
- return { ...this.settings };
414
- }
415
- setSettings(settings) {
416
- this.settings = { ...this.settings, ...settings };
417
- }
418
- // ─── Lightmap Baking ───────────────────────────────────
419
- onBakeProgress(callback) {
420
- this.bakeCallbacks.push(callback);
421
- return () => {
422
- this.bakeCallbacks = this.bakeCallbacks.filter((c) => c !== callback);
423
- };
424
- }
425
- emitProgress() {
426
- for (const callback of this.bakeCallbacks) {
427
- callback({ ...this.bakeProgress });
316
+ const dx = position.x - probe.position.x;
317
+ const dy = position.y - probe.position.y;
318
+ const dz = position.z - probe.position.z;
319
+ const dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
320
+ allProbes.push({ probe, distance: dist });
321
+ }
322
+ }
323
+ if (allProbes.length === 0) {
324
+ return null;
325
+ }
326
+ allProbes.sort((a, b) => a.distance - b.distance);
327
+ const nearest = allProbes.slice(0, 4);
328
+ const result = new Float32Array(27);
329
+ let totalWeight = 0;
330
+ const weights = [];
331
+ for (const { distance } of nearest) {
332
+ const weight = 1 / (distance + 1e-3);
333
+ weights.push(weight);
334
+ totalWeight += weight;
335
+ }
336
+ for (let i = 0; i < nearest.length; i++) {
337
+ const weight = weights[i] / totalWeight;
338
+ const sh = nearest[i].probe.sh.coefficients;
339
+ for (let j = 0; j < 27; j++) {
340
+ result[j] += sh[j] * weight;
341
+ }
342
+ }
343
+ return { coefficients: result };
344
+ }
345
+ // ─── Reflection Probe Management ───────────────────────
346
+ addReflectionProbe(probe) {
347
+ this.reflectionProbes.push(probe);
348
+ }
349
+ removeReflectionProbe(probeId) {
350
+ this.reflectionProbes = this.reflectionProbes.filter((p) => p.id !== probeId);
351
+ }
352
+ getReflectionProbe(probeId) {
353
+ return this.reflectionProbes.find((p) => p.id === probeId);
354
+ }
355
+ getAllReflectionProbes() {
356
+ return [...this.reflectionProbes];
357
+ }
358
+ /** Get blended reflection at a position */
359
+ sampleReflection(position) {
360
+ const overlapping = [];
361
+ for (const probe of this.reflectionProbes) {
362
+ if (!probe.isValid) {
363
+ continue;
364
+ }
365
+ const localPos = {
366
+ x: position.x - probe.position.x - probe.center.x,
367
+ y: position.y - probe.position.y - probe.center.y,
368
+ z: position.z - probe.position.z - probe.center.z
369
+ };
370
+ const halfSize = {
371
+ x: probe.size.x / 2 + probe.blendDistance,
372
+ y: probe.size.y / 2 + probe.blendDistance,
373
+ z: probe.size.z / 2 + probe.blendDistance
374
+ };
375
+ if (Math.abs(localPos.x) <= halfSize.x && Math.abs(localPos.y) <= halfSize.y && Math.abs(localPos.z) <= halfSize.z) {
376
+ overlapping.push(probe);
377
+ }
378
+ }
379
+ if (overlapping.length === 0) {
380
+ return null;
381
+ }
382
+ overlapping.sort((a, b) => b.importance - a.importance);
383
+ return overlapping[0].bakedCubemapId ?? null;
384
+ }
385
+ // ─── Settings ──────────────────────────────────────────
386
+ getSettings() {
387
+ return { ...this.settings };
388
+ }
389
+ setSettings(settings) {
390
+ this.settings = { ...this.settings, ...settings };
391
+ }
392
+ // ─── Lightmap Baking ───────────────────────────────────
393
+ onBakeProgress(callback) {
394
+ this.bakeCallbacks.push(callback);
395
+ return () => {
396
+ this.bakeCallbacks = this.bakeCallbacks.filter((c) => c !== callback);
397
+ };
398
+ }
399
+ emitProgress() {
400
+ for (const callback of this.bakeCallbacks) {
401
+ callback({ ...this.bakeProgress });
402
+ }
403
+ }
404
+ async startBake(entityBounds) {
405
+ this.bakeAbort = false;
406
+ const startTime = Date.now();
407
+ this.bakeProgress = {
408
+ phase: "preparing",
409
+ progress: 0,
410
+ totalProgress: 0,
411
+ currentBounce: 0,
412
+ totalBounces: this.settings.bounces,
413
+ samplesRendered: 0,
414
+ totalSamples: this.settings.directSamples + this.settings.indirectSamples,
415
+ lightmapsCompleted: 0,
416
+ totalLightmaps: 0,
417
+ probesCompleted: 0,
418
+ totalProbes: this.countTotalProbes(),
419
+ reflectionProbesCompleted: 0,
420
+ totalReflectionProbes: this.reflectionProbes.length,
421
+ elapsedTime: 0,
422
+ estimatedRemainingTime: 0,
423
+ message: "Preparing scene..."
424
+ };
425
+ this.emitProgress();
426
+ try {
427
+ await this.prepareForBake(entityBounds);
428
+ if (this.bakeAbort) {
429
+ throw new Error("Bake cancelled");
430
+ }
431
+ this.bakeProgress.phase = "directLighting";
432
+ this.bakeProgress.message = "Computing direct lighting...";
433
+ this.emitProgress();
434
+ await this.bakeDirectLighting();
435
+ if (this.bakeAbort) {
436
+ throw new Error("Bake cancelled");
437
+ }
438
+ this.bakeProgress.phase = "indirectLighting";
439
+ this.bakeProgress.message = "Computing indirect lighting...";
440
+ this.emitProgress();
441
+ for (let bounce = 0; bounce < this.settings.bounces; bounce++) {
442
+ this.bakeProgress.currentBounce = bounce + 1;
443
+ this.bakeProgress.message = `Computing bounce ${bounce + 1}/${this.settings.bounces}...`;
444
+ this.emitProgress();
445
+ await this.bakeIndirectBounce(bounce);
446
+ if (this.bakeAbort) {
447
+ throw new Error("Bake cancelled");
428
448
  }
429
- }
430
- async startBake(entityBounds) {
431
- this.bakeAbort = false;
432
- const startTime = Date.now();
433
- // Reset progress
434
- this.bakeProgress = {
435
- phase: 'preparing',
436
- progress: 0,
437
- totalProgress: 0,
438
- currentBounce: 0,
439
- totalBounces: this.settings.bounces,
440
- samplesRendered: 0,
441
- totalSamples: this.settings.directSamples + this.settings.indirectSamples,
442
- lightmapsCompleted: 0,
443
- totalLightmaps: 0,
444
- probesCompleted: 0,
445
- totalProbes: this.countTotalProbes(),
446
- reflectionProbesCompleted: 0,
447
- totalReflectionProbes: this.reflectionProbes.length,
448
- elapsedTime: 0,
449
- estimatedRemainingTime: 0,
450
- message: 'Preparing scene...',
451
- };
449
+ }
450
+ if (this.settings.denoiser !== "none") {
451
+ this.bakeProgress.phase = "denoising";
452
+ this.bakeProgress.message = "Denoising lightmaps...";
452
453
  this.emitProgress();
453
- try {
454
- // Phase 1: Prepare
455
- await this.prepareForBake(entityBounds);
456
- if (this.bakeAbort) {
457
- throw new Error('Bake cancelled');
458
- }
459
- // Phase 2: Direct Lighting
460
- this.bakeProgress.phase = 'directLighting';
461
- this.bakeProgress.message = 'Computing direct lighting...';
462
- this.emitProgress();
463
- await this.bakeDirectLighting();
464
- if (this.bakeAbort) {
465
- throw new Error('Bake cancelled');
466
- }
467
- // Phase 3: Indirect Lighting (bounces)
468
- this.bakeProgress.phase = 'indirectLighting';
469
- this.bakeProgress.message = 'Computing indirect lighting...';
470
- this.emitProgress();
471
- for (let bounce = 0; bounce < this.settings.bounces; bounce++) {
472
- this.bakeProgress.currentBounce = bounce + 1;
473
- this.bakeProgress.message = `Computing bounce ${bounce + 1}/${this.settings.bounces}...`;
474
- this.emitProgress();
475
- await this.bakeIndirectBounce(bounce);
476
- if (this.bakeAbort) {
477
- throw new Error('Bake cancelled');
478
- }
479
- }
480
- // Phase 4: Denoising
481
- if (this.settings.denoiser !== 'none') {
482
- this.bakeProgress.phase = 'denoising';
483
- this.bakeProgress.message = 'Denoising lightmaps...';
484
- this.emitProgress();
485
- await this.denoiseLightmaps();
486
- if (this.bakeAbort) {
487
- throw new Error('Bake cancelled');
488
- }
489
- }
490
- // Phase 5: Compositing
491
- this.bakeProgress.phase = 'compositing';
492
- this.bakeProgress.message = 'Compositing final lightmaps...';
493
- this.emitProgress();
494
- await this.compositeLightmaps();
495
- if (this.bakeAbort) {
496
- throw new Error('Bake cancelled');
497
- }
498
- // Phase 6: Light Probes
499
- this.bakeProgress.phase = 'probes';
500
- this.bakeProgress.message = 'Baking light probes...';
501
- this.emitProgress();
502
- await this.bakeLightProbes();
503
- if (this.bakeAbort) {
504
- throw new Error('Bake cancelled');
505
- }
506
- // Phase 7: Reflection Probes
507
- this.bakeProgress.phase = 'reflections';
508
- this.bakeProgress.message = 'Baking reflection probes...';
509
- this.emitProgress();
510
- await this.bakeReflectionProbes();
511
- if (this.bakeAbort) {
512
- throw new Error('Bake cancelled');
513
- }
514
- // Finished
515
- this.bakeProgress.phase = 'finished';
516
- this.bakeProgress.progress = 1;
517
- this.bakeProgress.totalProgress = 1;
518
- this.bakeProgress.message = 'Bake completed successfully';
519
- this.bakeProgress.elapsedTime = Date.now() - startTime;
520
- this.emitProgress();
454
+ await this.denoiseLightmaps();
455
+ if (this.bakeAbort) {
456
+ throw new Error("Bake cancelled");
521
457
  }
522
- catch (error) {
523
- if (this.bakeAbort) {
524
- this.bakeProgress.phase = 'cancelled';
525
- this.bakeProgress.message = 'Bake cancelled by user';
526
- }
527
- else {
528
- this.bakeProgress.phase = 'error';
529
- this.bakeProgress.message = `Bake failed: ${error}`;
458
+ }
459
+ this.bakeProgress.phase = "compositing";
460
+ this.bakeProgress.message = "Compositing final lightmaps...";
461
+ this.emitProgress();
462
+ await this.compositeLightmaps();
463
+ if (this.bakeAbort) {
464
+ throw new Error("Bake cancelled");
465
+ }
466
+ this.bakeProgress.phase = "probes";
467
+ this.bakeProgress.message = "Baking light probes...";
468
+ this.emitProgress();
469
+ await this.bakeLightProbes();
470
+ if (this.bakeAbort) {
471
+ throw new Error("Bake cancelled");
472
+ }
473
+ this.bakeProgress.phase = "reflections";
474
+ this.bakeProgress.message = "Baking reflection probes...";
475
+ this.emitProgress();
476
+ await this.bakeReflectionProbes();
477
+ if (this.bakeAbort) {
478
+ throw new Error("Bake cancelled");
479
+ }
480
+ this.bakeProgress.phase = "finished";
481
+ this.bakeProgress.progress = 1;
482
+ this.bakeProgress.totalProgress = 1;
483
+ this.bakeProgress.message = "Bake completed successfully";
484
+ this.bakeProgress.elapsedTime = Date.now() - startTime;
485
+ this.emitProgress();
486
+ } catch (error) {
487
+ if (this.bakeAbort) {
488
+ this.bakeProgress.phase = "cancelled";
489
+ this.bakeProgress.message = "Bake cancelled by user";
490
+ } else {
491
+ this.bakeProgress.phase = "error";
492
+ this.bakeProgress.message = `Bake failed: ${error}`;
493
+ }
494
+ this.emitProgress();
495
+ }
496
+ }
497
+ cancelBake() {
498
+ this.bakeAbort = true;
499
+ }
500
+ getBakeProgress() {
501
+ return { ...this.bakeProgress };
502
+ }
503
+ countTotalProbes() {
504
+ let count = 0;
505
+ for (const group of this.lightProbeGroups) {
506
+ count += group.probes.length;
507
+ }
508
+ return count;
509
+ }
510
+ async prepareForBake(entityBounds) {
511
+ const totalArea = this.calculateTotalLightmapArea(entityBounds);
512
+ const texelsPerUnit = this.settings.lightmapResolution;
513
+ const maxSize = this.settings.maxLightmapSize;
514
+ const totalTexels = totalArea * texelsPerUnit * texelsPerUnit;
515
+ const texelsPerLightmap = maxSize * maxSize;
516
+ this.bakeProgress.totalLightmaps = Math.ceil(totalTexels / texelsPerLightmap);
517
+ this.lightmapUVs = this.packLightmapUVs(entityBounds);
518
+ this.lightmaps = [];
519
+ for (let i = 0; i < this.bakeProgress.totalLightmaps; i++) {
520
+ this.lightmaps.push({
521
+ id: `lm_${i}`,
522
+ colorData: new Uint8Array(maxSize * maxSize * 4),
523
+ width: maxSize,
524
+ height: maxSize,
525
+ isHDR: true
526
+ });
527
+ if (this.settings.mode === "directional") {
528
+ this.lightmaps[i].directionData = new Uint8Array(maxSize * maxSize * 4);
529
+ }
530
+ if (this.settings.mixedMode === "shadowmask") {
531
+ this.lightmaps[i].shadowmaskData = new Uint8Array(maxSize * maxSize * 4);
532
+ }
533
+ }
534
+ await this.sleep(10);
535
+ }
536
+ calculateTotalLightmapArea(entityBounds) {
537
+ let area = 0;
538
+ for (const bounds of entityBounds.values()) {
539
+ const dx = bounds.max.x - bounds.min.x;
540
+ const dy = bounds.max.y - bounds.min.y;
541
+ const dz = bounds.max.z - bounds.min.z;
542
+ area += 2 * (dx * dy + dy * dz + dx * dz);
543
+ }
544
+ return area;
545
+ }
546
+ packLightmapUVs(entityBounds) {
547
+ const uvs = [];
548
+ let currentLightmap = 0;
549
+ let currentU = 0;
550
+ let currentV = 0;
551
+ let rowHeight = 0;
552
+ const maxSize = this.settings.maxLightmapSize;
553
+ const padding = this.settings.lightmapPadding;
554
+ for (const [entityId, bounds] of entityBounds) {
555
+ const dx = bounds.max.x - bounds.min.x;
556
+ const dy = bounds.max.y - bounds.min.y;
557
+ const texelsX = Math.ceil(dx * this.settings.lightmapResolution) + padding * 2;
558
+ const texelsY = Math.ceil(dy * this.settings.lightmapResolution) + padding * 2;
559
+ if (currentU + texelsX > maxSize) {
560
+ currentU = 0;
561
+ currentV += rowHeight + padding;
562
+ rowHeight = 0;
563
+ }
564
+ if (currentV + texelsY > maxSize) {
565
+ currentLightmap++;
566
+ currentU = 0;
567
+ currentV = 0;
568
+ rowHeight = 0;
569
+ }
570
+ uvs.push({
571
+ entityId,
572
+ lightmapIndex: currentLightmap,
573
+ uvOffset: { x: currentU / maxSize, y: currentV / maxSize },
574
+ uvScale: { x: texelsX / maxSize, y: texelsY / maxSize }
575
+ });
576
+ currentU += texelsX + padding;
577
+ rowHeight = Math.max(rowHeight, texelsY);
578
+ }
579
+ return uvs;
580
+ }
581
+ async bakeDirectLighting() {
582
+ const bakedLights = this.getBakedLights();
583
+ const totalSamples = this.settings.directSamples;
584
+ for (let sample = 0; sample < totalSamples; sample++) {
585
+ for (const lightmap of this.lightmaps) {
586
+ for (let y = 0; y < lightmap.height; y++) {
587
+ for (let x = 0; x < lightmap.width; x++) {
588
+ let r = 0, g = 0, b = 0;
589
+ for (const light of bakedLights) {
590
+ const contribution = this.calculateDirectLighting(x, y, lightmap, light, sample);
591
+ r += contribution.r;
592
+ g += contribution.g;
593
+ b += contribution.b;
530
594
  }
531
- this.emitProgress();
595
+ const idx = (y * lightmap.width + x) * 4;
596
+ lightmap.colorData[idx] = Math.min(255, lightmap.colorData[idx] + r);
597
+ lightmap.colorData[idx + 1] = Math.min(255, lightmap.colorData[idx + 1] + g);
598
+ lightmap.colorData[idx + 2] = Math.min(255, lightmap.colorData[idx + 2] + b);
599
+ lightmap.colorData[idx + 3] = 255;
600
+ }
532
601
  }
533
- }
534
- cancelBake() {
535
- this.bakeAbort = true;
536
- }
537
- getBakeProgress() {
538
- return { ...this.bakeProgress };
539
- }
540
- countTotalProbes() {
541
- let count = 0;
542
- for (const group of this.lightProbeGroups) {
543
- count += group.probes.length;
544
- }
545
- return count;
546
- }
547
- async prepareForBake(entityBounds) {
548
- // Calculate how many lightmaps we need
549
- const totalArea = this.calculateTotalLightmapArea(entityBounds);
550
- const texelsPerUnit = this.settings.lightmapResolution;
551
- const maxSize = this.settings.maxLightmapSize;
552
- const totalTexels = totalArea * texelsPerUnit * texelsPerUnit;
553
- const texelsPerLightmap = maxSize * maxSize;
554
- this.bakeProgress.totalLightmaps = Math.ceil(totalTexels / texelsPerLightmap);
555
- // Assign UV coordinates to entities
556
- this.lightmapUVs = this.packLightmapUVs(entityBounds);
557
- // Initialize lightmaps
558
- this.lightmaps = [];
559
- for (let i = 0; i < this.bakeProgress.totalLightmaps; i++) {
560
- this.lightmaps.push({
561
- id: `lm_${i}`,
562
- colorData: new Uint8Array(maxSize * maxSize * 4),
563
- width: maxSize,
564
- height: maxSize,
565
- isHDR: true,
566
- });
567
- if (this.settings.mode === 'directional') {
568
- this.lightmaps[i].directionData = new Uint8Array(maxSize * maxSize * 4);
569
- }
570
- if (this.settings.mixedMode === 'shadowmask') {
571
- this.lightmaps[i].shadowmaskData = new Uint8Array(maxSize * maxSize * 4);
572
- }
602
+ }
603
+ this.bakeProgress.samplesRendered = sample + 1;
604
+ this.bakeProgress.progress = (sample + 1) / totalSamples;
605
+ this.emitProgress();
606
+ if (sample % 4 === 0) {
607
+ await this.sleep(1);
608
+ }
609
+ }
610
+ }
611
+ calculateDirectLighting(x, y, lightmap, light, _sample) {
612
+ const intensity = light.intensity;
613
+ const falloff = 1;
614
+ return {
615
+ r: light.color.r * intensity * falloff * 2,
616
+ // Scaled for 8-bit accumulation
617
+ g: light.color.g * intensity * falloff * 2,
618
+ b: light.color.b * intensity * falloff * 2,
619
+ a: 1
620
+ };
621
+ }
622
+ async bakeIndirectBounce(bounceIndex) {
623
+ const totalSamples = this.settings.indirectSamples / this.settings.bounces;
624
+ for (let sample = 0; sample < totalSamples; sample++) {
625
+ for (const lightmap of this.lightmaps) {
626
+ for (let y = 0; y < lightmap.height; y++) {
627
+ for (let x = 0; x < lightmap.width; x++) {
628
+ const indirect = this.sampleIndirectLighting(x, y, lightmap, sample, bounceIndex);
629
+ const idx = (y * lightmap.width + x) * 4;
630
+ lightmap.colorData[idx] = Math.min(255, lightmap.colorData[idx] + indirect.r);
631
+ lightmap.colorData[idx + 1] = Math.min(255, lightmap.colorData[idx + 1] + indirect.g);
632
+ lightmap.colorData[idx + 2] = Math.min(255, lightmap.colorData[idx + 2] + indirect.b);
633
+ }
573
634
  }
574
- await this.sleep(10); // Yield to UI
575
- }
576
- calculateTotalLightmapArea(entityBounds) {
577
- let area = 0;
578
- for (const bounds of entityBounds.values()) {
579
- // Calculate surface area of bounds
580
- const dx = bounds.max.x - bounds.min.x;
581
- const dy = bounds.max.y - bounds.min.y;
582
- const dz = bounds.max.z - bounds.min.z;
583
- // Approximate surface area
584
- area += 2 * (dx * dy + dy * dz + dx * dz);
635
+ }
636
+ const baseProgress = bounceIndex / this.settings.bounces;
637
+ const bounceProgress = (sample + 1) / totalSamples / this.settings.bounces;
638
+ this.bakeProgress.progress = baseProgress + bounceProgress;
639
+ this.emitProgress();
640
+ if (sample % 8 === 0) {
641
+ await this.sleep(1);
642
+ }
643
+ }
644
+ }
645
+ sampleIndirectLighting(x, y, lightmap, sample, bounce) {
646
+ const falloff = 1 / (bounce + 1);
647
+ return {
648
+ r: Math.random() * 5 * falloff,
649
+ g: Math.random() * 5 * falloff,
650
+ b: Math.random() * 5 * falloff,
651
+ a: 1
652
+ };
653
+ }
654
+ async denoiseLightmaps() {
655
+ for (let i = 0; i < this.lightmaps.length; i++) {
656
+ const lightmap = this.lightmaps[i];
657
+ await this.applyBoxBlur(lightmap.colorData, lightmap.width, lightmap.height, 1);
658
+ this.bakeProgress.lightmapsCompleted = i + 1;
659
+ this.bakeProgress.progress = (i + 1) / this.lightmaps.length;
660
+ this.emitProgress();
661
+ }
662
+ }
663
+ async applyBoxBlur(data, width, height, radius) {
664
+ const temp = new Uint8Array(data.length);
665
+ for (let y = 0; y < height; y++) {
666
+ for (let x = 0; x < width; x++) {
667
+ let r = 0, g = 0, b = 0, count = 0;
668
+ for (let dx = -radius; dx <= radius; dx++) {
669
+ const nx = x + dx;
670
+ if (nx >= 0 && nx < width) {
671
+ const idx2 = (y * width + nx) * 4;
672
+ r += data[idx2];
673
+ g += data[idx2 + 1];
674
+ b += data[idx2 + 2];
675
+ count++;
676
+ }
585
677
  }
586
- return area;
587
- }
588
- packLightmapUVs(entityBounds) {
589
- const uvs = [];
590
- // Simple packing: assign sequentially (in production, use proper rect packing)
591
- let currentLightmap = 0;
592
- let currentU = 0;
593
- let currentV = 0;
594
- let rowHeight = 0;
595
- const maxSize = this.settings.maxLightmapSize;
596
- const padding = this.settings.lightmapPadding;
597
- for (const [entityId, bounds] of entityBounds) {
598
- const dx = bounds.max.x - bounds.min.x;
599
- const dy = bounds.max.y - bounds.min.y;
600
- const texelsX = Math.ceil(dx * this.settings.lightmapResolution) + padding * 2;
601
- const texelsY = Math.ceil(dy * this.settings.lightmapResolution) + padding * 2;
602
- // Check if fits in current row
603
- if (currentU + texelsX > maxSize) {
604
- // Move to next row
605
- currentU = 0;
606
- currentV += rowHeight + padding;
607
- rowHeight = 0;
608
- }
609
- // Check if fits in current lightmap
610
- if (currentV + texelsY > maxSize) {
611
- // Move to next lightmap
612
- currentLightmap++;
613
- currentU = 0;
614
- currentV = 0;
615
- rowHeight = 0;
616
- }
617
- uvs.push({
618
- entityId,
619
- lightmapIndex: currentLightmap,
620
- uvOffset: { x: currentU / maxSize, y: currentV / maxSize },
621
- uvScale: { x: texelsX / maxSize, y: texelsY / maxSize },
622
- });
623
- currentU += texelsX + padding;
624
- rowHeight = Math.max(rowHeight, texelsY);
678
+ const idx = (y * width + x) * 4;
679
+ temp[idx] = r / count;
680
+ temp[idx + 1] = g / count;
681
+ temp[idx + 2] = b / count;
682
+ temp[idx + 3] = 255;
683
+ }
684
+ }
685
+ for (let y = 0; y < height; y++) {
686
+ for (let x = 0; x < width; x++) {
687
+ let r = 0, g = 0, b = 0, count = 0;
688
+ for (let dy = -radius; dy <= radius; dy++) {
689
+ const ny = y + dy;
690
+ if (ny >= 0 && ny < height) {
691
+ const idx2 = (ny * width + x) * 4;
692
+ r += temp[idx2];
693
+ g += temp[idx2 + 1];
694
+ b += temp[idx2 + 2];
695
+ count++;
696
+ }
625
697
  }
626
- return uvs;
627
- }
628
- async bakeDirectLighting() {
629
- const bakedLights = this.getBakedLights();
630
- const totalSamples = this.settings.directSamples;
631
- for (let sample = 0; sample < totalSamples; sample++) {
632
- // For each lightmap texel, trace rays to lights
633
- for (const lightmap of this.lightmaps) {
634
- for (let y = 0; y < lightmap.height; y++) {
635
- for (let x = 0; x < lightmap.width; x++) {
636
- // Accumulate direct lighting from all baked lights
637
- let r = 0, g = 0, b = 0;
638
- for (const light of bakedLights) {
639
- const contribution = this.calculateDirectLighting(x, y, lightmap, light, sample);
640
- r += contribution.r;
641
- g += contribution.g;
642
- b += contribution.b;
643
- }
644
- // Accumulate in lightmap
645
- const idx = (y * lightmap.width + x) * 4;
646
- lightmap.colorData[idx] = Math.min(255, lightmap.colorData[idx] + r);
647
- lightmap.colorData[idx + 1] = Math.min(255, lightmap.colorData[idx + 1] + g);
648
- lightmap.colorData[idx + 2] = Math.min(255, lightmap.colorData[idx + 2] + b);
649
- lightmap.colorData[idx + 3] = 255;
650
- }
651
- }
652
- }
653
- this.bakeProgress.samplesRendered = sample + 1;
654
- this.bakeProgress.progress = (sample + 1) / totalSamples;
655
- this.emitProgress();
656
- if (sample % 4 === 0) {
657
- await this.sleep(1); // Yield to UI periodically
658
- }
698
+ const idx = (y * width + x) * 4;
699
+ data[idx] = r / count;
700
+ data[idx + 1] = g / count;
701
+ data[idx + 2] = b / count;
702
+ }
703
+ }
704
+ }
705
+ async compositeLightmaps() {
706
+ for (let i = 0; i < this.lightmaps.length; i++) {
707
+ const lightmap = this.lightmaps[i];
708
+ for (let j = 0; j < lightmap.colorData.length; j += 4) {
709
+ lightmap.colorData[j] = Math.pow(lightmap.colorData[j] / 255, 1 / 2.2) * 255;
710
+ lightmap.colorData[j + 1] = Math.pow(lightmap.colorData[j + 1] / 255, 1 / 2.2) * 255;
711
+ lightmap.colorData[j + 2] = Math.pow(lightmap.colorData[j + 2] / 255, 1 / 2.2) * 255;
712
+ }
713
+ this.bakeProgress.progress = (i + 1) / this.lightmaps.length;
714
+ this.emitProgress();
715
+ await this.sleep(1);
716
+ }
717
+ }
718
+ async bakeLightProbes() {
719
+ let probeIndex = 0;
720
+ for (const group of this.lightProbeGroups) {
721
+ for (const probe of group.probes) {
722
+ probe.sh = await this.computeSphericalHarmonics(probe.position);
723
+ probe.isValid = true;
724
+ probeIndex++;
725
+ this.bakeProgress.probesCompleted = probeIndex;
726
+ this.bakeProgress.progress = probeIndex / this.bakeProgress.totalProbes;
727
+ this.emitProgress();
728
+ if (probeIndex % 10 === 0) {
729
+ await this.sleep(1);
659
730
  }
660
- }
661
- calculateDirectLighting(x, y, lightmap, light, _sample) {
662
- // Simplified direct lighting calculation
663
- // In production, this would involve ray tracing
664
- const intensity = light.intensity;
665
- const falloff = 1; // Would calculate based on distance for point/spot lights
731
+ }
732
+ }
733
+ }
734
+ async computeSphericalHarmonics(position) {
735
+ const coefficients = new Float32Array(27);
736
+ const samples = 64;
737
+ for (let i = 0; i < samples; i++) {
738
+ const theta = Math.acos(1 - 2 * Math.random());
739
+ const phi = Math.random() * Math.PI * 2;
740
+ const dir = {
741
+ x: Math.sin(theta) * Math.cos(phi),
742
+ y: Math.cos(theta),
743
+ z: Math.sin(theta) * Math.sin(phi)
744
+ };
745
+ const lighting = this.sampleEnvironmentLighting(position, dir);
746
+ const y0 = 0.282095;
747
+ coefficients[0] += lighting.r * y0;
748
+ coefficients[1] += lighting.g * y0;
749
+ coefficients[2] += lighting.b * y0;
750
+ const y1 = 0.488603;
751
+ coefficients[3] += lighting.r * y1 * dir.y;
752
+ coefficients[4] += lighting.g * y1 * dir.y;
753
+ coefficients[5] += lighting.b * y1 * dir.y;
754
+ coefficients[6] += lighting.r * y1 * dir.z;
755
+ coefficients[7] += lighting.g * y1 * dir.z;
756
+ coefficients[8] += lighting.b * y1 * dir.z;
757
+ coefficients[9] += lighting.r * y1 * dir.x;
758
+ coefficients[10] += lighting.g * y1 * dir.x;
759
+ coefficients[11] += lighting.b * y1 * dir.x;
760
+ }
761
+ const scale = 4 * Math.PI / samples;
762
+ for (let i = 0; i < 27; i++) {
763
+ coefficients[i] *= scale;
764
+ }
765
+ return { coefficients };
766
+ }
767
+ sampleEnvironmentLighting(position, direction) {
768
+ const settings = this.settings;
769
+ if (settings.environmentLighting === "color") {
770
+ return settings.skyColor;
771
+ }
772
+ if (settings.environmentLighting === "gradient") {
773
+ const t = direction.y * 0.5 + 0.5;
774
+ if (t > 0.5) {
775
+ const st = (t - 0.5) * 2;
666
776
  return {
667
- r: light.color.r * intensity * falloff * 2, // Scaled for 8-bit accumulation
668
- g: light.color.g * intensity * falloff * 2,
669
- b: light.color.b * intensity * falloff * 2,
670
- a: 1,
777
+ r: settings.equatorColor.r + (settings.skyColor.r - settings.equatorColor.r) * st,
778
+ g: settings.equatorColor.g + (settings.skyColor.g - settings.equatorColor.g) * st,
779
+ b: settings.equatorColor.b + (settings.skyColor.b - settings.equatorColor.b) * st,
780
+ a: 1
671
781
  };
672
- }
673
- async bakeIndirectBounce(bounceIndex) {
674
- const totalSamples = this.settings.indirectSamples / this.settings.bounces;
675
- for (let sample = 0; sample < totalSamples; sample++) {
676
- // For each lightmap texel, sample hemisphere for indirect light
677
- for (const lightmap of this.lightmaps) {
678
- for (let y = 0; y < lightmap.height; y++) {
679
- for (let x = 0; x < lightmap.width; x++) {
680
- const indirect = this.sampleIndirectLighting(x, y, lightmap, sample, bounceIndex);
681
- const idx = (y * lightmap.width + x) * 4;
682
- lightmap.colorData[idx] = Math.min(255, lightmap.colorData[idx] + indirect.r);
683
- lightmap.colorData[idx + 1] = Math.min(255, lightmap.colorData[idx + 1] + indirect.g);
684
- lightmap.colorData[idx + 2] = Math.min(255, lightmap.colorData[idx + 2] + indirect.b);
685
- }
686
- }
687
- }
688
- const baseProgress = bounceIndex / this.settings.bounces;
689
- const bounceProgress = (sample + 1) / totalSamples / this.settings.bounces;
690
- this.bakeProgress.progress = baseProgress + bounceProgress;
691
- this.emitProgress();
692
- if (sample % 8 === 0) {
693
- await this.sleep(1);
694
- }
695
- }
696
- }
697
- sampleIndirectLighting(x, y, lightmap, sample, bounce) {
698
- // Simplified indirect lighting
699
- // In production, this would involve path tracing / radiosity
700
- const falloff = 1 / (bounce + 1);
782
+ } else {
783
+ const st = t * 2;
701
784
  return {
702
- r: Math.random() * 5 * falloff,
703
- g: Math.random() * 5 * falloff,
704
- b: Math.random() * 5 * falloff,
705
- a: 1,
785
+ r: settings.groundColor.r + (settings.equatorColor.r - settings.groundColor.r) * st,
786
+ g: settings.groundColor.g + (settings.equatorColor.g - settings.groundColor.g) * st,
787
+ b: settings.groundColor.b + (settings.equatorColor.b - settings.groundColor.b) * st,
788
+ a: 1
706
789
  };
707
- }
708
- async denoiseLightmaps() {
709
- // Simplified denoising (in production, use OIDN or similar)
710
- for (let i = 0; i < this.lightmaps.length; i++) {
711
- const lightmap = this.lightmaps[i];
712
- await this.applyBoxBlur(lightmap.colorData, lightmap.width, lightmap.height, 1);
713
- this.bakeProgress.lightmapsCompleted = i + 1;
714
- this.bakeProgress.progress = (i + 1) / this.lightmaps.length;
715
- this.emitProgress();
716
- }
717
- }
718
- async applyBoxBlur(data, width, height, radius) {
719
- const temp = new Uint8Array(data.length);
720
- // Horizontal pass
721
- for (let y = 0; y < height; y++) {
722
- for (let x = 0; x < width; x++) {
723
- let r = 0, g = 0, b = 0, count = 0;
724
- for (let dx = -radius; dx <= radius; dx++) {
725
- const nx = x + dx;
726
- if (nx >= 0 && nx < width) {
727
- const idx = (y * width + nx) * 4;
728
- r += data[idx];
729
- g += data[idx + 1];
730
- b += data[idx + 2];
731
- count++;
732
- }
733
- }
734
- const idx = (y * width + x) * 4;
735
- temp[idx] = r / count;
736
- temp[idx + 1] = g / count;
737
- temp[idx + 2] = b / count;
738
- temp[idx + 3] = 255;
739
- }
740
- }
741
- // Vertical pass
742
- for (let y = 0; y < height; y++) {
743
- for (let x = 0; x < width; x++) {
744
- let r = 0, g = 0, b = 0, count = 0;
745
- for (let dy = -radius; dy <= radius; dy++) {
746
- const ny = y + dy;
747
- if (ny >= 0 && ny < height) {
748
- const idx = (ny * width + x) * 4;
749
- r += temp[idx];
750
- g += temp[idx + 1];
751
- b += temp[idx + 2];
752
- count++;
753
- }
754
- }
755
- const idx = (y * width + x) * 4;
756
- data[idx] = r / count;
757
- data[idx + 1] = g / count;
758
- data[idx + 2] = b / count;
759
- }
760
- }
761
- }
762
- async compositeLightmaps() {
763
- // Final compositing (gamma correction, AO, etc.)
764
- for (let i = 0; i < this.lightmaps.length; i++) {
765
- const lightmap = this.lightmaps[i];
766
- // Apply gamma
767
- for (let j = 0; j < lightmap.colorData.length; j += 4) {
768
- lightmap.colorData[j] = Math.pow(lightmap.colorData[j] / 255, 1 / 2.2) * 255;
769
- lightmap.colorData[j + 1] = Math.pow(lightmap.colorData[j + 1] / 255, 1 / 2.2) * 255;
770
- lightmap.colorData[j + 2] = Math.pow(lightmap.colorData[j + 2] / 255, 1 / 2.2) * 255;
771
- }
772
- this.bakeProgress.progress = (i + 1) / this.lightmaps.length;
773
- this.emitProgress();
774
- await this.sleep(1);
775
- }
776
- }
777
- async bakeLightProbes() {
778
- let probeIndex = 0;
779
- for (const group of this.lightProbeGroups) {
780
- for (const probe of group.probes) {
781
- // Bake spherical harmonics for this probe
782
- probe.sh = await this.computeSphericalHarmonics(probe.position);
783
- probe.isValid = true;
784
- probeIndex++;
785
- this.bakeProgress.probesCompleted = probeIndex;
786
- this.bakeProgress.progress = probeIndex / this.bakeProgress.totalProbes;
787
- this.emitProgress();
788
- if (probeIndex % 10 === 0) {
789
- await this.sleep(1);
790
- }
791
- }
792
- }
793
- }
794
- async computeSphericalHarmonics(position) {
795
- const coefficients = new Float32Array(27);
796
- // Sample environment in all directions and project onto SH basis
797
- const samples = 64;
798
- for (let i = 0; i < samples; i++) {
799
- // Generate uniform direction
800
- const theta = Math.acos(1 - 2 * Math.random());
801
- const phi = Math.random() * Math.PI * 2;
802
- const dir = {
803
- x: Math.sin(theta) * Math.cos(phi),
804
- y: Math.cos(theta),
805
- z: Math.sin(theta) * Math.sin(phi),
806
- };
807
- // Sample lighting in this direction
808
- const lighting = this.sampleEnvironmentLighting(position, dir);
809
- // Project onto SH bands
810
- // L0 (constant)
811
- const y0 = 0.282095;
812
- coefficients[0] += lighting.r * y0;
813
- coefficients[1] += lighting.g * y0;
814
- coefficients[2] += lighting.b * y0;
815
- // L1 (linear)
816
- const y1 = 0.488603;
817
- coefficients[3] += lighting.r * y1 * dir.y;
818
- coefficients[4] += lighting.g * y1 * dir.y;
819
- coefficients[5] += lighting.b * y1 * dir.y;
820
- coefficients[6] += lighting.r * y1 * dir.z;
821
- coefficients[7] += lighting.g * y1 * dir.z;
822
- coefficients[8] += lighting.b * y1 * dir.z;
823
- coefficients[9] += lighting.r * y1 * dir.x;
824
- coefficients[10] += lighting.g * y1 * dir.x;
825
- coefficients[11] += lighting.b * y1 * dir.x;
826
- // L2 (quadratic) - simplified
827
- // ... additional coefficients
828
- }
829
- // Normalize
830
- const scale = (4 * Math.PI) / samples;
831
- for (let i = 0; i < 27; i++) {
832
- coefficients[i] *= scale;
833
- }
834
- return { coefficients };
835
- }
836
- sampleEnvironmentLighting(position, direction) {
837
- // Sample from environment settings
838
- const settings = this.settings;
839
- if (settings.environmentLighting === 'color') {
840
- return settings.skyColor;
841
- }
842
- if (settings.environmentLighting === 'gradient') {
843
- // Interpolate based on direction
844
- const t = direction.y * 0.5 + 0.5;
845
- if (t > 0.5) {
846
- // Sky to equator
847
- const st = (t - 0.5) * 2;
848
- return {
849
- r: settings.equatorColor.r + (settings.skyColor.r - settings.equatorColor.r) * st,
850
- g: settings.equatorColor.g + (settings.skyColor.g - settings.equatorColor.g) * st,
851
- b: settings.equatorColor.b + (settings.skyColor.b - settings.equatorColor.b) * st,
852
- a: 1,
853
- };
854
- }
855
- else {
856
- // Equator to ground
857
- const st = t * 2;
858
- return {
859
- r: settings.groundColor.r + (settings.equatorColor.r - settings.groundColor.r) * st,
860
- g: settings.groundColor.g + (settings.equatorColor.g - settings.groundColor.g) * st,
861
- b: settings.groundColor.b + (settings.equatorColor.b - settings.groundColor.b) * st,
862
- a: 1,
863
- };
864
- }
865
- }
866
- // Skybox mode - sample from skybox texture
867
- return settings.skyColor;
868
- }
869
- async bakeReflectionProbes() {
870
- for (let i = 0; i < this.reflectionProbes.length; i++) {
871
- const probe = this.reflectionProbes[i];
872
- if (probe.type === 'baked') {
873
- // Render cubemap for this probe
874
- probe.bakedCubemapId = await this.renderCubemap(probe);
875
- probe.isValid = true;
876
- }
877
- this.bakeProgress.reflectionProbesCompleted = i + 1;
878
- this.bakeProgress.progress = (i + 1) / this.reflectionProbes.length;
879
- this.emitProgress();
880
- await this.sleep(10);
881
- }
882
- }
883
- async renderCubemap(probe) {
884
- // In production, this would render 6 faces of a cubemap
885
- // Return a reference to the generated texture
886
- return `cubemap_${probe.id}`;
887
- }
888
- sleep(ms) {
889
- return new Promise((resolve) => setTimeout(resolve, ms));
890
- }
891
- // ─── GI Preview ────────────────────────────────────────
892
- enableGIPreview(_enable) {
893
- // Toggle real-time GI preview in viewport
894
- // This would update rendering settings
895
- }
896
- // ─── Lightmap Access ───────────────────────────────────
897
- getLightmaps() {
898
- return [...this.lightmaps];
899
- }
900
- getLightmapUVs() {
901
- return [...this.lightmapUVs];
902
- }
903
- // ─── Serialization ─────────────────────────────────────
904
- serialize() {
905
- return JSON.stringify({
906
- lights: this.lights,
907
- lightProbeGroups: this.lightProbeGroups.map((g) => ({
908
- ...g,
909
- probes: g.probes.map((p) => ({
910
- ...p,
911
- sh: { coefficients: Array.from(p.sh.coefficients) },
912
- })),
913
- })),
914
- reflectionProbes: this.reflectionProbes,
915
- settings: this.settings,
916
- lightmaps: this.lightmaps.map((lm) => ({
917
- ...lm,
918
- colorData: Array.from(lm.colorData),
919
- directionData: lm.directionData ? Array.from(lm.directionData) : undefined,
920
- shadowmaskData: lm.shadowmaskData ? Array.from(lm.shadowmaskData) : undefined,
921
- })),
922
- lightmapUVs: this.lightmapUVs,
923
- });
924
- }
925
- static deserialize(json) {
926
- const data = JSON.parse(json);
927
- const system = new LightingSystem();
928
- system.lights = data.lights;
929
- system.lightProbeGroups = data.lightProbeGroups.map((g) => ({
930
- ...g,
931
- probes: g.probes.map((p) => ({
932
- ...p,
933
- sh: { coefficients: new Float32Array(p.sh.coefficients) },
934
- })),
935
- }));
936
- system.reflectionProbes = data.reflectionProbes;
937
- system.settings = data.settings;
938
- system.lightmaps = data.lightmaps.map((lm) => ({
939
- ...lm,
940
- colorData: new Uint8Array(lm.colorData),
941
- directionData: lm.directionData ? new Uint8Array(lm.directionData) : undefined,
942
- shadowmaskData: lm.shadowmaskData ? new Uint8Array(lm.shadowmaskData) : undefined,
943
- }));
944
- system.lightmapUVs = data.lightmapUVs;
945
- return system;
946
- }
790
+ }
791
+ }
792
+ return settings.skyColor;
793
+ }
794
+ async bakeReflectionProbes() {
795
+ for (let i = 0; i < this.reflectionProbes.length; i++) {
796
+ const probe = this.reflectionProbes[i];
797
+ if (probe.type === "baked") {
798
+ probe.bakedCubemapId = await this.renderCubemap(probe);
799
+ probe.isValid = true;
800
+ }
801
+ this.bakeProgress.reflectionProbesCompleted = i + 1;
802
+ this.bakeProgress.progress = (i + 1) / this.reflectionProbes.length;
803
+ this.emitProgress();
804
+ await this.sleep(10);
805
+ }
806
+ }
807
+ async renderCubemap(probe) {
808
+ return `cubemap_${probe.id}`;
809
+ }
810
+ sleep(ms) {
811
+ return new Promise((resolve) => setTimeout(resolve, ms));
812
+ }
813
+ // ─── GI Preview ────────────────────────────────────────
814
+ enableGIPreview(_enable) {
815
+ }
816
+ // ─── Lightmap Access ───────────────────────────────────
817
+ getLightmaps() {
818
+ return [...this.lightmaps];
819
+ }
820
+ getLightmapUVs() {
821
+ return [...this.lightmapUVs];
822
+ }
823
+ // ─── Serialization ─────────────────────────────────────
824
+ serialize() {
825
+ return JSON.stringify({
826
+ lights: this.lights,
827
+ lightProbeGroups: this.lightProbeGroups.map((g) => ({
828
+ ...g,
829
+ probes: g.probes.map((p) => ({
830
+ ...p,
831
+ sh: { coefficients: Array.from(p.sh.coefficients) }
832
+ }))
833
+ })),
834
+ reflectionProbes: this.reflectionProbes,
835
+ settings: this.settings,
836
+ lightmaps: this.lightmaps.map((lm) => ({
837
+ ...lm,
838
+ colorData: Array.from(lm.colorData),
839
+ directionData: lm.directionData ? Array.from(lm.directionData) : void 0,
840
+ shadowmaskData: lm.shadowmaskData ? Array.from(lm.shadowmaskData) : void 0
841
+ })),
842
+ lightmapUVs: this.lightmapUVs
843
+ });
844
+ }
845
+ static deserialize(json) {
846
+ const data = JSON.parse(json);
847
+ const system = new LightingSystem();
848
+ system.lights = data.lights;
849
+ system.lightProbeGroups = data.lightProbeGroups.map((g) => ({
850
+ ...g,
851
+ probes: g.probes.map((p) => ({
852
+ ...p,
853
+ sh: { coefficients: new Float32Array(p.sh.coefficients) }
854
+ }))
855
+ }));
856
+ system.reflectionProbes = data.reflectionProbes;
857
+ system.settings = data.settings;
858
+ system.lightmaps = data.lightmaps.map((lm) => ({
859
+ ...lm,
860
+ colorData: new Uint8Array(lm.colorData),
861
+ directionData: lm.directionData ? new Uint8Array(lm.directionData) : void 0,
862
+ shadowmaskData: lm.shadowmaskData ? new Uint8Array(lm.shadowmaskData) : void 0
863
+ }));
864
+ system.lightmapUVs = data.lightmapUVs;
865
+ return system;
866
+ }
947
867
  }
948
- // ============================================================
949
- // Factory Functions
950
- // ============================================================
951
868
  function createLightingSystem() {
952
- return new LightingSystem();
869
+ return new LightingSystem();
953
870
  }
954
871
  function createDefaultLightingSetup() {
955
- const system = new LightingSystem();
956
- // Add a directional light (sun)
957
- system.addLight(createDirectionalLight('Directional Light'));
958
- // Add a light probe group
959
- const probeGroup = createLightProbeGroup('Default Probes');
960
- system.addLightProbeGroup(probeGroup);
961
- system.autoGenerateProbes(probeGroup.id);
962
- // Add a reflection probe
963
- system.addReflectionProbe(createReflectionProbe('Reflection Probe', { x: 0, y: 2, z: 0 }));
964
- return system;
872
+ const system = new LightingSystem();
873
+ system.addLight(createDirectionalLight("Directional Light"));
874
+ const probeGroup = createLightProbeGroup("Default Probes");
875
+ system.addLightProbeGroup(probeGroup);
876
+ system.autoGenerateProbes(probeGroup.id);
877
+ system.addReflectionProbe(createReflectionProbe("Reflection Probe", { x: 0, y: 2, z: 0 }));
878
+ return system;
965
879
  }
966
-
967
- export { DEFAULT_LIGHTMAP_SETTINGS, LightingSystem, createAreaLight, createDefaultLightingSetup, createDirectionalLight, createLightProbe, createLightProbeGroup, createLightingSystem, createPointLight, createReflectionProbe, createSpotLight };
880
+ export {
881
+ DEFAULT_LIGHTMAP_SETTINGS,
882
+ LightingSystem,
883
+ createAreaLight,
884
+ createDefaultLightingSetup,
885
+ createDirectionalLight,
886
+ createLightProbe,
887
+ createLightProbeGroup,
888
+ createLightingSystem,
889
+ createPointLight,
890
+ createReflectionProbe,
891
+ createSpotLight
892
+ };