@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.
Files changed (434) hide show
  1. package/CHANGELOG.md +9 -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,1113 +1,1046 @@
1
- 'use strict';
2
-
3
- var TypeScriptExporter = require('../scripting/exporters/TypeScriptExporter.js');
4
- var GraphToAST = require('../scripting/GraphToAST.js');
5
- var PlatformExporter = require('./PlatformExporter.js');
6
-
7
- /* ────────────────────────────────────────────────────────────────
8
- Three.js Exporter
9
-
10
- Exports Nice2Dev projects to Three.js format for 3D web games.
11
- Generates ES modules with scene management and entity systems.
12
- ──────────────────────────────────────────────────────────────── */
13
- /* ── Three.js Exporter Class ──────────────────────────────────── */
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const TypeScriptExporter = require("../scripting/exporters/TypeScriptExporter.js");
4
+ const GraphToAST = require("../scripting/GraphToAST.js");
5
+ const PlatformExporter = require("./PlatformExporter.js");
14
6
  class ThreeJSExporter extends PlatformExporter.PlatformExporter {
15
- constructor() {
16
- super(...arguments);
17
- this.platformId = 'threejs';
18
- this.platformInfo = {
19
- id: 'threejs',
20
- name: 'Three.js',
21
- description: '3D JavaScript library for WebGL',
22
- website: 'https://threejs.org',
23
- features: ['3d-rendering', 'particles', 'animation', 'vr-ar'],
24
- supportedAssets: ['sprite', 'audio', 'font', 'script', 'material', 'shader', 'animation'],
25
- exportFormats: ['.html', '.js', '.ts'],
26
- };
27
- this.tsExporter = new TypeScriptExporter.TypeScriptExporter();
28
- this.graphToAST = new GraphToAST.GraphToAST();
7
+ constructor() {
8
+ super(...arguments);
9
+ this.platformId = "threejs";
10
+ this.platformInfo = {
11
+ id: "threejs",
12
+ name: "Three.js",
13
+ description: "3D JavaScript library for WebGL",
14
+ website: "https://threejs.org",
15
+ features: ["3d-rendering", "particles", "animation", "vr-ar"],
16
+ supportedAssets: ["sprite", "audio", "font", "script", "material", "shader", "animation"],
17
+ exportFormats: [".html", ".js", ".ts"]
18
+ };
19
+ this.tsExporter = new TypeScriptExporter.TypeScriptExporter();
20
+ this.graphToAST = new GraphToAST.GraphToAST();
21
+ }
22
+ async doExport(project, options) {
23
+ const three = options.platformOptions;
24
+ const useTS = three?.typescript !== false;
25
+ const bundler = three?.bundler || "vite";
26
+ this.exportPackageJson(project, three);
27
+ this.exportIndexHtml(project, three);
28
+ this.exportMainGame(project, options, three, useTS);
29
+ this.exportScenes(project, options, useTS);
30
+ await this.exportScripts(project, options, useTS);
31
+ this.exportUtilities(three, useTS);
32
+ this.exportShaders(project);
33
+ if (bundler !== "none") {
34
+ this.exportBundlerConfig(bundler, useTS);
29
35
  }
30
- async doExport(project, options) {
31
- const three = options.platformOptions;
32
- const useTS = three?.typescript !== false;
33
- const bundler = three?.bundler || 'vite';
34
- // 1. Generate package.json
35
- this.exportPackageJson(project, three);
36
- // 2. Generate HTML entry
37
- this.exportIndexHtml(project, three);
38
- // 3. Generate main game file
39
- this.exportMainGame(project, options, three, useTS);
40
- // 4. Export scenes
41
- this.exportScenes(project, options, useTS);
42
- // 5. Export scripts
43
- await this.exportScripts(project, options, useTS);
44
- // 6. Export utilities
45
- this.exportUtilities(three, useTS);
46
- // 7. Export shaders
47
- this.exportShaders(project);
48
- // 8. Generate bundler config
49
- if (bundler !== 'none') {
50
- this.exportBundlerConfig(bundler, useTS);
51
- }
52
- // 9. Generate tsconfig if TypeScript
53
- if (useTS) {
54
- this.exportTSConfig();
55
- }
36
+ if (useTS) {
37
+ this.exportTSConfig();
56
38
  }
57
- exportPackageJson(project, three) {
58
- const useTS = three?.typescript !== false;
59
- const bundler = three?.bundler || 'vite';
60
- const threeVersion = three?.version || '^0.162.0';
61
- const dependencies = {
62
- three: threeVersion,
63
- };
64
- // Add physics engine
65
- if (three?.physics === 'cannon') {
66
- dependencies['cannon-es'] = '^0.20.0';
67
- }
68
- else if (three?.physics === 'rapier') {
69
- dependencies['@dimforge/rapier3d'] = '^0.12.0';
70
- }
71
- // Add post-processing
72
- if (three?.postProcessing) {
73
- dependencies['postprocessing'] = '^6.0.0';
74
- }
75
- const packageJson = {
76
- name: project.name.toLowerCase().replace(/\s+/g, '-'),
77
- version: project.version,
78
- description: project.description || `${project.name} - 3D game built with Nice2Dev`,
79
- type: 'module',
80
- scripts: {
81
- dev: bundler === 'vite'
82
- ? 'vite'
83
- : bundler === 'webpack'
84
- ? 'webpack serve'
85
- : 'parcel index.html',
86
- build: bundler === 'vite'
87
- ? 'vite build'
88
- : bundler === 'webpack'
89
- ? 'webpack'
90
- : 'parcel build index.html',
91
- preview: bundler === 'vite' ? 'vite preview' : 'serve dist',
92
- },
93
- dependencies,
94
- devDependencies: {
95
- ...(useTS ? { typescript: '^5.0.0', '@types/three': '^0.162.0' } : {}),
96
- ...(bundler === 'vite' ? { vite: '^5.0.0' } : {}),
97
- ...(bundler === 'webpack'
98
- ? {
99
- webpack: '^5.0.0',
100
- 'webpack-cli': '^5.0.0',
101
- 'webpack-dev-server': '^4.0.0',
102
- 'ts-loader': '^9.0.0',
103
- }
104
- : {}),
105
- },
106
- };
107
- this.addTextFile('package.json', JSON.stringify(packageJson, null, 2));
39
+ }
40
+ exportPackageJson(project, three) {
41
+ const useTS = three?.typescript !== false;
42
+ const bundler = three?.bundler || "vite";
43
+ const threeVersion = three?.version || "^0.162.0";
44
+ const dependencies = {
45
+ three: threeVersion
46
+ };
47
+ if (three?.physics === "cannon") {
48
+ dependencies["cannon-es"] = "^0.20.0";
49
+ } else if (three?.physics === "rapier") {
50
+ dependencies["@dimforge/rapier3d"] = "^0.12.0";
108
51
  }
109
- exportIndexHtml(project, _three) {
110
- const html = `<!DOCTYPE html>
111
- <html lang="en">
112
- <head>
113
- <meta charset="UTF-8">
114
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
115
- <title>${project.name}</title>
116
- <style>
117
- * {
118
- margin: 0;
119
- padding: 0;
120
- box-sizing: border-box;
121
- }
122
-
123
- html, body {
124
- width: 100%;
125
- height: 100%;
126
- overflow: hidden;
127
- }
128
-
129
- body {
130
- background-color: ${project.settings.backgroundColor};
131
- }
132
-
133
- #game-container {
134
- width: 100%;
135
- height: 100%;
136
- }
137
-
138
- canvas {
139
- display: block;
140
- width: 100%;
141
- height: 100%;
142
- }
143
-
144
- #loading-screen {
145
- position: fixed;
146
- top: 0;
147
- left: 0;
148
- width: 100%;
149
- height: 100%;
150
- background: ${project.settings.backgroundColor};
151
- display: flex;
152
- flex-direction: column;
153
- justify-content: center;
154
- align-items: center;
155
- z-index: 1000;
156
- transition: opacity 0.5s ease;
157
- }
158
-
159
- #loading-screen.hidden {
160
- opacity: 0;
161
- pointer-events: none;
162
- }
163
-
164
- .loading-bar {
165
- width: 200px;
166
- height: 4px;
167
- background: rgba(255, 255, 255, 0.2);
168
- border-radius: 2px;
169
- overflow: hidden;
170
- }
171
-
172
- .loading-bar-fill {
173
- width: 0%;
174
- height: 100%;
175
- background: white;
176
- transition: width 0.3s ease;
177
- }
178
-
179
- .loading-text {
180
- color: white;
181
- font-family: sans-serif;
182
- margin-bottom: 10px;
183
- }
184
- </style>
185
- </head>
186
- <body>
187
- <div id="loading-screen">
188
- <div class="loading-text">Loading...</div>
189
- <div class="loading-bar">
190
- <div class="loading-bar-fill" id="loading-progress"></div>
191
- </div>
192
- </div>
193
- <div id="game-container"></div>
194
- <script type="module" src="/src/main.ts"></script>
195
- </body>
196
- </html>
197
- `;
198
- this.addTextFile('index.html', html);
52
+ if (three?.postProcessing) {
53
+ dependencies["postprocessing"] = "^6.0.0";
54
+ }
55
+ const packageJson = {
56
+ name: project.name.toLowerCase().replace(/\s+/g, "-"),
57
+ version: project.version,
58
+ description: project.description || `${project.name} - 3D game built with Nice2Dev`,
59
+ type: "module",
60
+ scripts: {
61
+ dev: bundler === "vite" ? "vite" : bundler === "webpack" ? "webpack serve" : "parcel index.html",
62
+ build: bundler === "vite" ? "vite build" : bundler === "webpack" ? "webpack" : "parcel build index.html",
63
+ preview: bundler === "vite" ? "vite preview" : "serve dist"
64
+ },
65
+ dependencies,
66
+ devDependencies: {
67
+ ...useTS ? { typescript: "^5.0.0", "@types/three": "^0.162.0" } : {},
68
+ ...bundler === "vite" ? { vite: "^5.0.0" } : {},
69
+ ...bundler === "webpack" ? {
70
+ webpack: "^5.0.0",
71
+ "webpack-cli": "^5.0.0",
72
+ "webpack-dev-server": "^4.0.0",
73
+ "ts-loader": "^9.0.0"
74
+ } : {}
75
+ }
76
+ };
77
+ this.addTextFile("package.json", JSON.stringify(packageJson, null, 2));
78
+ }
79
+ exportIndexHtml(project, _three) {
80
+ const html = `<!DOCTYPE html>
81
+ <html lang="en">
82
+ <head>
83
+ <meta charset="UTF-8">
84
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
85
+ <title>${project.name}</title>
86
+ <style>
87
+ * {
88
+ margin: 0;
89
+ padding: 0;
90
+ box-sizing: border-box;
91
+ }
92
+
93
+ html, body {
94
+ width: 100%;
95
+ height: 100%;
96
+ overflow: hidden;
97
+ }
98
+
99
+ body {
100
+ background-color: ${project.settings.backgroundColor};
101
+ }
102
+
103
+ #game-container {
104
+ width: 100%;
105
+ height: 100%;
199
106
  }
200
- exportMainGame(project, options, three, useTS) {
201
- const ext = useTS ? 'ts' : 'js';
202
- const { width: _width, height: _height } = project.settings.resolution;
203
- const hasPhysics = three?.physics && three.physics !== 'none';
204
- const hasXR = three?.xr;
205
- const hasOrbitControls = three?.orbitControls;
206
- const hasPostProcessing = three?.postProcessing;
207
- let imports = `import * as THREE from 'three';
208
- import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
209
- import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
107
+
108
+ canvas {
109
+ display: block;
110
+ width: 100%;
111
+ height: 100%;
112
+ }
113
+
114
+ #loading-screen {
115
+ position: fixed;
116
+ top: 0;
117
+ left: 0;
118
+ width: 100%;
119
+ height: 100%;
120
+ background: ${project.settings.backgroundColor};
121
+ display: flex;
122
+ flex-direction: column;
123
+ justify-content: center;
124
+ align-items: center;
125
+ z-index: 1000;
126
+ transition: opacity 0.5s ease;
127
+ }
128
+
129
+ #loading-screen.hidden {
130
+ opacity: 0;
131
+ pointer-events: none;
132
+ }
133
+
134
+ .loading-bar {
135
+ width: 200px;
136
+ height: 4px;
137
+ background: rgba(255, 255, 255, 0.2);
138
+ border-radius: 2px;
139
+ overflow: hidden;
140
+ }
141
+
142
+ .loading-bar-fill {
143
+ width: 0%;
144
+ height: 100%;
145
+ background: white;
146
+ transition: width 0.3s ease;
147
+ }
148
+
149
+ .loading-text {
150
+ color: white;
151
+ font-family: sans-serif;
152
+ margin-bottom: 10px;
153
+ }
154
+ </style>
155
+ </head>
156
+ <body>
157
+ <div id="loading-screen">
158
+ <div class="loading-text">Loading...</div>
159
+ <div class="loading-bar">
160
+ <div class="loading-bar-fill" id="loading-progress"></div>
161
+ </div>
162
+ </div>
163
+ <div id="game-container"></div>
164
+ <script type="module" src="/src/main.ts"><\/script>
165
+ </body>
166
+ </html>
210
167
  `;
211
- if (hasOrbitControls) {
212
- imports += `import { OrbitControls } from 'three/addons/controls/OrbitControls.js';\n`;
213
- }
214
- if (hasXR) {
215
- imports += `import { VRButton } from 'three/addons/webxr/VRButton.js';\n`;
216
- }
217
- if (hasPostProcessing) {
218
- imports += `import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
219
- import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
220
- import { UnrealBloomPass } from 'three/addons/postprocessing/UnrealBloomPass.js';
168
+ this.addTextFile("index.html", html);
169
+ }
170
+ exportMainGame(project, options, three, useTS) {
171
+ const ext = useTS ? "ts" : "js";
172
+ const { width: _width, height: _height } = project.settings.resolution;
173
+ const hasPhysics = three?.physics && three.physics !== "none";
174
+ const hasXR = three?.xr;
175
+ const hasOrbitControls = three?.orbitControls;
176
+ const hasPostProcessing = three?.postProcessing;
177
+ let imports = `import * as THREE from 'three';
178
+ import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
179
+ import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
221
180
  `;
222
- }
223
- if (hasPhysics && three?.physics === 'cannon') {
224
- imports += `import * as CANNON from 'cannon-es';\n`;
225
- }
226
- imports += `
227
- import { GameManager } from './game/GameManager${useTS ? '' : '.js'}';
228
- import { AssetLoader } from './game/AssetLoader${useTS ? '' : '.js'}';
229
- import { InputManager } from './game/InputManager${useTS ? '' : '.js'}';
181
+ if (hasOrbitControls) {
182
+ imports += `import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
230
183
  `;
231
- // Scene imports
232
- for (const scene of project.scenes) {
233
- const sceneName = this.sanitizeName(scene.name);
234
- imports += `import { ${sceneName}Scene } from './scenes/${sceneName}${useTS ? '' : '.js'}';\n`;
235
- }
236
- const main = `${imports}
237
-
238
- ${useTS
239
- ? `
240
- interface GameConfig {
241
- container: HTMLElement;
242
- width: number;
243
- height: number;
244
- }
245
- `
246
- : ''}
247
-
248
- class Game {
249
- ${useTS ? 'private renderer: THREE.WebGLRenderer;' : ''}
250
- ${useTS ? 'private camera: THREE.PerspectiveCamera;' : ''}
251
- ${useTS ? 'private scene: THREE.Scene;' : ''}
252
- ${useTS ? 'private clock: THREE.Clock;' : ''}
253
- ${useTS ? 'private gameManager: GameManager;' : ''}
254
- ${useTS ? 'private assetLoader: AssetLoader;' : ''}
255
- ${useTS ? 'private inputManager: InputManager;' : ''}
256
- ${hasOrbitControls && useTS ? 'private controls: OrbitControls;' : ''}
257
- ${hasPhysics && three?.physics === 'cannon' && useTS ? 'private world: CANNON.World;' : ''}
258
- ${hasPostProcessing && useTS ? 'private composer: EffectComposer;' : ''}
259
-
260
- async init()${useTS ? ': Promise<void>' : ''} {
261
- const container = document.getElementById('game-container');
262
- if (!container) throw new Error('Container not found');
263
-
264
- // Initialize renderer
265
- this.renderer = new THREE.WebGLRenderer({
266
- antialias: ${!project.settings.rendering?.pixelArt},
267
- alpha: false,
268
- powerPreference: 'high-performance',
269
- });
270
- this.renderer.setSize(window.innerWidth, window.innerHeight);
271
- this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
272
- this.renderer.shadowMap.enabled = true;
273
- this.renderer.shadowMap.type = THREE.PCFSoftShadowMap;
274
- this.renderer.outputColorSpace = THREE.SRGBColorSpace;
275
- this.renderer.toneMapping = THREE.ACESFilmicToneMapping;
276
- this.renderer.toneMappingExposure = 1;
277
- container.appendChild(this.renderer.domElement);
278
-
279
- ${hasXR
280
- ? `
281
- // Enable XR
282
- this.renderer.xr.enabled = true;
283
- document.body.appendChild(VRButton.createButton(this.renderer));
284
- `
285
- : ''}
286
-
287
- // Initialize camera
288
- this.camera = new THREE.PerspectiveCamera(
289
- 75,
290
- window.innerWidth / window.innerHeight,
291
- 0.1,
292
- 1000
293
- );
294
- this.camera.position.set(0, 5, 10);
295
-
296
- // Initialize scene
297
- this.scene = new THREE.Scene();
298
- this.scene.background = new THREE.Color('${project.settings.backgroundColor}');
299
-
300
- ${hasOrbitControls
301
- ? `
302
- // Initialize controls
303
- this.controls = new OrbitControls(this.camera, this.renderer.domElement);
304
- this.controls.enableDamping = true;
305
- this.controls.dampingFactor = 0.05;
306
- `
307
- : ''}
308
-
309
- ${hasPhysics && three?.physics === 'cannon'
310
- ? `
311
- // Initialize physics
312
- this.world = new CANNON.World();
313
- this.world.gravity.set(
314
- ${project.settings.physics?.gravity.x ?? 0},
315
- ${project.settings.physics?.gravity.y ?? -9.82},
316
- 0
317
- );
318
- this.world.broadphase = new CANNON.NaiveBroadphase();
319
- `
320
- : ''}
321
-
322
- ${hasPostProcessing
323
- ? `
324
- // Initialize post-processing
325
- this.composer = new EffectComposer(this.renderer);
326
- this.composer.addPass(new RenderPass(this.scene, this.camera));
327
- this.composer.addPass(new UnrealBloomPass(
328
- new THREE.Vector2(window.innerWidth, window.innerHeight),
329
- 0.5, // strength
330
- 0.4, // radius
331
- 0.85 // threshold
332
- ));
333
- `
334
- : ''}
335
-
336
- // Initialize managers
337
- this.clock = new THREE.Clock();
338
- this.assetLoader = new AssetLoader();
339
- this.inputManager = new InputManager();
340
- this.gameManager = new GameManager(
341
- this.scene,
342
- this.camera,
343
- this.assetLoader,
344
- this.inputManager
345
- ${hasPhysics && three?.physics === 'cannon' ? ', this.world' : ''}
346
- );
347
-
348
- // Load assets
349
- await this.loadAssets();
350
-
351
- // Load initial scene
352
- const initialScene = new ${this.sanitizeName(project.scenes[0]?.name || 'Main')}Scene(this.gameManager);
353
- await initialScene.init();
354
- this.gameManager.setCurrentScene(initialScene);
355
-
356
- // Hide loading screen
357
- const loadingScreen = document.getElementById('loading-screen');
358
- if (loadingScreen) {
359
- loadingScreen.classList.add('hidden');
360
- }
361
-
362
- // Handle resize
363
- window.addEventListener('resize', this.onResize.bind(this));
364
-
365
- // Start game loop
366
- ${hasXR
367
- ? `
368
- this.renderer.setAnimationLoop(this.animate.bind(this));
369
- `
370
- : `
371
- this.animate();
372
- `}
373
-
374
- console.log('${project.name} initialized!');
375
- }
376
-
377
- private async loadAssets()${useTS ? ': Promise<void>' : ''} {
378
- const progressBar = document.getElementById('loading-progress');
379
-
380
- const updateProgress = (progress${useTS ? ': number' : ''}) => {
381
- if (progressBar) {
382
- progressBar.style.width = \`\${progress * 100}%\`;
383
- }
384
- };
385
-
386
- await this.assetLoader.loadAll(updateProgress);
387
- }
388
-
389
- private animate(${hasXR ? 'time' + (useTS ? ': number' : '') : ''})${useTS ? ': void' : ''} {
390
- ${hasXR ? '' : 'requestAnimationFrame(this.animate.bind(this));'}
391
-
392
- const delta = this.clock.getDelta();
393
-
394
- ${hasOrbitControls ? 'this.controls.update();' : ''}
395
-
396
- ${hasPhysics && three?.physics === 'cannon'
397
- ? `
398
- // Update physics
399
- this.world.step(1 / 60, delta, 3);
400
- `
401
- : ''}
402
-
403
- // Update game
404
- this.gameManager.update(delta);
405
-
406
- // Update input
407
- this.inputManager.update();
408
-
409
- // Render
410
- ${hasPostProcessing ? 'this.composer.render();' : 'this.renderer.render(this.scene, this.camera);'}
411
- }
412
-
413
- private onResize()${useTS ? ': void' : ''} {
414
- this.camera.aspect = window.innerWidth / window.innerHeight;
415
- this.camera.updateProjectionMatrix();
416
- this.renderer.setSize(window.innerWidth, window.innerHeight);
417
- ${hasPostProcessing ? 'this.composer.setSize(window.innerWidth, window.innerHeight);' : ''}
418
- }
419
- }
420
-
421
- // Start game
422
- const game = new Game();
423
- game.init().catch(console.error);
424
- `;
425
- this.addTextFile(`src/main.${ext}`, main);
426
184
  }
427
- exportScenes(project, options, useTS) {
428
- for (const scene of project.scenes) {
429
- this.exportScene(scene, project, useTS);
430
- }
185
+ if (hasXR) {
186
+ imports += `import { VRButton } from 'three/addons/webxr/VRButton.js';
187
+ `;
431
188
  }
432
- exportScene(scene, project, useTS) {
433
- const ext = useTS ? 'ts' : 'js';
434
- const sceneName = this.sanitizeName(scene.name);
435
- let content = `import * as THREE from 'three';
436
- import { GameManager } from '../game/GameManager${useTS ? '' : '.js'}';
437
- ${useTS ? `import type { GameScene } from '../game/GameManager';` : ''}
438
-
439
- export class ${sceneName}Scene ${useTS ? 'implements GameScene' : ''} {
440
- ${useTS ? 'public name: string;' : ''}
441
- ${useTS ? 'public container: THREE.Group;' : ''}
442
- ${useTS ? 'private gameManager: GameManager;' : ''}
443
- ${useTS ? 'private entities: Map<string, THREE.Object3D> = new Map();' : ''}
444
- ${useTS ? 'private lights: THREE.Light[] = [];' : ''}
445
-
446
- constructor(gameManager${useTS ? ': GameManager' : ''}) {
447
- this.name = '${scene.name}';
448
- this.gameManager = gameManager;
449
- this.container = new THREE.Group();
450
- ${useTS
451
- ? ''
452
- : `
453
- this.entities = new Map();
454
- this.lights = [];`}
455
- }
456
-
457
- async init()${useTS ? ': Promise<void>' : ''} {
458
- // Add default lighting
459
- this.setupLighting();
460
-
461
- // Create entities
189
+ if (hasPostProcessing) {
190
+ imports += `import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
191
+ import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
192
+ import { UnrealBloomPass } from 'three/addons/postprocessing/UnrealBloomPass.js';
462
193
  `;
463
- // Create entities
464
- for (const entity of scene.entities) {
465
- content += this.generateEntityCode(entity, project, useTS);
466
- }
467
- content += `
468
- // Add container to scene
469
- this.gameManager.scene.add(this.container);
470
- }
471
-
472
- private setupLighting()${useTS ? ': void' : ''} {
473
- // Ambient light
474
- const ambient = new THREE.AmbientLight(0xffffff, 0.4);
475
- this.container.add(ambient);
476
- this.lights.push(ambient);
477
-
478
- // Directional light (sun)
479
- const directional = new THREE.DirectionalLight(0xffffff, 0.8);
480
- directional.position.set(10, 20, 10);
481
- directional.castShadow = true;
482
- directional.shadow.mapSize.width = 2048;
483
- directional.shadow.mapSize.height = 2048;
484
- directional.shadow.camera.near = 0.1;
485
- directional.shadow.camera.far = 100;
486
- directional.shadow.camera.left = -20;
487
- directional.shadow.camera.right = 20;
488
- directional.shadow.camera.top = 20;
489
- directional.shadow.camera.bottom = -20;
490
- this.container.add(directional);
491
- this.lights.push(directional);
492
- }
493
-
494
- update(delta${useTS ? ': number' : ''})${useTS ? ': void' : ''} {
495
- // Update logic for scene entities
496
- }
497
-
498
- destroy()${useTS ? ': void' : ''} {
499
- // Clean up
500
- this.container.traverse((object) => {
501
- if (object ${useTS ? 'instanceof THREE.Mesh' : '.isMesh'}) {
502
- object.geometry.dispose();
503
- if (Array.isArray(object.material)) {
504
- object.material.forEach(m => m.dispose());
505
- } else {
506
- object.material.dispose();
507
- }
508
- }
509
- });
510
-
511
- this.gameManager.scene.remove(this.container);
512
- this.entities.clear();
513
- }
514
- }
194
+ }
195
+ if (hasPhysics && three?.physics === "cannon") {
196
+ imports += `import * as CANNON from 'cannon-es';
515
197
  `;
516
- this.addTextFile(`src/scenes/${sceneName}.${ext}`, content);
517
198
  }
518
- generateEntityCode(entity, project, useTS) {
519
- let code = `
520
- // Entity: ${entity.name}
521
- {
199
+ imports += `
200
+ import { GameManager } from './game/GameManager${useTS ? "" : ".js"}';
201
+ import { AssetLoader } from './game/AssetLoader${useTS ? "" : ".js"}';
202
+ import { InputManager } from './game/InputManager${useTS ? "" : ".js"}';
522
203
  `;
523
- // Determine what kind of object to create based on components
524
- const hasMesh = entity.components.some((c) => c.type === 'mesh' ||
525
- c.type === 'box' ||
526
- c.type === 'sphere' ||
527
- c.type === 'plane' ||
528
- c.type === 'cylinder');
529
- const hasModel = entity.components.some((c) => c.type === 'model');
530
- const hasLight = entity.components.some((c) => c.type.includes('light'));
531
- if (hasLight) {
532
- const lightComp = entity.components.find((c) => c.type.includes('light'));
533
- if (lightComp) {
534
- code += this.generateLightCode(entity, lightComp, useTS);
535
- }
536
- }
537
- else if (hasModel) {
538
- const modelComp = entity.components.find((c) => c.type === 'model');
539
- if (modelComp) {
540
- code += this.generateModelCode(entity, modelComp, project, useTS);
541
- }
542
- }
543
- else if (hasMesh) {
544
- code += this.generateMeshCode(entity, project, useTS);
545
- }
546
- else {
547
- // Empty group
548
- code += ` const entity = new THREE.Group();
549
- entity.name = '${entity.name}';
204
+ for (const scene of project.scenes) {
205
+ const sceneName = this.sanitizeName(scene.name);
206
+ imports += `import { ${sceneName}Scene } from './scenes/${sceneName}${useTS ? "" : ".js"}';
550
207
  `;
551
- }
552
- code += `
553
- entity.position.set(${entity.position?.x ?? 0}, ${entity.position?.y ?? 0}, 0);
554
- entity.rotation.z = ${entity.rotation ?? 0};
555
- entity.scale.set(${entity.scale?.x ?? 1}, ${entity.scale?.y ?? 1}, 1);
556
-
557
- this.container.add(entity);
558
- this.entities.set('${entity.id}', entity);
559
- }
208
+ }
209
+ const main = `${imports}
210
+
211
+ ${useTS ? `
212
+ interface GameConfig {
213
+ container: HTMLElement;
214
+ width: number;
215
+ height: number;
216
+ }
217
+ ` : ""}
218
+
219
+ class Game {
220
+ ${useTS ? "private renderer: THREE.WebGLRenderer;" : ""}
221
+ ${useTS ? "private camera: THREE.PerspectiveCamera;" : ""}
222
+ ${useTS ? "private scene: THREE.Scene;" : ""}
223
+ ${useTS ? "private clock: THREE.Clock;" : ""}
224
+ ${useTS ? "private gameManager: GameManager;" : ""}
225
+ ${useTS ? "private assetLoader: AssetLoader;" : ""}
226
+ ${useTS ? "private inputManager: InputManager;" : ""}
227
+ ${hasOrbitControls && useTS ? "private controls: OrbitControls;" : ""}
228
+ ${hasPhysics && three?.physics === "cannon" && useTS ? "private world: CANNON.World;" : ""}
229
+ ${hasPostProcessing && useTS ? "private composer: EffectComposer;" : ""}
230
+
231
+ async init()${useTS ? ": Promise<void>" : ""} {
232
+ const container = document.getElementById('game-container');
233
+ if (!container) throw new Error('Container not found');
234
+
235
+ // Initialize renderer
236
+ this.renderer = new THREE.WebGLRenderer({
237
+ antialias: ${!project.settings.rendering?.pixelArt},
238
+ alpha: false,
239
+ powerPreference: 'high-performance',
240
+ });
241
+ this.renderer.setSize(window.innerWidth, window.innerHeight);
242
+ this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
243
+ this.renderer.shadowMap.enabled = true;
244
+ this.renderer.shadowMap.type = THREE.PCFSoftShadowMap;
245
+ this.renderer.outputColorSpace = THREE.SRGBColorSpace;
246
+ this.renderer.toneMapping = THREE.ACESFilmicToneMapping;
247
+ this.renderer.toneMappingExposure = 1;
248
+ container.appendChild(this.renderer.domElement);
249
+
250
+ ${hasXR ? `
251
+ // Enable XR
252
+ this.renderer.xr.enabled = true;
253
+ document.body.appendChild(VRButton.createButton(this.renderer));
254
+ ` : ""}
255
+
256
+ // Initialize camera
257
+ this.camera = new THREE.PerspectiveCamera(
258
+ 75,
259
+ window.innerWidth / window.innerHeight,
260
+ 0.1,
261
+ 1000
262
+ );
263
+ this.camera.position.set(0, 5, 10);
264
+
265
+ // Initialize scene
266
+ this.scene = new THREE.Scene();
267
+ this.scene.background = new THREE.Color('${project.settings.backgroundColor}');
268
+
269
+ ${hasOrbitControls ? `
270
+ // Initialize controls
271
+ this.controls = new OrbitControls(this.camera, this.renderer.domElement);
272
+ this.controls.enableDamping = true;
273
+ this.controls.dampingFactor = 0.05;
274
+ ` : ""}
275
+
276
+ ${hasPhysics && three?.physics === "cannon" ? `
277
+ // Initialize physics
278
+ this.world = new CANNON.World();
279
+ this.world.gravity.set(
280
+ ${project.settings.physics?.gravity.x ?? 0},
281
+ ${project.settings.physics?.gravity.y ?? -9.82},
282
+ 0
283
+ );
284
+ this.world.broadphase = new CANNON.NaiveBroadphase();
285
+ ` : ""}
286
+
287
+ ${hasPostProcessing ? `
288
+ // Initialize post-processing
289
+ this.composer = new EffectComposer(this.renderer);
290
+ this.composer.addPass(new RenderPass(this.scene, this.camera));
291
+ this.composer.addPass(new UnrealBloomPass(
292
+ new THREE.Vector2(window.innerWidth, window.innerHeight),
293
+ 0.5, // strength
294
+ 0.4, // radius
295
+ 0.85 // threshold
296
+ ));
297
+ ` : ""}
298
+
299
+ // Initialize managers
300
+ this.clock = new THREE.Clock();
301
+ this.assetLoader = new AssetLoader();
302
+ this.inputManager = new InputManager();
303
+ this.gameManager = new GameManager(
304
+ this.scene,
305
+ this.camera,
306
+ this.assetLoader,
307
+ this.inputManager
308
+ ${hasPhysics && three?.physics === "cannon" ? ", this.world" : ""}
309
+ );
310
+
311
+ // Load assets
312
+ await this.loadAssets();
313
+
314
+ // Load initial scene
315
+ const initialScene = new ${this.sanitizeName(project.scenes[0]?.name || "Main")}Scene(this.gameManager);
316
+ await initialScene.init();
317
+ this.gameManager.setCurrentScene(initialScene);
318
+
319
+ // Hide loading screen
320
+ const loadingScreen = document.getElementById('loading-screen');
321
+ if (loadingScreen) {
322
+ loadingScreen.classList.add('hidden');
323
+ }
324
+
325
+ // Handle resize
326
+ window.addEventListener('resize', this.onResize.bind(this));
327
+
328
+ // Start game loop
329
+ ${hasXR ? `
330
+ this.renderer.setAnimationLoop(this.animate.bind(this));
331
+ ` : `
332
+ this.animate();
333
+ `}
334
+
335
+ console.log('${project.name} initialized!');
336
+ }
337
+
338
+ private async loadAssets()${useTS ? ": Promise<void>" : ""} {
339
+ const progressBar = document.getElementById('loading-progress');
340
+
341
+ const updateProgress = (progress${useTS ? ": number" : ""}) => {
342
+ if (progressBar) {
343
+ progressBar.style.width = \`\${progress * 100}%\`;
344
+ }
345
+ };
346
+
347
+ await this.assetLoader.loadAll(updateProgress);
348
+ }
349
+
350
+ private animate(${hasXR ? "time" + (useTS ? ": number" : "") : ""})${useTS ? ": void" : ""} {
351
+ ${hasXR ? "" : "requestAnimationFrame(this.animate.bind(this));"}
352
+
353
+ const delta = this.clock.getDelta();
354
+
355
+ ${hasOrbitControls ? "this.controls.update();" : ""}
356
+
357
+ ${hasPhysics && three?.physics === "cannon" ? `
358
+ // Update physics
359
+ this.world.step(1 / 60, delta, 3);
360
+ ` : ""}
361
+
362
+ // Update game
363
+ this.gameManager.update(delta);
364
+
365
+ // Update input
366
+ this.inputManager.update();
367
+
368
+ // Render
369
+ ${hasPostProcessing ? "this.composer.render();" : "this.renderer.render(this.scene, this.camera);"}
370
+ }
371
+
372
+ private onResize()${useTS ? ": void" : ""} {
373
+ this.camera.aspect = window.innerWidth / window.innerHeight;
374
+ this.camera.updateProjectionMatrix();
375
+ this.renderer.setSize(window.innerWidth, window.innerHeight);
376
+ ${hasPostProcessing ? "this.composer.setSize(window.innerWidth, window.innerHeight);" : ""}
377
+ }
378
+ }
379
+
380
+ // Start game
381
+ const game = new Game();
382
+ game.init().catch(console.error);
560
383
  `;
561
- // Process children
562
- if (entity.children) {
563
- for (const child of entity.children) {
564
- code += this.generateEntityCode(child, project, useTS);
565
- }
566
- }
567
- return code;
384
+ this.addTextFile(`src/main.${ext}`, main);
385
+ }
386
+ exportScenes(project, options, useTS) {
387
+ for (const scene of project.scenes) {
388
+ this.exportScene(scene, project, useTS);
568
389
  }
569
- generateMeshCode(entity, project, _useTS) {
570
- const meshComp = entity.components.find((c) => c.type === 'mesh' ||
571
- c.type === 'box' ||
572
- c.type === 'sphere' ||
573
- c.type === 'plane' ||
574
- c.type === 'cylinder');
575
- if (!meshComp) {
576
- return ' const entity = new THREE.Group();\n';
577
- }
578
- const meshProps = meshComp.properties ?? {};
579
- let geometryCode = '';
580
- let materialCode = '';
581
- // Geometry
582
- switch (meshComp.type) {
583
- case 'box':
584
- geometryCode = `new THREE.BoxGeometry(${meshProps.width ?? 1}, ${meshProps.height ?? 1}, ${meshProps.depth ?? 1})`;
585
- break;
586
- case 'sphere':
587
- geometryCode = `new THREE.SphereGeometry(${meshProps.radius ?? 0.5}, 32, 16)`;
588
- break;
589
- case 'plane':
590
- geometryCode = `new THREE.PlaneGeometry(${meshProps.width ?? 10}, ${meshProps.height ?? 10})`;
591
- break;
592
- case 'cylinder':
593
- geometryCode = `new THREE.CylinderGeometry(${meshProps.radiusTop ?? 0.5}, ${meshProps.radiusBottom ?? 0.5}, ${meshProps.height ?? 1}, 32)`;
594
- break;
595
- default:
596
- geometryCode = 'new THREE.BoxGeometry(1, 1, 1)';
597
- }
598
- // Material
599
- const color = meshProps.color ?? '#ffffff';
600
- const materialId = meshProps.materialId;
601
- const material = materialId ? project.assets.find((a) => a.id === materialId) : null;
602
- if (material) {
603
- const matColor = material.metadata?.color ?? color;
604
- materialCode = `new THREE.MeshStandardMaterial({
605
- color: '${matColor}',
606
- roughness: ${material.metadata?.roughness ?? 0.5},
607
- metalness: ${material.metadata?.metalness ?? 0.5},
608
- })`;
609
- }
610
- else {
611
- materialCode = `new THREE.MeshStandardMaterial({ color: '${color}' })`;
390
+ }
391
+ exportScene(scene, project, useTS) {
392
+ const ext = useTS ? "ts" : "js";
393
+ const sceneName = this.sanitizeName(scene.name);
394
+ let content = `import * as THREE from 'three';
395
+ import { GameManager } from '../game/GameManager${useTS ? "" : ".js"}';
396
+ ${useTS ? `import type { GameScene } from '../game/GameManager';` : ""}
397
+
398
+ export class ${sceneName}Scene ${useTS ? "implements GameScene" : ""} {
399
+ ${useTS ? "public name: string;" : ""}
400
+ ${useTS ? "public container: THREE.Group;" : ""}
401
+ ${useTS ? "private gameManager: GameManager;" : ""}
402
+ ${useTS ? "private entities: Map<string, THREE.Object3D> = new Map();" : ""}
403
+ ${useTS ? "private lights: THREE.Light[] = [];" : ""}
404
+
405
+ constructor(gameManager${useTS ? ": GameManager" : ""}) {
406
+ this.name = '${scene.name}';
407
+ this.gameManager = gameManager;
408
+ this.container = new THREE.Group();
409
+ ${useTS ? "" : `
410
+ this.entities = new Map();
411
+ this.lights = [];`}
412
+ }
413
+
414
+ async init()${useTS ? ": Promise<void>" : ""} {
415
+ // Add default lighting
416
+ this.setupLighting();
417
+
418
+ // Create entities
419
+ `;
420
+ for (const entity of scene.entities) {
421
+ content += this.generateEntityCode(entity, project, useTS);
422
+ }
423
+ content += `
424
+ // Add container to scene
425
+ this.gameManager.scene.add(this.container);
426
+ }
427
+
428
+ private setupLighting()${useTS ? ": void" : ""} {
429
+ // Ambient light
430
+ const ambient = new THREE.AmbientLight(0xffffff, 0.4);
431
+ this.container.add(ambient);
432
+ this.lights.push(ambient);
433
+
434
+ // Directional light (sun)
435
+ const directional = new THREE.DirectionalLight(0xffffff, 0.8);
436
+ directional.position.set(10, 20, 10);
437
+ directional.castShadow = true;
438
+ directional.shadow.mapSize.width = 2048;
439
+ directional.shadow.mapSize.height = 2048;
440
+ directional.shadow.camera.near = 0.1;
441
+ directional.shadow.camera.far = 100;
442
+ directional.shadow.camera.left = -20;
443
+ directional.shadow.camera.right = 20;
444
+ directional.shadow.camera.top = 20;
445
+ directional.shadow.camera.bottom = -20;
446
+ this.container.add(directional);
447
+ this.lights.push(directional);
448
+ }
449
+
450
+ update(delta${useTS ? ": number" : ""})${useTS ? ": void" : ""} {
451
+ // Update logic for scene entities
452
+ }
453
+
454
+ destroy()${useTS ? ": void" : ""} {
455
+ // Clean up
456
+ this.container.traverse((object) => {
457
+ if (object ${useTS ? "instanceof THREE.Mesh" : ".isMesh"}) {
458
+ object.geometry.dispose();
459
+ if (Array.isArray(object.material)) {
460
+ object.material.forEach(m => m.dispose());
461
+ } else {
462
+ object.material.dispose();
612
463
  }
613
- return ` const geometry = ${geometryCode};
614
- const material = ${materialCode};
615
- const entity = new THREE.Mesh(geometry, material);
616
- entity.name = '${entity.name}';
617
- entity.castShadow = true;
618
- entity.receiveShadow = true;
464
+ }
465
+ });
466
+
467
+ this.gameManager.scene.remove(this.container);
468
+ this.entities.clear();
469
+ }
470
+ }
471
+ `;
472
+ this.addTextFile(`src/scenes/${sceneName}.${ext}`, content);
473
+ }
474
+ generateEntityCode(entity, project, useTS) {
475
+ let code = `
476
+ // Entity: ${entity.name}
477
+ {
478
+ `;
479
+ const hasMesh = entity.components.some(
480
+ (c) => c.type === "mesh" || c.type === "box" || c.type === "sphere" || c.type === "plane" || c.type === "cylinder"
481
+ );
482
+ const hasModel = entity.components.some((c) => c.type === "model");
483
+ const hasLight = entity.components.some((c) => c.type.includes("light"));
484
+ if (hasLight) {
485
+ const lightComp = entity.components.find((c) => c.type.includes("light"));
486
+ if (lightComp) {
487
+ code += this.generateLightCode(entity, lightComp, useTS);
488
+ }
489
+ } else if (hasModel) {
490
+ const modelComp = entity.components.find((c) => c.type === "model");
491
+ if (modelComp) {
492
+ code += this.generateModelCode(entity, modelComp, project, useTS);
493
+ }
494
+ } else if (hasMesh) {
495
+ code += this.generateMeshCode(entity, project, useTS);
496
+ } else {
497
+ code += ` const entity = new THREE.Group();
498
+ entity.name = '${entity.name}';
619
499
  `;
620
500
  }
621
- generateModelCode(entity, component, _project, _useTS) {
622
- const compProps = component.properties ?? {};
623
- const modelPath = compProps.path;
624
- return ` // Model loading is handled asynchronously
625
- const entity = new THREE.Group();
626
- entity.name = '${entity.name}';
627
- ${modelPath
628
- ? `
629
- this.gameManager.assetLoader.getModel('${modelPath}').then(model => {
630
- entity.add(model.scene.clone());
631
- });`
632
- : ''}
501
+ code += `
502
+ entity.position.set(${entity.position?.x ?? 0}, ${entity.position?.y ?? 0}, 0);
503
+ entity.rotation.z = ${entity.rotation ?? 0};
504
+ entity.scale.set(${entity.scale?.x ?? 1}, ${entity.scale?.y ?? 1}, 1);
505
+
506
+ this.container.add(entity);
507
+ this.entities.set('${entity.id}', entity);
508
+ }
633
509
  `;
510
+ if (entity.children) {
511
+ for (const child of entity.children) {
512
+ code += this.generateEntityCode(child, project, useTS);
513
+ }
514
+ }
515
+ return code;
516
+ }
517
+ generateMeshCode(entity, project, _useTS) {
518
+ const meshComp = entity.components.find(
519
+ (c) => c.type === "mesh" || c.type === "box" || c.type === "sphere" || c.type === "plane" || c.type === "cylinder"
520
+ );
521
+ if (!meshComp) {
522
+ return " const entity = new THREE.Group();\n";
523
+ }
524
+ const meshProps = meshComp.properties ?? {};
525
+ let geometryCode = "";
526
+ let materialCode = "";
527
+ switch (meshComp.type) {
528
+ case "box":
529
+ geometryCode = `new THREE.BoxGeometry(${meshProps.width ?? 1}, ${meshProps.height ?? 1}, ${meshProps.depth ?? 1})`;
530
+ break;
531
+ case "sphere":
532
+ geometryCode = `new THREE.SphereGeometry(${meshProps.radius ?? 0.5}, 32, 16)`;
533
+ break;
534
+ case "plane":
535
+ geometryCode = `new THREE.PlaneGeometry(${meshProps.width ?? 10}, ${meshProps.height ?? 10})`;
536
+ break;
537
+ case "cylinder":
538
+ geometryCode = `new THREE.CylinderGeometry(${meshProps.radiusTop ?? 0.5}, ${meshProps.radiusBottom ?? 0.5}, ${meshProps.height ?? 1}, 32)`;
539
+ break;
540
+ default:
541
+ geometryCode = "new THREE.BoxGeometry(1, 1, 1)";
542
+ }
543
+ const color = meshProps.color ?? "#ffffff";
544
+ const materialId = meshProps.materialId;
545
+ const material = materialId ? project.assets.find((a) => a.id === materialId) : null;
546
+ if (material) {
547
+ const matColor = material.metadata?.color ?? color;
548
+ materialCode = `new THREE.MeshStandardMaterial({
549
+ color: '${matColor}',
550
+ roughness: ${material.metadata?.roughness ?? 0.5},
551
+ metalness: ${material.metadata?.metalness ?? 0.5},
552
+ })`;
553
+ } else {
554
+ materialCode = `new THREE.MeshStandardMaterial({ color: '${color}' })`;
634
555
  }
635
- generateLightCode(entity, component, _useTS) {
636
- const compProps = component.properties ?? {};
637
- const color = compProps.color ?? '#ffffff';
638
- const intensity = compProps.intensity ?? 1;
639
- switch (component.type) {
640
- case 'point-light':
641
- return ` const entity = new THREE.PointLight('${color}', ${intensity}, ${compProps.distance ?? 100});
642
- entity.name = '${entity.name}';
643
- entity.castShadow = ${compProps.castShadow ?? true};
556
+ return ` const geometry = ${geometryCode};
557
+ const material = ${materialCode};
558
+ const entity = new THREE.Mesh(geometry, material);
559
+ entity.name = '${entity.name}';
560
+ entity.castShadow = true;
561
+ entity.receiveShadow = true;
644
562
  `;
645
- case 'spot-light':
646
- return ` const entity = new THREE.SpotLight('${color}', ${intensity});
647
- entity.name = '${entity.name}';
648
- entity.angle = ${compProps.angle ?? Math.PI / 6};
649
- entity.penumbra = ${compProps.penumbra ?? 0.5};
650
- entity.castShadow = ${compProps.castShadow ?? true};
563
+ }
564
+ generateModelCode(entity, component, _project, _useTS) {
565
+ const compProps = component.properties ?? {};
566
+ const modelPath = compProps.path;
567
+ return ` // Model loading is handled asynchronously
568
+ const entity = new THREE.Group();
569
+ entity.name = '${entity.name}';
570
+ ${modelPath ? `
571
+ this.gameManager.assetLoader.getModel('${modelPath}').then(model => {
572
+ entity.add(model.scene.clone());
573
+ });` : ""}
651
574
  `;
652
- case 'directional-light':
653
- return ` const entity = new THREE.DirectionalLight('${color}', ${intensity});
654
- entity.name = '${entity.name}';
655
- entity.castShadow = ${compProps.castShadow ?? true};
575
+ }
576
+ generateLightCode(entity, component, _useTS) {
577
+ const compProps = component.properties ?? {};
578
+ const color = compProps.color ?? "#ffffff";
579
+ const intensity = compProps.intensity ?? 1;
580
+ switch (component.type) {
581
+ case "point-light":
582
+ return ` const entity = new THREE.PointLight('${color}', ${intensity}, ${compProps.distance ?? 100});
583
+ entity.name = '${entity.name}';
584
+ entity.castShadow = ${compProps.castShadow ?? true};
656
585
  `;
657
- case 'ambient-light':
658
- return ` const entity = new THREE.AmbientLight('${color}', ${intensity});
659
- entity.name = '${entity.name}';
586
+ case "spot-light":
587
+ return ` const entity = new THREE.SpotLight('${color}', ${intensity});
588
+ entity.name = '${entity.name}';
589
+ entity.angle = ${compProps.angle ?? Math.PI / 6};
590
+ entity.penumbra = ${compProps.penumbra ?? 0.5};
591
+ entity.castShadow = ${compProps.castShadow ?? true};
660
592
  `;
661
- case 'hemisphere-light': {
662
- const groundColor = compProps.groundColor ?? '#444444';
663
- return ` const entity = new THREE.HemisphereLight('${color}', '${groundColor}', ${intensity});
664
- entity.name = '${entity.name}';
593
+ case "directional-light":
594
+ return ` const entity = new THREE.DirectionalLight('${color}', ${intensity});
595
+ entity.name = '${entity.name}';
596
+ entity.castShadow = ${compProps.castShadow ?? true};
665
597
  `;
666
- }
667
- default:
668
- return ` const entity = new THREE.Group();
669
- entity.name = '${entity.name}';
598
+ case "ambient-light":
599
+ return ` const entity = new THREE.AmbientLight('${color}', ${intensity});
600
+ entity.name = '${entity.name}';
601
+ `;
602
+ case "hemisphere-light": {
603
+ const groundColor = compProps.groundColor ?? "#444444";
604
+ return ` const entity = new THREE.HemisphereLight('${color}', '${groundColor}', ${intensity});
605
+ entity.name = '${entity.name}';
606
+ `;
607
+ }
608
+ default:
609
+ return ` const entity = new THREE.Group();
610
+ entity.name = '${entity.name}';
670
611
  `;
671
- }
672
612
  }
673
- async exportScripts(project, options, _useTS) {
674
- for (const script of project.scripts) {
675
- try {
676
- const ast = this.graphToAST.convert(script);
677
- const result = this.tsExporter.export(ast, {
678
- includeDebugComments: options.debug,
679
- });
680
- for (const file of result.files) {
681
- this.addTextFile(`src/scripts/${file.path}`, file.content);
682
- }
683
- }
684
- catch (error) {
685
- this.addWarning('SCRIPT_EXPORT_ERROR', `Failed to export script "${script.name}": ${error}`);
686
- }
613
+ }
614
+ async exportScripts(project, options, _useTS) {
615
+ for (const script of project.scripts) {
616
+ try {
617
+ const ast = this.graphToAST.convert(script);
618
+ const result = this.tsExporter.export(ast, {
619
+ includeDebugComments: options.debug
620
+ });
621
+ for (const file of result.files) {
622
+ this.addTextFile(`src/scripts/${file.path}`, file.content);
687
623
  }
624
+ } catch (error) {
625
+ this.addWarning(
626
+ "SCRIPT_EXPORT_ERROR",
627
+ `Failed to export script "${script.name}": ${error}`
628
+ );
629
+ }
688
630
  }
689
- exportUtilities(three, useTS) {
690
- const ext = useTS ? 'ts' : 'js';
691
- const hasPhysics = three?.physics === 'cannon';
692
- // GameManager
693
- const gameManager = `import * as THREE from 'three';
694
- import { AssetLoader } from './AssetLoader${useTS ? '' : '.js'}';
695
- import { InputManager } from './InputManager${useTS ? '' : '.js'}';
696
- ${hasPhysics ? `import * as CANNON from 'cannon-es';` : ''}
697
-
698
- ${useTS
699
- ? `
700
- export interface GameScene {
701
- name: string;
702
- container: THREE.Group;
703
- init(): Promise<void>;
704
- update(delta: number): void;
705
- destroy(): void;
706
- }
707
- `
708
- : ''}
709
-
710
- export class GameManager {
711
- ${useTS ? 'public scene: THREE.Scene;' : ''}
712
- ${useTS ? 'public camera: THREE.Camera;' : ''}
713
- ${useTS ? 'public assetLoader: AssetLoader;' : ''}
714
- ${useTS ? 'public input: InputManager;' : ''}
715
- ${hasPhysics && useTS ? 'public world: CANNON.World;' : ''}
716
- ${useTS ? 'private currentScene: GameScene | null = null;' : ''}
717
- ${useTS ? 'private entities: Map<string, THREE.Object3D> = new Map();' : ''}
718
- ${useTS ? 'private isPaused: boolean = false;' : ''}
719
-
720
- constructor(
721
- scene${useTS ? ': THREE.Scene' : ''},
722
- camera${useTS ? ': THREE.Camera' : ''},
723
- assetLoader${useTS ? ': AssetLoader' : ''},
724
- inputManager${useTS ? ': InputManager' : ''}
725
- ${hasPhysics ? `, world${useTS ? ': CANNON.World' : ''}` : ''}
726
- ) {
727
- this.scene = scene;
728
- this.camera = camera;
729
- this.assetLoader = assetLoader;
730
- this.input = inputManager;
731
- ${hasPhysics ? 'this.world = world;' : ''}
732
- ${useTS
733
- ? ''
734
- : `
735
- this.currentScene = null;
736
- this.entities = new Map();
737
- this.isPaused = false;`}
738
- }
739
-
740
- setCurrentScene(scene${useTS ? ': GameScene' : ''})${useTS ? ': void' : ''} {
741
- if (this.currentScene) {
742
- this.currentScene.destroy();
743
- }
744
- this.currentScene = scene;
745
- }
746
-
747
- registerEntity(id${useTS ? ': string' : ''}, entity${useTS ? ': THREE.Object3D' : ''})${useTS ? ': void' : ''} {
748
- this.entities.set(id, entity);
749
- }
750
-
751
- getEntity(id${useTS ? ': string' : ''})${useTS ? ': THREE.Object3D | undefined' : ''} {
752
- return this.entities.get(id);
753
- }
754
-
755
- update(delta${useTS ? ': number' : ''})${useTS ? ': void' : ''} {
756
- if (this.isPaused) return;
757
-
758
- if (this.currentScene) {
759
- this.currentScene.update(delta);
760
- }
761
- }
762
-
763
- pause()${useTS ? ': void' : ''} {
764
- this.isPaused = true;
765
- }
766
-
767
- resume()${useTS ? ': void' : ''} {
768
- this.isPaused = false;
769
- }
770
-
771
- get paused()${useTS ? ': boolean' : ''} {
772
- return this.isPaused;
773
- }
774
-
775
- // Utility methods
776
- raycast(origin${useTS ? ': THREE.Vector3' : ''}, direction${useTS ? ': THREE.Vector3' : ''})${useTS ? ': THREE.Intersection | null' : ''} {
777
- const raycaster = new THREE.Raycaster(origin, direction);
778
- const intersects = raycaster.intersectObjects(this.scene.children, true);
779
- return intersects.length > 0 ? intersects[0] : null;
780
- }
781
-
782
- getMouseWorldPosition(screenX${useTS ? ': number' : ''}, screenY${useTS ? ': number' : ''}, plane${useTS ? '?: THREE.Plane' : ''})${useTS ? ': THREE.Vector3 | null' : ''} {
783
- const mouse = new THREE.Vector2(
784
- (screenX / window.innerWidth) * 2 - 1,
785
- -(screenY / window.innerHeight) * 2 + 1
786
- );
787
-
788
- const raycaster = new THREE.Raycaster();
789
- raycaster.setFromCamera(mouse, this.camera ${useTS ? 'as THREE.PerspectiveCamera' : ''});
790
-
791
- if (plane) {
792
- const target = new THREE.Vector3();
793
- raycaster.ray.intersectPlane(plane, target);
794
- return target;
795
- }
796
-
797
- const intersects = raycaster.intersectObjects(this.scene.children, true);
798
- return intersects.length > 0 ? intersects[0].point : null;
799
- }
800
- }
801
- `;
802
- this.addTextFile(`src/game/GameManager.${ext}`, gameManager);
803
- // AssetLoader
804
- const assetLoader = `import * as THREE from 'three';
805
- import { GLTFLoader${useTS ? ', GLTF' : ''} } from 'three/addons/loaders/GLTFLoader.js';
806
- import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
807
-
808
- export class AssetLoader {
809
- ${useTS ? 'private textureLoader: THREE.TextureLoader;' : ''}
810
- ${useTS ? 'private gltfLoader: GLTFLoader;' : ''}
811
- ${useTS ? 'private audioLoader: THREE.AudioLoader;' : ''}
812
- ${useTS ? 'private textures: Map<string, THREE.Texture> = new Map();' : ''}
813
- ${useTS ? 'private models: Map<string, GLTF> = new Map();' : ''}
814
- ${useTS ? 'private audio: Map<string, AudioBuffer> = new Map();' : ''}
815
-
816
- constructor() {
817
- this.textureLoader = new THREE.TextureLoader();
818
-
819
- const dracoLoader = new DRACOLoader();
820
- dracoLoader.setDecoderPath('https://www.gstatic.com/draco/versioned/decoders/1.5.6/');
821
-
822
- this.gltfLoader = new GLTFLoader();
823
- this.gltfLoader.setDRACOLoader(dracoLoader);
824
-
825
- this.audioLoader = new THREE.AudioLoader();
826
-
827
- ${useTS
828
- ? ''
829
- : `
830
- this.textures = new Map();
831
- this.models = new Map();
832
- this.audio = new Map();`}
833
- }
834
-
835
- async loadAll(onProgress${useTS ? '?: (progress: number) => void' : ''})${useTS ? ': Promise<void>' : ''} {
836
- // Load all assets here
837
- // This would be populated based on project assets
838
- if (onProgress) onProgress(1);
839
- }
840
-
841
- async loadTexture(path${useTS ? ': string' : ''})${useTS ? ': Promise<THREE.Texture>' : ''} {
842
- if (this.textures.has(path)) {
843
- return this.textures.get(path)${useTS ? '!' : ''};
844
- }
845
-
846
- return new Promise((resolve, reject) => {
847
- this.textureLoader.load(
848
- path,
849
- (texture) => {
850
- this.textures.set(path, texture);
851
- resolve(texture);
852
- },
853
- undefined,
854
- reject
855
- );
856
- });
857
- }
858
-
859
- async loadModel(path${useTS ? ': string' : ''})${useTS ? ': Promise<GLTF>' : ''} {
860
- if (this.models.has(path)) {
861
- return this.models.get(path)${useTS ? '!' : ''};
862
- }
863
-
864
- return new Promise((resolve, reject) => {
865
- this.gltfLoader.load(
866
- path,
867
- (gltf) => {
868
- this.models.set(path, gltf);
869
- resolve(gltf);
870
- },
871
- undefined,
872
- reject
873
- );
874
- });
875
- }
876
-
877
- getTexture(path${useTS ? ': string' : ''})${useTS ? ': THREE.Texture | undefined' : ''} {
878
- return this.textures.get(path);
879
- }
880
-
881
- getModel(path${useTS ? ': string' : ''})${useTS ? ': Promise<GLTF>' : ''} {
882
- return this.loadModel(path);
883
- }
884
-
885
- getAudio(path${useTS ? ': string' : ''})${useTS ? ': AudioBuffer | undefined' : ''} {
886
- return this.audio.get(path);
887
- }
888
- }
631
+ }
632
+ exportUtilities(three, useTS) {
633
+ const ext = useTS ? "ts" : "js";
634
+ const hasPhysics = three?.physics === "cannon";
635
+ const gameManager = `import * as THREE from 'three';
636
+ import { AssetLoader } from './AssetLoader${useTS ? "" : ".js"}';
637
+ import { InputManager } from './InputManager${useTS ? "" : ".js"}';
638
+ ${hasPhysics ? `import * as CANNON from 'cannon-es';` : ""}
639
+
640
+ ${useTS ? `
641
+ export interface GameScene {
642
+ name: string;
643
+ container: THREE.Group;
644
+ init(): Promise<void>;
645
+ update(delta: number): void;
646
+ destroy(): void;
647
+ }
648
+ ` : ""}
649
+
650
+ export class GameManager {
651
+ ${useTS ? "public scene: THREE.Scene;" : ""}
652
+ ${useTS ? "public camera: THREE.Camera;" : ""}
653
+ ${useTS ? "public assetLoader: AssetLoader;" : ""}
654
+ ${useTS ? "public input: InputManager;" : ""}
655
+ ${hasPhysics && useTS ? "public world: CANNON.World;" : ""}
656
+ ${useTS ? "private currentScene: GameScene | null = null;" : ""}
657
+ ${useTS ? "private entities: Map<string, THREE.Object3D> = new Map();" : ""}
658
+ ${useTS ? "private isPaused: boolean = false;" : ""}
659
+
660
+ constructor(
661
+ scene${useTS ? ": THREE.Scene" : ""},
662
+ camera${useTS ? ": THREE.Camera" : ""},
663
+ assetLoader${useTS ? ": AssetLoader" : ""},
664
+ inputManager${useTS ? ": InputManager" : ""}
665
+ ${hasPhysics ? `, world${useTS ? ": CANNON.World" : ""}` : ""}
666
+ ) {
667
+ this.scene = scene;
668
+ this.camera = camera;
669
+ this.assetLoader = assetLoader;
670
+ this.input = inputManager;
671
+ ${hasPhysics ? "this.world = world;" : ""}
672
+ ${useTS ? "" : `
673
+ this.currentScene = null;
674
+ this.entities = new Map();
675
+ this.isPaused = false;`}
676
+ }
677
+
678
+ setCurrentScene(scene${useTS ? ": GameScene" : ""})${useTS ? ": void" : ""} {
679
+ if (this.currentScene) {
680
+ this.currentScene.destroy();
681
+ }
682
+ this.currentScene = scene;
683
+ }
684
+
685
+ registerEntity(id${useTS ? ": string" : ""}, entity${useTS ? ": THREE.Object3D" : ""})${useTS ? ": void" : ""} {
686
+ this.entities.set(id, entity);
687
+ }
688
+
689
+ getEntity(id${useTS ? ": string" : ""})${useTS ? ": THREE.Object3D | undefined" : ""} {
690
+ return this.entities.get(id);
691
+ }
692
+
693
+ update(delta${useTS ? ": number" : ""})${useTS ? ": void" : ""} {
694
+ if (this.isPaused) return;
695
+
696
+ if (this.currentScene) {
697
+ this.currentScene.update(delta);
698
+ }
699
+ }
700
+
701
+ pause()${useTS ? ": void" : ""} {
702
+ this.isPaused = true;
703
+ }
704
+
705
+ resume()${useTS ? ": void" : ""} {
706
+ this.isPaused = false;
707
+ }
708
+
709
+ get paused()${useTS ? ": boolean" : ""} {
710
+ return this.isPaused;
711
+ }
712
+
713
+ // Utility methods
714
+ raycast(origin${useTS ? ": THREE.Vector3" : ""}, direction${useTS ? ": THREE.Vector3" : ""})${useTS ? ": THREE.Intersection | null" : ""} {
715
+ const raycaster = new THREE.Raycaster(origin, direction);
716
+ const intersects = raycaster.intersectObjects(this.scene.children, true);
717
+ return intersects.length > 0 ? intersects[0] : null;
718
+ }
719
+
720
+ getMouseWorldPosition(screenX${useTS ? ": number" : ""}, screenY${useTS ? ": number" : ""}, plane${useTS ? "?: THREE.Plane" : ""})${useTS ? ": THREE.Vector3 | null" : ""} {
721
+ const mouse = new THREE.Vector2(
722
+ (screenX / window.innerWidth) * 2 - 1,
723
+ -(screenY / window.innerHeight) * 2 + 1
724
+ );
725
+
726
+ const raycaster = new THREE.Raycaster();
727
+ raycaster.setFromCamera(mouse, this.camera ${useTS ? "as THREE.PerspectiveCamera" : ""});
728
+
729
+ if (plane) {
730
+ const target = new THREE.Vector3();
731
+ raycaster.ray.intersectPlane(plane, target);
732
+ return target;
733
+ }
734
+
735
+ const intersects = raycaster.intersectObjects(this.scene.children, true);
736
+ return intersects.length > 0 ? intersects[0].point : null;
737
+ }
738
+ }
889
739
  `;
890
- this.addTextFile(`src/game/AssetLoader.${ext}`, assetLoader);
891
- // InputManager
892
- const inputManager = `import * as THREE from 'three';
893
-
894
- export class InputManager {
895
- ${useTS ? 'private keys: Set<string> = new Set();' : ''}
896
- ${useTS ? 'private keysJustPressed: Set<string> = new Set();' : ''}
897
- ${useTS ? 'private keysJustReleased: Set<string> = new Set();' : ''}
898
- ${useTS ? 'private mousePosition: THREE.Vector2 = new THREE.Vector2();' : ''}
899
- ${useTS ? 'private mouseButtons: Set<number> = new Set();' : ''}
900
- ${useTS ? 'private mouseDelta: THREE.Vector2 = new THREE.Vector2();' : ''}
901
- ${useTS ? 'private wheelDelta: number = 0;' : ''}
902
-
903
- constructor() {
904
- ${useTS
905
- ? ''
906
- : `
907
- this.keys = new Set();
908
- this.keysJustPressed = new Set();
909
- this.keysJustReleased = new Set();
910
- this.mousePosition = new THREE.Vector2();
911
- this.mouseButtons = new Set();
912
- this.mouseDelta = new THREE.Vector2();
913
- this.wheelDelta = 0;`}
914
-
915
- window.addEventListener('keydown', this.onKeyDown.bind(this));
916
- window.addEventListener('keyup', this.onKeyUp.bind(this));
917
- window.addEventListener('mousemove', this.onMouseMove.bind(this));
918
- window.addEventListener('mousedown', this.onMouseDown.bind(this));
919
- window.addEventListener('mouseup', this.onMouseUp.bind(this));
920
- window.addEventListener('wheel', this.onWheel.bind(this));
921
- window.addEventListener('contextmenu', (e) => e.preventDefault());
922
- }
923
-
924
- private onKeyDown(e${useTS ? ': KeyboardEvent' : ''})${useTS ? ': void' : ''} {
925
- if (!this.keys.has(e.code)) {
926
- this.keysJustPressed.add(e.code);
927
- }
928
- this.keys.add(e.code);
929
- }
930
-
931
- private onKeyUp(e${useTS ? ': KeyboardEvent' : ''})${useTS ? ': void' : ''} {
932
- this.keys.delete(e.code);
933
- this.keysJustReleased.add(e.code);
934
- }
935
-
936
- private onMouseMove(e${useTS ? ': MouseEvent' : ''})${useTS ? ': void' : ''} {
937
- this.mouseDelta.set(e.movementX, e.movementY);
938
- this.mousePosition.set(e.clientX, e.clientY);
939
- }
940
-
941
- private onMouseDown(e${useTS ? ': MouseEvent' : ''})${useTS ? ': void' : ''} {
942
- this.mouseButtons.add(e.button);
943
- }
944
-
945
- private onMouseUp(e${useTS ? ': MouseEvent' : ''})${useTS ? ': void' : ''} {
946
- this.mouseButtons.delete(e.button);
947
- }
948
-
949
- private onWheel(e${useTS ? ': WheelEvent' : ''})${useTS ? ': void' : ''} {
950
- this.wheelDelta = e.deltaY;
951
- }
952
-
953
- isKeyPressed(code${useTS ? ': string' : ''})${useTS ? ': boolean' : ''} {
954
- return this.keys.has(code);
955
- }
956
-
957
- isKeyJustPressed(code${useTS ? ': string' : ''})${useTS ? ': boolean' : ''} {
958
- return this.keysJustPressed.has(code);
959
- }
960
-
961
- isKeyJustReleased(code${useTS ? ': string' : ''})${useTS ? ': boolean' : ''} {
962
- return this.keysJustReleased.has(code);
963
- }
964
-
965
- isMouseButtonPressed(button${useTS ? ': number' : ''})${useTS ? ': boolean' : ''} {
966
- return this.mouseButtons.has(button);
967
- }
968
-
969
- getMousePosition()${useTS ? ': THREE.Vector2' : ''} {
970
- return this.mousePosition.clone();
971
- }
972
-
973
- getMouseDelta()${useTS ? ': THREE.Vector2' : ''} {
974
- return this.mouseDelta.clone();
975
- }
976
-
977
- getWheelDelta()${useTS ? ': number' : ''} {
978
- return this.wheelDelta;
979
- }
980
-
981
- getAxis(positive${useTS ? ': string' : ''}, negative${useTS ? ': string' : ''})${useTS ? ': number' : ''} {
982
- let value = 0;
983
- if (this.keys.has(positive)) value += 1;
984
- if (this.keys.has(negative)) value -= 1;
985
- return value;
986
- }
987
-
988
- update()${useTS ? ': void' : ''} {
989
- this.keysJustPressed.clear();
990
- this.keysJustReleased.clear();
991
- this.mouseDelta.set(0, 0);
992
- this.wheelDelta = 0;
993
- }
994
- }
740
+ this.addTextFile(`src/game/GameManager.${ext}`, gameManager);
741
+ const assetLoader = `import * as THREE from 'three';
742
+ import { GLTFLoader${useTS ? ", GLTF" : ""} } from 'three/addons/loaders/GLTFLoader.js';
743
+ import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
744
+
745
+ export class AssetLoader {
746
+ ${useTS ? "private textureLoader: THREE.TextureLoader;" : ""}
747
+ ${useTS ? "private gltfLoader: GLTFLoader;" : ""}
748
+ ${useTS ? "private audioLoader: THREE.AudioLoader;" : ""}
749
+ ${useTS ? "private textures: Map<string, THREE.Texture> = new Map();" : ""}
750
+ ${useTS ? "private models: Map<string, GLTF> = new Map();" : ""}
751
+ ${useTS ? "private audio: Map<string, AudioBuffer> = new Map();" : ""}
752
+
753
+ constructor() {
754
+ this.textureLoader = new THREE.TextureLoader();
755
+
756
+ const dracoLoader = new DRACOLoader();
757
+ dracoLoader.setDecoderPath('https://www.gstatic.com/draco/versioned/decoders/1.5.6/');
758
+
759
+ this.gltfLoader = new GLTFLoader();
760
+ this.gltfLoader.setDRACOLoader(dracoLoader);
761
+
762
+ this.audioLoader = new THREE.AudioLoader();
763
+
764
+ ${useTS ? "" : `
765
+ this.textures = new Map();
766
+ this.models = new Map();
767
+ this.audio = new Map();`}
768
+ }
769
+
770
+ async loadAll(onProgress${useTS ? "?: (progress: number) => void" : ""})${useTS ? ": Promise<void>" : ""} {
771
+ // Load all assets here
772
+ // This would be populated based on project assets
773
+ if (onProgress) onProgress(1);
774
+ }
775
+
776
+ async loadTexture(path${useTS ? ": string" : ""})${useTS ? ": Promise<THREE.Texture>" : ""} {
777
+ if (this.textures.has(path)) {
778
+ return this.textures.get(path)${useTS ? "!" : ""};
779
+ }
780
+
781
+ return new Promise((resolve, reject) => {
782
+ this.textureLoader.load(
783
+ path,
784
+ (texture) => {
785
+ this.textures.set(path, texture);
786
+ resolve(texture);
787
+ },
788
+ undefined,
789
+ reject
790
+ );
791
+ });
792
+ }
793
+
794
+ async loadModel(path${useTS ? ": string" : ""})${useTS ? ": Promise<GLTF>" : ""} {
795
+ if (this.models.has(path)) {
796
+ return this.models.get(path)${useTS ? "!" : ""};
797
+ }
798
+
799
+ return new Promise((resolve, reject) => {
800
+ this.gltfLoader.load(
801
+ path,
802
+ (gltf) => {
803
+ this.models.set(path, gltf);
804
+ resolve(gltf);
805
+ },
806
+ undefined,
807
+ reject
808
+ );
809
+ });
810
+ }
811
+
812
+ getTexture(path${useTS ? ": string" : ""})${useTS ? ": THREE.Texture | undefined" : ""} {
813
+ return this.textures.get(path);
814
+ }
815
+
816
+ getModel(path${useTS ? ": string" : ""})${useTS ? ": Promise<GLTF>" : ""} {
817
+ return this.loadModel(path);
818
+ }
819
+
820
+ getAudio(path${useTS ? ": string" : ""})${useTS ? ": AudioBuffer | undefined" : ""} {
821
+ return this.audio.get(path);
822
+ }
823
+ }
995
824
  `;
996
- this.addTextFile(`src/game/InputManager.${ext}`, inputManager);
825
+ this.addTextFile(`src/game/AssetLoader.${ext}`, assetLoader);
826
+ const inputManager = `import * as THREE from 'three';
827
+
828
+ export class InputManager {
829
+ ${useTS ? "private keys: Set<string> = new Set();" : ""}
830
+ ${useTS ? "private keysJustPressed: Set<string> = new Set();" : ""}
831
+ ${useTS ? "private keysJustReleased: Set<string> = new Set();" : ""}
832
+ ${useTS ? "private mousePosition: THREE.Vector2 = new THREE.Vector2();" : ""}
833
+ ${useTS ? "private mouseButtons: Set<number> = new Set();" : ""}
834
+ ${useTS ? "private mouseDelta: THREE.Vector2 = new THREE.Vector2();" : ""}
835
+ ${useTS ? "private wheelDelta: number = 0;" : ""}
836
+
837
+ constructor() {
838
+ ${useTS ? "" : `
839
+ this.keys = new Set();
840
+ this.keysJustPressed = new Set();
841
+ this.keysJustReleased = new Set();
842
+ this.mousePosition = new THREE.Vector2();
843
+ this.mouseButtons = new Set();
844
+ this.mouseDelta = new THREE.Vector2();
845
+ this.wheelDelta = 0;`}
846
+
847
+ window.addEventListener('keydown', this.onKeyDown.bind(this));
848
+ window.addEventListener('keyup', this.onKeyUp.bind(this));
849
+ window.addEventListener('mousemove', this.onMouseMove.bind(this));
850
+ window.addEventListener('mousedown', this.onMouseDown.bind(this));
851
+ window.addEventListener('mouseup', this.onMouseUp.bind(this));
852
+ window.addEventListener('wheel', this.onWheel.bind(this));
853
+ window.addEventListener('contextmenu', (e) => e.preventDefault());
854
+ }
855
+
856
+ private onKeyDown(e${useTS ? ": KeyboardEvent" : ""})${useTS ? ": void" : ""} {
857
+ if (!this.keys.has(e.code)) {
858
+ this.keysJustPressed.add(e.code);
997
859
  }
998
- exportShaders(project) {
999
- // Export shader assets
1000
- const shaders = project.assets.filter((a) => a.type === 'shader');
1001
- for (const shader of shaders) {
1002
- const vertexShader = shader.metadata?.vertex ??
1003
- `
1004
- varying vec2 vUv;
1005
-
1006
- void main() {
1007
- vUv = uv;
1008
- gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
860
+ this.keys.add(e.code);
861
+ }
862
+
863
+ private onKeyUp(e${useTS ? ": KeyboardEvent" : ""})${useTS ? ": void" : ""} {
864
+ this.keys.delete(e.code);
865
+ this.keysJustReleased.add(e.code);
866
+ }
867
+
868
+ private onMouseMove(e${useTS ? ": MouseEvent" : ""})${useTS ? ": void" : ""} {
869
+ this.mouseDelta.set(e.movementX, e.movementY);
870
+ this.mousePosition.set(e.clientX, e.clientY);
871
+ }
872
+
873
+ private onMouseDown(e${useTS ? ": MouseEvent" : ""})${useTS ? ": void" : ""} {
874
+ this.mouseButtons.add(e.button);
875
+ }
876
+
877
+ private onMouseUp(e${useTS ? ": MouseEvent" : ""})${useTS ? ": void" : ""} {
878
+ this.mouseButtons.delete(e.button);
879
+ }
880
+
881
+ private onWheel(e${useTS ? ": WheelEvent" : ""})${useTS ? ": void" : ""} {
882
+ this.wheelDelta = e.deltaY;
883
+ }
884
+
885
+ isKeyPressed(code${useTS ? ": string" : ""})${useTS ? ": boolean" : ""} {
886
+ return this.keys.has(code);
887
+ }
888
+
889
+ isKeyJustPressed(code${useTS ? ": string" : ""})${useTS ? ": boolean" : ""} {
890
+ return this.keysJustPressed.has(code);
891
+ }
892
+
893
+ isKeyJustReleased(code${useTS ? ": string" : ""})${useTS ? ": boolean" : ""} {
894
+ return this.keysJustReleased.has(code);
895
+ }
896
+
897
+ isMouseButtonPressed(button${useTS ? ": number" : ""})${useTS ? ": boolean" : ""} {
898
+ return this.mouseButtons.has(button);
899
+ }
900
+
901
+ getMousePosition()${useTS ? ": THREE.Vector2" : ""} {
902
+ return this.mousePosition.clone();
903
+ }
904
+
905
+ getMouseDelta()${useTS ? ": THREE.Vector2" : ""} {
906
+ return this.mouseDelta.clone();
907
+ }
908
+
909
+ getWheelDelta()${useTS ? ": number" : ""} {
910
+ return this.wheelDelta;
911
+ }
912
+
913
+ getAxis(positive${useTS ? ": string" : ""}, negative${useTS ? ": string" : ""})${useTS ? ": number" : ""} {
914
+ let value = 0;
915
+ if (this.keys.has(positive)) value += 1;
916
+ if (this.keys.has(negative)) value -= 1;
917
+ return value;
918
+ }
919
+
920
+ update()${useTS ? ": void" : ""} {
921
+ this.keysJustPressed.clear();
922
+ this.keysJustReleased.clear();
923
+ this.mouseDelta.set(0, 0);
924
+ this.wheelDelta = 0;
925
+ }
926
+ }
927
+ `;
928
+ this.addTextFile(`src/game/InputManager.${ext}`, inputManager);
929
+ }
930
+ exportShaders(project) {
931
+ const shaders = project.assets.filter((a) => a.type === "shader");
932
+ for (const shader of shaders) {
933
+ const vertexShader = shader.metadata?.vertex ?? `
934
+ varying vec2 vUv;
935
+
936
+ void main() {
937
+ vUv = uv;
938
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
1009
939
  }`;
1010
- const fragmentShader = shader.metadata?.fragment ??
1011
- `
1012
- varying vec2 vUv;
1013
-
1014
- void main() {
1015
- gl_FragColor = vec4(vUv, 0.5, 1.0);
940
+ const fragmentShader = shader.metadata?.fragment ?? `
941
+ varying vec2 vUv;
942
+
943
+ void main() {
944
+ gl_FragColor = vec4(vUv, 0.5, 1.0);
1016
945
  }`;
1017
- this.addTextFile(`src/shaders/${this.sanitizeName(shader.name)}.vert`, vertexShader);
1018
- this.addTextFile(`src/shaders/${this.sanitizeName(shader.name)}.frag`, fragmentShader);
1019
- }
946
+ this.addTextFile(`src/shaders/${this.sanitizeName(shader.name)}.vert`, vertexShader);
947
+ this.addTextFile(`src/shaders/${this.sanitizeName(shader.name)}.frag`, fragmentShader);
1020
948
  }
1021
- exportBundlerConfig(bundler, useTS) {
1022
- if (bundler === 'vite') {
1023
- this.addTextFile('vite.config.ts', `import { defineConfig } from 'vite';
1024
-
1025
- export default defineConfig({
1026
- base: './',
1027
- build: {
1028
- outDir: 'dist',
1029
- assetsDir: 'assets',
1030
- sourcemap: true,
1031
- },
1032
- server: {
1033
- port: 3000,
1034
- open: true,
1035
- },
1036
- assetsInclude: ['**/*.glb', '**/*.gltf', '**/*.hdr'],
1037
- });
1038
- `);
1039
- }
1040
- else if (bundler === 'webpack') {
1041
- this.addTextFile('webpack.config.js', `const path = require('path');
1042
- const HtmlWebpackPlugin = require('html-webpack-plugin');
1043
-
1044
- module.exports = {
1045
- entry: './src/main.${useTS ? 'ts' : 'js'}',
1046
- output: {
1047
- filename: 'bundle.js',
1048
- path: path.resolve(__dirname, 'dist'),
1049
- },
1050
- resolve: {
1051
- extensions: ['.ts', '.js'],
1052
- alias: {
1053
- 'three/addons': path.resolve(__dirname, 'node_modules/three/examples/jsm'),
1054
- },
1055
- },
1056
- module: {
1057
- rules: [
1058
- {
1059
- test: /\\.ts$/,
1060
- use: 'ts-loader',
1061
- exclude: /node_modules/,
1062
- },
1063
- {
1064
- test: /\\.(glb|gltf|hdr)$/,
1065
- type: 'asset/resource',
1066
- },
1067
- ],
1068
- },
1069
- plugins: [
1070
- new HtmlWebpackPlugin({
1071
- template: 'index.html',
1072
- }),
1073
- ],
1074
- devServer: {
1075
- static: './dist',
1076
- port: 3000,
1077
- open: true,
1078
- },
1079
- };
1080
- `);
1081
- }
1082
- }
1083
- exportTSConfig() {
1084
- const tsconfig = {
1085
- compilerOptions: {
1086
- target: 'ES2020',
1087
- useDefineForClassFields: true,
1088
- module: 'ESNext',
1089
- lib: ['ES2020', 'DOM', 'DOM.Iterable'],
1090
- skipLibCheck: true,
1091
- moduleResolution: 'bundler',
1092
- allowImportingTsExtensions: true,
1093
- resolveJsonModule: true,
1094
- isolatedModules: true,
1095
- noEmit: true,
1096
- strict: true,
1097
- noUnusedLocals: true,
1098
- noUnusedParameters: true,
1099
- noFallthroughCasesInSwitch: true,
1100
- paths: {
1101
- 'three/addons/*': ['node_modules/three/examples/jsm/*'],
1102
- },
1103
- },
1104
- include: ['src'],
1105
- };
1106
- this.addTextFile('tsconfig.json', JSON.stringify(tsconfig, null, 2));
1107
- }
1108
- sanitizeName(name) {
1109
- return name.replace(/[^a-zA-Z0-9]/g, '');
949
+ }
950
+ exportBundlerConfig(bundler, useTS) {
951
+ if (bundler === "vite") {
952
+ this.addTextFile(
953
+ "vite.config.ts",
954
+ `import { defineConfig } from 'vite';
955
+
956
+ export default defineConfig({
957
+ base: './',
958
+ build: {
959
+ outDir: 'dist',
960
+ assetsDir: 'assets',
961
+ sourcemap: true,
962
+ },
963
+ server: {
964
+ port: 3000,
965
+ open: true,
966
+ },
967
+ assetsInclude: ['**/*.glb', '**/*.gltf', '**/*.hdr'],
968
+ });
969
+ `
970
+ );
971
+ } else if (bundler === "webpack") {
972
+ this.addTextFile(
973
+ "webpack.config.js",
974
+ `const path = require('path');
975
+ const HtmlWebpackPlugin = require('html-webpack-plugin');
976
+
977
+ module.exports = {
978
+ entry: './src/main.${useTS ? "ts" : "js"}',
979
+ output: {
980
+ filename: 'bundle.js',
981
+ path: path.resolve(__dirname, 'dist'),
982
+ },
983
+ resolve: {
984
+ extensions: ['.ts', '.js'],
985
+ alias: {
986
+ 'three/addons': path.resolve(__dirname, 'node_modules/three/examples/jsm'),
987
+ },
988
+ },
989
+ module: {
990
+ rules: [
991
+ {
992
+ test: /\\.ts$/,
993
+ use: 'ts-loader',
994
+ exclude: /node_modules/,
995
+ },
996
+ {
997
+ test: /\\.(glb|gltf|hdr)$/,
998
+ type: 'asset/resource',
999
+ },
1000
+ ],
1001
+ },
1002
+ plugins: [
1003
+ new HtmlWebpackPlugin({
1004
+ template: 'index.html',
1005
+ }),
1006
+ ],
1007
+ devServer: {
1008
+ static: './dist',
1009
+ port: 3000,
1010
+ open: true,
1011
+ },
1012
+ };
1013
+ `
1014
+ );
1110
1015
  }
1016
+ }
1017
+ exportTSConfig() {
1018
+ const tsconfig = {
1019
+ compilerOptions: {
1020
+ target: "ES2020",
1021
+ useDefineForClassFields: true,
1022
+ module: "ESNext",
1023
+ lib: ["ES2020", "DOM", "DOM.Iterable"],
1024
+ skipLibCheck: true,
1025
+ moduleResolution: "bundler",
1026
+ allowImportingTsExtensions: true,
1027
+ resolveJsonModule: true,
1028
+ isolatedModules: true,
1029
+ noEmit: true,
1030
+ strict: true,
1031
+ noUnusedLocals: true,
1032
+ noUnusedParameters: true,
1033
+ noFallthroughCasesInSwitch: true,
1034
+ paths: {
1035
+ "three/addons/*": ["node_modules/three/examples/jsm/*"]
1036
+ }
1037
+ },
1038
+ include: ["src"]
1039
+ };
1040
+ this.addTextFile("tsconfig.json", JSON.stringify(tsconfig, null, 2));
1041
+ }
1042
+ sanitizeName(name) {
1043
+ return name.replace(/[^a-zA-Z0-9]/g, "");
1044
+ }
1111
1045
  }
1112
-
1113
1046
  exports.ThreeJSExporter = ThreeJSExporter;