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