@nice2dev/game-engine 1.3.15 → 1.3.17

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