@nice2dev/game-engine 1.3.15 → 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.
- package/CHANGELOG.md +9 -0
- package/dist/cjs/accessibility/Accessibility.js +152 -165
- package/dist/cjs/ai/AI.js +292 -294
- package/dist/cjs/ai/BehaviorTree.js +1029 -1113
- package/dist/cjs/ai/StateMachine.js +694 -756
- package/dist/cjs/animation/Animation.js +232 -241
- package/dist/cjs/audio/AudioAdvanced.js +221 -236
- package/dist/cjs/audio/AudioBridge.js +441 -435
- package/dist/cjs/audio/AudioManager.js +242 -259
- package/dist/cjs/build-cloud/BuildOrchestration.js +1059 -1098
- package/dist/cjs/build-cloud/GodotBuildCloud.js +641 -670
- package/dist/cjs/build-cloud/UnityBuildCloud.js +563 -610
- package/dist/cjs/build-cloud/UnrealBuildCloud.js +610 -635
- package/dist/cjs/core/EventBus.js +51 -56
- package/dist/cjs/core/GameClock.js +62 -66
- package/dist/cjs/core/GameConfig.js +72 -79
- package/dist/cjs/core/GameLoop.js +80 -89
- package/dist/cjs/core/ServiceLocator.js +61 -65
- package/dist/cjs/core/Validation.js +72 -82
- package/dist/cjs/core/math.js +108 -112
- package/dist/cjs/devtools/DevTools.js +542 -563
- package/dist/cjs/devtools/DeveloperExperience.js +521 -559
- package/dist/cjs/devtools/GameplayAnalytics.js +636 -646
- package/dist/cjs/dialogue/DialogueSystem.js +984 -986
- package/dist/cjs/docs/DocGenerator.js +339 -364
- package/dist/cjs/ecs/World.js +355 -371
- package/dist/cjs/editor/AchievementEditor.js +580 -636
- package/dist/cjs/editor/AdvancedEditor.js +184 -191
- package/dist/cjs/editor/AnimationRetargeting.js +696 -741
- package/dist/cjs/editor/AssetBrowser.js +1072 -1160
- package/dist/cjs/editor/AssetManager.js +187 -192
- package/dist/cjs/editor/ConsolePro.js +971 -1061
- package/dist/cjs/editor/CraftingEditor.js +680 -730
- package/dist/cjs/editor/DebugTools.js +187 -185
- package/dist/cjs/editor/DialogueSystem.js +844 -901
- package/dist/cjs/editor/LeaderboardSystem.js +429 -483
- package/dist/cjs/editor/NiceGameEditor.js +1903 -1201
- package/dist/cjs/editor/PrefabSystem.js +772 -838
- package/dist/cjs/editor/ProfilerPanel.js +649 -700
- package/dist/cjs/editor/QuestEditor.js +792 -839
- package/dist/cjs/editor/ReplaySystem.js +585 -634
- package/dist/cjs/editor/SceneEditor.js +176 -200
- package/dist/cjs/editor/ScreenshotMode.js +621 -688
- package/dist/cjs/editor/ShaderGraph.js +1556 -1582
- package/dist/cjs/editor/TimelineEditor.js +715 -778
- package/dist/cjs/editor/UndoRedoPro.js +830 -904
- package/dist/cjs/editor/VRARMode.js +582 -645
- package/dist/cjs/engine/NiceGameEngine.js +141 -164
- package/dist/cjs/engine/SaveSystem.js +441 -495
- package/dist/cjs/enterprise/Enterprise.js +254 -261
- package/dist/cjs/export/BevyExporter.js +927 -967
- package/dist/cjs/export/CocosExporter.js +644 -673
- package/dist/cjs/export/Construct3Exporter.js +783 -794
- package/dist/cjs/export/DefoldExporter.js +1028 -1069
- package/dist/cjs/export/GDevelopExporter.js +674 -708
- package/dist/cjs/export/GameMakerExporter.js +791 -805
- package/dist/cjs/export/GodotExporter.js +1003 -1045
- package/dist/cjs/export/MinecraftBedrockExporter.js +573 -578
- package/dist/cjs/export/MonoGameExporter.js +1265 -1293
- package/dist/cjs/export/Pico8Exporter.js +766 -812
- package/dist/cjs/export/PlatformExporter.js +188 -206
- package/dist/cjs/export/RPGMakerExporter.js +860 -879
- package/dist/cjs/export/RobloxExporter.js +883 -919
- package/dist/cjs/export/Solar2DExporter.js +1218 -1256
- package/dist/cjs/export/ThreeJSExporter.js +1006 -1073
- package/dist/cjs/export/Tic80Exporter.js +1210 -1267
- package/dist/cjs/export/UnityExporter.js +1116 -1131
- package/dist/cjs/export/UnrealExporter.js +889 -919
- package/dist/cjs/export/WebExporter.js +931 -970
- package/dist/cjs/export/index.js +42 -65
- package/dist/cjs/godot-integration/GodotAssetLibrary.js +659 -692
- package/dist/cjs/godot-integration/GodotImport.js +929 -1027
- package/dist/cjs/godot-integration/GodotLiveLink.js +915 -945
- package/dist/cjs/godot-integration/components/GodotProjectBrowser.js +911 -611
- package/dist/cjs/i18n/I18n.js +860 -900
- package/dist/cjs/i18n/useTranslation.js +84 -89
- package/dist/cjs/import/AsepriteImporter.js +658 -716
- package/dist/cjs/import/DragonBonesImporter.js +437 -461
- package/dist/cjs/import/GameMakerImporter.js +511 -521
- package/dist/cjs/import/GodotSceneImporter.js +788 -822
- package/dist/cjs/import/LDtkImporter.js +436 -454
- package/dist/cjs/import/Live2DImporter.js +497 -518
- package/dist/cjs/import/NdgFormat.js +424 -457
- package/dist/cjs/import/OgmoImporter.js +466 -493
- package/dist/cjs/import/RPGMakerImporter.js +451 -477
- package/dist/cjs/import/SceneImporter.js +378 -423
- package/dist/cjs/import/SpineImporter.js +511 -546
- package/dist/cjs/import/SpriterImporter.js +590 -613
- package/dist/cjs/import/TiledMapImporter.js +811 -846
- package/dist/cjs/import/UnitySceneImporter.js +687 -703
- package/dist/cjs/import/index.js +206 -251
- package/dist/cjs/index.js +275 -278
- package/dist/cjs/input/GamepadNavigation.js +185 -205
- package/dist/cjs/input/InputManager.js +397 -421
- package/dist/cjs/input/useGamepads.js +70 -81
- package/dist/cjs/integration/IconSprite.js +129 -256
- package/dist/cjs/inventory/InventorySystem.js +920 -995
- package/dist/cjs/kids/KidMode.js +997 -1022
- package/dist/cjs/kids/KidTools.js +570 -594
- package/dist/cjs/monetization/Monetization.js +170 -177
- package/dist/cjs/multiplayer/LocalMultiplayer.js +287 -287
- package/dist/cjs/multiplayer/MiniGameTypes.js +49 -59
- package/dist/cjs/native-engine/AnimationSystem.js +731 -806
- package/dist/cjs/native-engine/AssetPipeline.js +454 -515
- package/dist/cjs/native-engine/AudioEngine.js +763 -804
- package/dist/cjs/native-engine/InputSystem.js +1075 -1145
- package/dist/cjs/native-engine/NetworkingSystem.js +733 -793
- package/dist/cjs/native-engine/PhysicsEngine.js +583 -607
- package/dist/cjs/native-engine/RenderingEngine.js +302 -350
- package/dist/cjs/native-engine/SceneGraph.js +769 -808
- package/dist/cjs/network/MultiplayerTransport.js +97 -132
- package/dist/cjs/network/Networking.js +549 -564
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AbortController.js +21 -29
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +40 -48
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +35 -43
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +10 -15
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Errors.js +103 -135
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +131 -158
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +39 -53
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +5 -8
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +40 -48
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +494 -572
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +826 -953
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +125 -146
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +13 -23
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ILogger.js +11 -25
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ITransport.js +13 -24
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +108 -121
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Loggers.js +10 -14
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +150 -185
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +158 -196
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +90 -105
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Subject.js +30 -35
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +16 -21
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Utils.js +215 -248
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +135 -157
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +76 -85
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/index.js +24 -27
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +3 -4
- package/dist/cjs/pathfinding/Pathfinding.js +245 -263
- package/dist/cjs/performance/AssetStreaming.js +561 -635
- package/dist/cjs/performance/BenchmarkSuite.js +283 -311
- package/dist/cjs/performance/DeltaCompression.js +467 -526
- package/dist/cjs/performance/DeterministicPhysics.js +450 -498
- package/dist/cjs/performance/ECSOptimization.js +644 -695
- package/dist/cjs/performance/GameSaveSystem.js +509 -556
- package/dist/cjs/performance/HotReload.js +447 -500
- package/dist/cjs/performance/InputRecording.js +511 -561
- package/dist/cjs/performance/InterestManagement.js +453 -500
- package/dist/cjs/performance/LocalizationRuntime.js +376 -423
- package/dist/cjs/performance/MemoryManagement.js +410 -470
- package/dist/cjs/performance/ModSupport.js +445 -496
- package/dist/cjs/performance/MultiThreadedPhysics.js +400 -443
- package/dist/cjs/performance/NetworkPrediction.js +424 -482
- package/dist/cjs/performance/ObjectPooling.js +569 -617
- package/dist/cjs/performance/Performance.js +174 -190
- package/dist/cjs/performance/PerformanceAdvanced.js +614 -637
- package/dist/cjs/performance/WebGPURenderer.js +656 -683
- package/dist/cjs/physics/PhysicsAdvanced.js +345 -379
- package/dist/cjs/physics/PhysicsEngine2D.js +391 -427
- package/dist/cjs/plugins/PluginSDK.js +432 -466
- package/dist/cjs/plugins/PluginTestKit.js +307 -330
- package/dist/cjs/procedural/Procedural.js +243 -254
- package/dist/cjs/procedural/WorldBuilding.js +297 -314
- package/dist/cjs/quest/QuestSystem.js +975 -932
- package/dist/cjs/release/MobileExport.js +157 -163
- package/dist/cjs/release/Release.js +225 -238
- package/dist/cjs/rendering/Camera2D.js +121 -124
- package/dist/cjs/rendering/Renderer2D.js +321 -335
- package/dist/cjs/rendering/WebGPURenderPipeline.js +632 -651
- package/dist/cjs/runtime3d/Runtime3D.js +359 -378
- package/dist/cjs/runtime3d/SceneEditor3D.js +252 -263
- package/dist/cjs/scene/SceneManager.js +177 -193
- package/dist/cjs/scripting/GraphToAST.js +574 -547
- package/dist/cjs/scripting/LanguageExporter.js +254 -279
- package/dist/cjs/scripting/NodeGraph.js +546 -570
- package/dist/cjs/scripting/ScriptAST.js +31 -39
- package/dist/cjs/scripting/VisualScripting2.js +1016 -1065
- package/dist/cjs/scripting/exporters/CSharpExporter.js +464 -496
- package/dist/cjs/scripting/exporters/GDScriptExporter.js +390 -442
- package/dist/cjs/scripting/exporters/LuaExporter.js +406 -447
- package/dist/cjs/scripting/exporters/PythonExporter.js +484 -549
- package/dist/cjs/scripting/exporters/RustExporter.js +459 -512
- package/dist/cjs/scripting/exporters/TypeScriptExporter.js +505 -556
- package/dist/cjs/social/Social.js +72 -80
- package/dist/cjs/systems/LightingSystem.js +844 -931
- package/dist/cjs/systems/ParticleSystem2.js +1447 -1451
- package/dist/cjs/systems/PhysicsDebugSystem.js +1070 -1141
- package/dist/cjs/systems/TerrainSystem.js +985 -1098
- package/dist/cjs/templates/ActionTemplates.js +296 -309
- package/dist/cjs/templates/FightingTemplate.js +417 -463
- package/dist/cjs/templates/MetroidvaniaTemplate.js +353 -405
- package/dist/cjs/templates/PartyTemplates.js +190 -202
- package/dist/cjs/templates/PuzzleTemplates.js +245 -261
- package/dist/cjs/templates/RPGTemplates.js +160 -178
- package/dist/cjs/templates/SportsTemplates.js +237 -250
- package/dist/cjs/templates/StrategyTemplates.js +143 -153
- package/dist/cjs/templates/SurvivalTemplate.js +336 -380
- package/dist/cjs/templates/WaveDefense.js +499 -526
- package/dist/cjs/tilemap/Tilemap.js +207 -214
- package/dist/cjs/tutorials/TutorialBranching.js +396 -417
- package/dist/cjs/tutorials/TutorialEngine.js +888 -931
- package/dist/cjs/tutorials/TutorialOverlay.js +602 -640
- package/dist/cjs/tutorials/content/Tutorials_T05_T08.js +787 -809
- package/dist/cjs/tutorials/content/Tutorials_T09_T11.js +736 -756
- package/dist/cjs/tutorials/content/Tutorials_T12_T15.js +754 -778
- package/dist/cjs/ui/GameUI.js +295 -312
- package/dist/cjs/unity-integration/UnityAssetStore.js +700 -741
- package/dist/cjs/unity-integration/UnityImport.js +1066 -1176
- package/dist/cjs/unity-integration/UnityLiveLink.js +934 -981
- package/dist/cjs/unity-integration/components/UnityAssetStoreBrowser.js +1233 -757
- package/dist/cjs/unity-integration/components/UnityProjectBrowser.js +1240 -768
- package/dist/cjs/unreal-integration/UnrealImport.js +391 -412
- package/dist/cjs/unreal-integration/UnrealLiveLink.js +1102 -1137
- package/dist/cjs/unreal-integration/UnrealMarketplace.js +436 -473
- package/dist/cjs/unreal-integration/components/UnrealProjectBrowser.js +1150 -767
- package/dist/cjs/xr/ARVR.js +167 -175
- package/dist/esm/accessibility/Accessibility.js +160 -164
- package/dist/esm/ai/AI.js +310 -293
- package/dist/esm/ai/BehaviorTree.js +1057 -1112
- package/dist/esm/ai/StateMachine.js +709 -755
- package/dist/esm/animation/Animation.js +237 -240
- package/dist/esm/audio/AudioAdvanced.js +239 -235
- package/dist/esm/audio/AudioBridge.js +448 -434
- package/dist/esm/audio/AudioManager.js +243 -258
- package/dist/esm/build-cloud/BuildOrchestration.js +1071 -1097
- package/dist/esm/build-cloud/GodotBuildCloud.js +647 -669
- package/dist/esm/build-cloud/UnityBuildCloud.js +571 -609
- package/dist/esm/build-cloud/UnrealBuildCloud.js +615 -634
- package/dist/esm/core/EventBus.js +52 -55
- package/dist/esm/core/GameClock.js +63 -65
- package/dist/esm/core/GameConfig.js +77 -78
- package/dist/esm/core/GameLoop.js +81 -88
- package/dist/esm/core/ServiceLocator.js +63 -64
- package/dist/esm/core/Validation.js +82 -81
- package/dist/esm/core/math.js +109 -111
- package/dist/esm/devtools/DevTools.js +546 -562
- package/dist/esm/devtools/DeveloperExperience.js +535 -558
- package/dist/esm/devtools/GameplayAnalytics.js +647 -645
- package/dist/esm/dialogue/DialogueSystem.js +998 -985
- package/dist/esm/docs/DocGenerator.js +342 -363
- package/dist/esm/ecs/World.js +358 -370
- package/dist/esm/editor/AchievementEditor.js +584 -635
- package/dist/esm/editor/AdvancedEditor.js +191 -190
- package/dist/esm/editor/AnimationRetargeting.js +700 -740
- package/dist/esm/editor/AssetBrowser.js +1078 -1159
- package/dist/esm/editor/AssetManager.js +188 -191
- package/dist/esm/editor/ConsolePro.js +977 -1060
- package/dist/esm/editor/CraftingEditor.js +684 -729
- package/dist/esm/editor/DebugTools.js +194 -184
- package/dist/esm/editor/DialogueSystem.js +849 -900
- package/dist/esm/editor/LeaderboardSystem.js +433 -482
- package/dist/esm/editor/NiceGameEditor.js +1908 -1200
- package/dist/esm/editor/PrefabSystem.js +777 -837
- package/dist/esm/editor/ProfilerPanel.js +654 -699
- package/dist/esm/editor/QuestEditor.js +795 -838
- package/dist/esm/editor/ReplaySystem.js +591 -633
- package/dist/esm/editor/SceneEditor.js +189 -199
- package/dist/esm/editor/ScreenshotMode.js +628 -687
- package/dist/esm/editor/ShaderGraph.js +1565 -1581
- package/dist/esm/editor/TimelineEditor.js +733 -777
- package/dist/esm/editor/UndoRedoPro.js +835 -903
- package/dist/esm/editor/VRARMode.js +586 -644
- package/dist/esm/engine/NiceGameEngine.js +142 -163
- package/dist/esm/engine/SaveSystem.js +447 -494
- package/dist/esm/enterprise/Enterprise.js +265 -260
- package/dist/esm/export/BevyExporter.js +929 -966
- package/dist/esm/export/CocosExporter.js +646 -672
- package/dist/esm/export/Construct3Exporter.js +785 -793
- package/dist/esm/export/DefoldExporter.js +1030 -1068
- package/dist/esm/export/GDevelopExporter.js +676 -707
- package/dist/esm/export/GameMakerExporter.js +793 -804
- package/dist/esm/export/GodotExporter.js +1004 -1044
- package/dist/esm/export/MinecraftBedrockExporter.js +575 -577
- package/dist/esm/export/MonoGameExporter.js +1267 -1292
- package/dist/esm/export/Pico8Exporter.js +768 -811
- package/dist/esm/export/PlatformExporter.js +193 -205
- package/dist/esm/export/RPGMakerExporter.js +862 -878
- package/dist/esm/export/RobloxExporter.js +885 -918
- package/dist/esm/export/Solar2DExporter.js +1220 -1255
- package/dist/esm/export/ThreeJSExporter.js +1007 -1072
- package/dist/esm/export/Tic80Exporter.js +1212 -1266
- package/dist/esm/export/UnityExporter.js +1117 -1130
- package/dist/esm/export/UnrealExporter.js +891 -918
- package/dist/esm/export/WebExporter.js +933 -969
- package/dist/esm/export/index.js +86 -71
- package/dist/esm/godot-integration/GodotAssetLibrary.js +663 -691
- package/dist/esm/godot-integration/GodotImport.js +935 -1026
- package/dist/esm/godot-integration/GodotLiveLink.js +918 -944
- package/dist/esm/godot-integration/components/GodotProjectBrowser.js +912 -610
- package/dist/esm/i18n/I18n.js +871 -899
- package/dist/esm/i18n/useTranslation.js +88 -88
- package/dist/esm/import/AsepriteImporter.js +637 -715
- package/dist/esm/import/DragonBonesImporter.js +417 -460
- package/dist/esm/import/GameMakerImporter.js +491 -520
- package/dist/esm/import/GodotSceneImporter.js +767 -821
- package/dist/esm/import/LDtkImporter.js +415 -453
- package/dist/esm/import/Live2DImporter.js +477 -517
- package/dist/esm/import/NdgFormat.js +410 -456
- package/dist/esm/import/OgmoImporter.js +446 -492
- package/dist/esm/import/RPGMakerImporter.js +431 -476
- package/dist/esm/import/SceneImporter.js +385 -422
- package/dist/esm/import/SpineImporter.js +491 -545
- package/dist/esm/import/SpriterImporter.js +570 -612
- package/dist/esm/import/TiledMapImporter.js +790 -845
- package/dist/esm/import/UnitySceneImporter.js +666 -702
- package/dist/esm/import/index.js +247 -258
- package/dist/esm/index.js +1332 -188
- package/dist/esm/input/GamepadNavigation.js +187 -204
- package/dist/esm/input/InputManager.js +401 -420
- package/dist/esm/input/useGamepads.js +72 -80
- package/dist/esm/integration/IconSprite.js +143 -255
- package/dist/esm/inventory/InventorySystem.js +925 -994
- package/dist/esm/kids/KidMode.js +1003 -1021
- package/dist/esm/kids/KidTools.js +573 -593
- package/dist/esm/monetization/Monetization.js +180 -176
- package/dist/esm/multiplayer/LocalMultiplayer.js +290 -286
- package/dist/esm/multiplayer/MiniGameTypes.js +58 -58
- package/dist/esm/native-engine/AnimationSystem.js +735 -805
- package/dist/esm/native-engine/AssetPipeline.js +456 -514
- package/dist/esm/native-engine/AudioEngine.js +765 -803
- package/dist/esm/native-engine/InputSystem.js +1079 -1144
- package/dist/esm/native-engine/NetworkingSystem.js +740 -792
- package/dist/esm/native-engine/PhysicsEngine.js +585 -606
- package/dist/esm/native-engine/RenderingEngine.js +304 -349
- package/dist/esm/native-engine/SceneGraph.js +773 -807
- package/dist/esm/network/MultiplayerTransport.js +99 -131
- package/dist/esm/network/Networking.js +556 -563
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AbortController.js +22 -28
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +41 -47
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +36 -42
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +11 -14
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Errors.js +111 -134
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +132 -157
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +40 -52
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +6 -7
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +42 -47
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +496 -571
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +828 -952
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +126 -145
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +14 -23
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ILogger.js +12 -25
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ITransport.js +15 -24
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +109 -120
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Loggers.js +11 -13
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +151 -184
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +159 -195
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +91 -104
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Subject.js +31 -34
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +17 -20
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Utils.js +230 -248
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +136 -156
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +77 -84
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/index.js +31 -12
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +4 -3
- package/dist/esm/pathfinding/Pathfinding.js +249 -262
- package/dist/esm/performance/AssetStreaming.js +567 -634
- package/dist/esm/performance/BenchmarkSuite.js +285 -310
- package/dist/esm/performance/DeltaCompression.js +478 -525
- package/dist/esm/performance/DeterministicPhysics.js +479 -497
- package/dist/esm/performance/ECSOptimization.js +653 -694
- package/dist/esm/performance/GameSaveSystem.js +515 -555
- package/dist/esm/performance/HotReload.js +454 -499
- package/dist/esm/performance/InputRecording.js +520 -560
- package/dist/esm/performance/InterestManagement.js +460 -499
- package/dist/esm/performance/LocalizationRuntime.js +382 -422
- package/dist/esm/performance/MemoryManagement.js +415 -469
- package/dist/esm/performance/ModSupport.js +455 -495
- package/dist/esm/performance/MultiThreadedPhysics.js +408 -442
- package/dist/esm/performance/NetworkPrediction.js +436 -481
- package/dist/esm/performance/ObjectPooling.js +582 -616
- package/dist/esm/performance/Performance.js +182 -189
- package/dist/esm/performance/PerformanceAdvanced.js +621 -636
- package/dist/esm/performance/WebGPURenderer.js +660 -682
- package/dist/esm/physics/PhysicsAdvanced.js +359 -378
- package/dist/esm/physics/PhysicsEngine2D.js +393 -426
- package/dist/esm/plugins/PluginSDK.js +435 -465
- package/dist/esm/plugins/PluginTestKit.js +315 -329
- package/dist/esm/procedural/Procedural.js +248 -253
- package/dist/esm/procedural/WorldBuilding.js +316 -313
- package/dist/esm/quest/QuestSystem.js +982 -931
- package/dist/esm/release/MobileExport.js +163 -162
- package/dist/esm/release/Release.js +234 -237
- package/dist/esm/rendering/Camera2D.js +122 -123
- package/dist/esm/rendering/Renderer2D.js +323 -334
- package/dist/esm/rendering/WebGPURenderPipeline.js +647 -650
- package/dist/esm/runtime3d/Runtime3D.js +368 -377
- package/dist/esm/runtime3d/SceneEditor3D.js +268 -262
- package/dist/esm/scene/SceneManager.js +178 -192
- package/dist/esm/scripting/GraphToAST.js +576 -546
- package/dist/esm/scripting/LanguageExporter.js +263 -278
- package/dist/esm/scripting/NodeGraph.js +550 -569
- package/dist/esm/scripting/ScriptAST.js +45 -38
- package/dist/esm/scripting/VisualScripting2.js +1025 -1064
- package/dist/esm/scripting/exporters/CSharpExporter.js +465 -495
- package/dist/esm/scripting/exporters/GDScriptExporter.js +391 -441
- package/dist/esm/scripting/exporters/LuaExporter.js +407 -446
- package/dist/esm/scripting/exporters/PythonExporter.js +485 -548
- package/dist/esm/scripting/exporters/RustExporter.js +460 -511
- package/dist/esm/scripting/exporters/TypeScriptExporter.js +506 -555
- package/dist/esm/social/Social.js +77 -79
- package/dist/esm/systems/LightingSystem.js +855 -930
- package/dist/esm/systems/ParticleSystem2.js +1453 -1450
- package/dist/esm/systems/PhysicsDebugSystem.js +1078 -1140
- package/dist/esm/systems/TerrainSystem.js +996 -1097
- package/dist/esm/templates/ActionTemplates.js +307 -308
- package/dist/esm/templates/FightingTemplate.js +439 -462
- package/dist/esm/templates/MetroidvaniaTemplate.js +391 -404
- package/dist/esm/templates/PartyTemplates.js +206 -201
- package/dist/esm/templates/PuzzleTemplates.js +260 -260
- package/dist/esm/templates/RPGTemplates.js +172 -177
- package/dist/esm/templates/SportsTemplates.js +251 -249
- package/dist/esm/templates/StrategyTemplates.js +158 -152
- package/dist/esm/templates/SurvivalTemplate.js +367 -379
- package/dist/esm/templates/WaveDefense.js +501 -525
- package/dist/esm/tilemap/Tilemap.js +209 -213
- package/dist/esm/tutorials/TutorialBranching.js +399 -416
- package/dist/esm/tutorials/TutorialEngine.js +893 -930
- package/dist/esm/tutorials/TutorialOverlay.js +603 -639
- package/dist/esm/tutorials/content/Tutorials_T05_T08.js +792 -808
- package/dist/esm/tutorials/content/Tutorials_T09_T11.js +740 -755
- package/dist/esm/tutorials/content/Tutorials_T12_T15.js +759 -777
- package/dist/esm/ui/GameUI.js +296 -311
- package/dist/esm/unity-integration/UnityAssetStore.js +704 -740
- package/dist/esm/unity-integration/UnityImport.js +1071 -1175
- package/dist/esm/unity-integration/UnityLiveLink.js +938 -980
- package/dist/esm/unity-integration/components/UnityAssetStoreBrowser.js +1234 -756
- package/dist/esm/unity-integration/components/UnityProjectBrowser.js +1241 -767
- package/dist/esm/unreal-integration/UnrealImport.js +395 -411
- package/dist/esm/unreal-integration/UnrealLiveLink.js +1105 -1136
- package/dist/esm/unreal-integration/UnrealMarketplace.js +442 -472
- package/dist/esm/unreal-integration/components/UnrealProjectBrowser.js +1151 -766
- package/dist/esm/xr/ARVR.js +181 -174
- 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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
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
|
-
|
|
404
|
-
|
|
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
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
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
|
-
|
|
431
|
-
this.
|
|
432
|
-
|
|
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
|
-
|
|
454
|
-
|
|
455
|
-
|
|
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
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
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
|
-
|
|
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
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
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
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
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
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
const
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
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
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
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
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
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
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
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
|
-
|
|
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
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
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
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
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
|
-
|
|
869
|
+
return new LightingSystem();
|
|
953
870
|
}
|
|
954
871
|
function createDefaultLightingSetup() {
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
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
|
-
|
|
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
|
+
};
|